blob: a2ac3166c34cf3bfae6f9e32f9ba4c6862800e2c [file] [log] [blame]
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +00001"""About Dialog for IDLE
2
Steven M. Gava44d3d1a2001-07-31 06:59:02 +00003"""
Neal Norwitz9d72bb42007-04-17 08:48:32 +00004import os
terryjreedybd570f42017-06-23 20:19:46 -04005from platform import python_version
Terry Jan Reedybfbaa6b2016-08-31 00:50:55 -04006
terryjreedy1b7474d2017-06-23 12:59:59 -04007from tkinter import Toplevel, Frame, Label, Button, PhotoImage
8from tkinter import SUNKEN, TOP, BOTTOM, LEFT, X, BOTH, W, EW, NSEW, E
Terry Jan Reedybfbaa6b2016-08-31 00:50:55 -04009
Terry Jan Reedy6fa5bdc2016-05-28 13:22:31 -040010from idlelib import textview
Neal Norwitz539594f2002-11-30 19:12:41 +000011
Terry Jan Reedybfbaa6b2016-08-31 00:50:55 -040012
Steven M. Gava44d3d1a2001-07-31 06:59:02 +000013class AboutDialog(Toplevel):
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +000014 """Modal about dialog for idle
15
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +000016 """
terryjreedybd570f42017-06-23 20:19:46 -040017 def __init__(self, parent, title=None, _htest=False, _utest=False):
terryjreedy12cbd872017-06-10 02:53:19 -040018 """Create popup, do not return until tk widget destroyed.
19
20 parent - parent of this dialog
21 title - string which is title of popup dialog
Terry Jan Reedy1b392ff2014-05-24 18:48:18 -040022 _htest - bool, change box location when running htest
terryjreedy12cbd872017-06-10 02:53:19 -040023 _utest - bool, don't wait_window when running unittest
Terry Jan Reedy1b392ff2014-05-24 18:48:18 -040024 """
Steven M. Gava885c0bb2001-07-31 10:44:35 +000025 Toplevel.__init__(self, parent)
26 self.configure(borderwidth=5)
Terry Jan Reedy1b392ff2014-05-24 18:48:18 -040027 # place dialog below parent if running htest
28 self.geometry("+%d+%d" % (
29 parent.winfo_rootx()+30,
30 parent.winfo_rooty()+(30 if not _htest else 100)))
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +000031 self.bg = "#707070"
32 self.fg = "#ffffff"
terryjreedy12cbd872017-06-10 02:53:19 -040033 self.create_widgets()
34 self.resizable(height=False, width=False)
terryjreedybd570f42017-06-23 20:19:46 -040035 self.title(title or f'About IDLE {python_version()}')
Steven M. Gava885c0bb2001-07-31 10:44:35 +000036 self.transient(parent)
37 self.grab_set()
terryjreedy12cbd872017-06-10 02:53:19 -040038 self.protocol("WM_DELETE_WINDOW", self.ok)
Steven M. Gava885c0bb2001-07-31 10:44:35 +000039 self.parent = parent
terryjreedy12cbd872017-06-10 02:53:19 -040040 self.button_ok.focus_set()
41 self.bind('<Return>', self.ok) # dismiss dialog
42 self.bind('<Escape>', self.ok) # dismiss dialog
43 self._current_textview = None
44 self._utest = _utest
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +000045
terryjreedy12cbd872017-06-10 02:53:19 -040046 if not _utest:
47 self.deiconify()
48 self.wait_window()
49
50 def create_widgets(self):
terryjreedy12cbd872017-06-10 02:53:19 -040051 frame = Frame(self, borderwidth=2, relief=SUNKEN)
52 frame_buttons = Frame(self)
53 frame_buttons.pack(side=BOTTOM, fill=X)
54 frame.pack(side=TOP, expand=True, fill=BOTH)
55 self.button_ok = Button(frame_buttons, text='Close',
56 command=self.ok)
57 self.button_ok.pack(padx=5, pady=5)
58
59 frame_background = Frame(frame, bg=self.bg)
60 frame_background.pack(expand=True, fill=BOTH)
61
62 header = Label(frame_background, text='IDLE', fg=self.fg,
63 bg=self.bg, font=('courier', 24, 'bold'))
terryjreedy1b7474d2017-06-23 12:59:59 -040064 header.grid(row=0, column=0, sticky=E, padx=10, pady=10)
65
66 tk_patchlevel = self.tk.call('info', 'patchlevel')
67 ext = '.png' if tk_patchlevel >= '8.6' else '.gif'
68 icon = os.path.join(os.path.abspath(os.path.dirname(__file__)),
69 'Icons', f'idle_48{ext}')
70 self.icon_image = PhotoImage(master=self._root(), file=icon)
71 logo = Label(frame_background, image=self.icon_image, bg=self.bg)
72 logo.grid(row=0, column=0, sticky=W, rowspan=2, padx=10, pady=10)
73
terryjreedy12cbd872017-06-10 02:53:19 -040074 byline_text = "Python's Integrated DeveLopment Environment" + 5*'\n'
75 byline = Label(frame_background, text=byline_text, justify=LEFT,
76 fg=self.fg, bg=self.bg)
77 byline.grid(row=2, column=0, sticky=W, columnspan=3, padx=10, pady=5)
78 email = Label(frame_background, text='email: idle-dev@python.org',
79 justify=LEFT, fg=self.fg, bg=self.bg)
80 email.grid(row=6, column=0, columnspan=2, sticky=W, padx=10, pady=0)
81 docs = Label(frame_background, text='https://docs.python.org/' +
terryjreedybd570f42017-06-23 20:19:46 -040082 python_version()[:3] + '/library/idle.html',
terryjreedy12cbd872017-06-10 02:53:19 -040083 justify=LEFT, fg=self.fg, bg=self.bg)
84 docs.grid(row=7, column=0, columnspan=2, sticky=W, padx=10, pady=0)
85
86 Frame(frame_background, borderwidth=1, relief=SUNKEN,
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +000087 height=2, bg=self.bg).grid(row=8, column=0, sticky=EW,
88 columnspan=3, padx=5, pady=5)
terryjreedy12cbd872017-06-10 02:53:19 -040089
terryjreedybd570f42017-06-23 20:19:46 -040090 pyver = Label(frame_background,
91 text='Python version: ' + python_version(),
terryjreedy12cbd872017-06-10 02:53:19 -040092 fg=self.fg, bg=self.bg)
93 pyver.grid(row=9, column=0, sticky=W, padx=10, pady=0)
terryjreedy12cbd872017-06-10 02:53:19 -040094 tkver = Label(frame_background, text='Tk version: ' + tk_patchlevel,
95 fg=self.fg, bg=self.bg)
96 tkver.grid(row=9, column=1, sticky=W, padx=2, pady=0)
97 py_buttons = Frame(frame_background, bg=self.bg)
98 py_buttons.grid(row=10, column=0, columnspan=2, sticky=NSEW)
99 self.py_license = Button(py_buttons, text='License', width=8,
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +0000100 highlightbackground=self.bg,
terryjreedy12cbd872017-06-10 02:53:19 -0400101 command=self.show_py_license)
102 self.py_license.pack(side=LEFT, padx=10, pady=10)
103 self.py_copyright = Button(py_buttons, text='Copyright', width=8,
104 highlightbackground=self.bg,
105 command=self.show_py_copyright)
106 self.py_copyright.pack(side=LEFT, padx=10, pady=10)
107 self.py_credits = Button(py_buttons, text='Credits', width=8,
108 highlightbackground=self.bg,
109 command=self.show_py_credits)
110 self.py_credits.pack(side=LEFT, padx=10, pady=10)
111
112 Frame(frame_background, borderwidth=1, relief=SUNKEN,
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +0000113 height=2, bg=self.bg).grid(row=11, column=0, sticky=EW,
114 columnspan=3, padx=5, pady=5)
Steven M. Gava885c0bb2001-07-31 10:44:35 +0000115
terryjreedybd570f42017-06-23 20:19:46 -0400116 idlever = Label(frame_background,
117 text='IDLE version: ' + python_version(),
terryjreedy12cbd872017-06-10 02:53:19 -0400118 fg=self.fg, bg=self.bg)
119 idlever.grid(row=12, column=0, sticky=W, padx=10, pady=0)
120 idle_buttons = Frame(frame_background, bg=self.bg)
121 idle_buttons.grid(row=13, column=0, columnspan=3, sticky=NSEW)
122 self.readme = Button(idle_buttons, text='README', width=8,
123 highlightbackground=self.bg,
124 command=self.show_readme)
125 self.readme.pack(side=LEFT, padx=10, pady=10)
126 self.idle_news = Button(idle_buttons, text='NEWS', width=8,
127 highlightbackground=self.bg,
128 command=self.show_idle_news)
129 self.idle_news.pack(side=LEFT, padx=10, pady=10)
130 self.idle_credits = Button(idle_buttons, text='Credits', width=8,
131 highlightbackground=self.bg,
132 command=self.show_idle_credits)
133 self.idle_credits.pack(side=LEFT, padx=10, pady=10)
134
135 # License, copyright, and credits are of type _sitebuiltins._Printer
136 def show_py_license(self):
137 "Handle License button event."
Guido van Rossum8ce8a782007-11-01 19:42:39 +0000138 self.display_printer_text('About - License', license)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000139
terryjreedy12cbd872017-06-10 02:53:19 -0400140 def show_py_copyright(self):
141 "Handle Copyright button event."
Guido van Rossum8ce8a782007-11-01 19:42:39 +0000142 self.display_printer_text('About - Copyright', copyright)
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +0000143
terryjreedy12cbd872017-06-10 02:53:19 -0400144 def show_py_credits(self):
145 "Handle Python Credits button event."
Guido van Rossum8ce8a782007-11-01 19:42:39 +0000146 self.display_printer_text('About - Python Credits', credits)
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +0000147
Terry Jan Reedy35676512016-01-16 23:44:04 -0500148 # Encode CREDITS.txt to utf-8 for proper version of Loewis.
149 # Specify others as ascii until need utf-8, so catch errors.
terryjreedy12cbd872017-06-10 02:53:19 -0400150 def show_idle_credits(self):
151 "Handle Idle Credits button event."
Terry Jan Reedy35676512016-01-16 23:44:04 -0500152 self.display_file_text('About - Credits', 'CREDITS.txt', 'utf-8')
Steven M. Gava885c0bb2001-07-31 10:44:35 +0000153
terryjreedy12cbd872017-06-10 02:53:19 -0400154 def show_readme(self):
155 "Handle Readme button event."
Terry Jan Reedy35676512016-01-16 23:44:04 -0500156 self.display_file_text('About - Readme', 'README.txt', 'ascii')
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +0000157
terryjreedy12cbd872017-06-10 02:53:19 -0400158 def show_idle_news(self):
159 "Handle News button event."
Terry Jan Reedy6ff7a142016-06-22 03:55:20 -0400160 self.display_file_text('About - NEWS', 'NEWS.txt', 'utf-8')
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +0000161
Guido van Rossum8ce8a782007-11-01 19:42:39 +0000162 def display_printer_text(self, title, printer):
terryjreedy12cbd872017-06-10 02:53:19 -0400163 """Create textview for built-in constants.
164
165 Built-in constants have type _sitebuiltins._Printer. The
166 text is extracted from the built-in and then sent to a text
167 viewer with self as the parent and title as the title of
168 the popup.
169 """
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +0000170 printer._Printer__setup()
Guido van Rossum8ce8a782007-11-01 19:42:39 +0000171 text = '\n'.join(printer._Printer__lines)
terryjreedy12cbd872017-06-10 02:53:19 -0400172 self._current_textview = textview.view_text(
173 self, title, text, _utest=self._utest)
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +0000174
Guido van Rossum8ce8a782007-11-01 19:42:39 +0000175 def display_file_text(self, title, filename, encoding=None):
terryjreedy12cbd872017-06-10 02:53:19 -0400176 """Create textview for filename.
Steven M. Gava885c0bb2001-07-31 10:44:35 +0000177
terryjreedy12cbd872017-06-10 02:53:19 -0400178 The filename needs to be in the current directory. The path
179 is sent to a text viewer with self as the parent, title as
180 the title of the popup, and the file encoding.
181 """
182 fn = os.path.join(os.path.abspath(os.path.dirname(__file__)), filename)
183 self._current_textview = textview.view_file(
184 self, title, fn, encoding, _utest=self._utest)
185
186 def ok(self, event=None):
187 "Dismiss help_about dialog."
Steven M. Gava885c0bb2001-07-31 10:44:35 +0000188 self.destroy()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000189
Terry Jan Reedybfbaa6b2016-08-31 00:50:55 -0400190
Steven M. Gava44d3d1a2001-07-31 06:59:02 +0000191if __name__ == '__main__':
Terry Jan Reedydf1d34c2016-06-22 04:50:16 -0400192 import unittest
Terry Jan Reedy47e00e52016-06-22 05:49:15 -0400193 unittest.main('idlelib.idle_test.test_help_about', verbosity=2, exit=False)
Terry Jan Reedy06313b72014-05-11 23:32:32 -0400194 from idlelib.idle_test.htest import run
195 run(AboutDialog)