jpayne@68
|
1 """About Dialog for IDLE
|
jpayne@68
|
2
|
jpayne@68
|
3 """
|
jpayne@68
|
4 import os
|
jpayne@68
|
5 import sys
|
jpayne@68
|
6 from platform import python_version, architecture
|
jpayne@68
|
7
|
jpayne@68
|
8 from tkinter import Toplevel, Frame, Label, Button, PhotoImage
|
jpayne@68
|
9 from tkinter import SUNKEN, TOP, BOTTOM, LEFT, X, BOTH, W, EW, NSEW, E
|
jpayne@68
|
10
|
jpayne@68
|
11 from idlelib import textview
|
jpayne@68
|
12
|
jpayne@68
|
13
|
jpayne@68
|
14 def build_bits():
|
jpayne@68
|
15 "Return bits for platform."
|
jpayne@68
|
16 if sys.platform == 'darwin':
|
jpayne@68
|
17 return '64' if sys.maxsize > 2**32 else '32'
|
jpayne@68
|
18 else:
|
jpayne@68
|
19 return architecture()[0][:2]
|
jpayne@68
|
20
|
jpayne@68
|
21
|
jpayne@68
|
22 class AboutDialog(Toplevel):
|
jpayne@68
|
23 """Modal about dialog for idle
|
jpayne@68
|
24
|
jpayne@68
|
25 """
|
jpayne@68
|
26 def __init__(self, parent, title=None, *, _htest=False, _utest=False):
|
jpayne@68
|
27 """Create popup, do not return until tk widget destroyed.
|
jpayne@68
|
28
|
jpayne@68
|
29 parent - parent of this dialog
|
jpayne@68
|
30 title - string which is title of popup dialog
|
jpayne@68
|
31 _htest - bool, change box location when running htest
|
jpayne@68
|
32 _utest - bool, don't wait_window when running unittest
|
jpayne@68
|
33 """
|
jpayne@68
|
34 Toplevel.__init__(self, parent)
|
jpayne@68
|
35 self.configure(borderwidth=5)
|
jpayne@68
|
36 # place dialog below parent if running htest
|
jpayne@68
|
37 self.geometry("+%d+%d" % (
|
jpayne@68
|
38 parent.winfo_rootx()+30,
|
jpayne@68
|
39 parent.winfo_rooty()+(30 if not _htest else 100)))
|
jpayne@68
|
40 self.bg = "#bbbbbb"
|
jpayne@68
|
41 self.fg = "#000000"
|
jpayne@68
|
42 self.create_widgets()
|
jpayne@68
|
43 self.resizable(height=False, width=False)
|
jpayne@68
|
44 self.title(title or
|
jpayne@68
|
45 f'About IDLE {python_version()} ({build_bits()} bit)')
|
jpayne@68
|
46 self.transient(parent)
|
jpayne@68
|
47 self.grab_set()
|
jpayne@68
|
48 self.protocol("WM_DELETE_WINDOW", self.ok)
|
jpayne@68
|
49 self.parent = parent
|
jpayne@68
|
50 self.button_ok.focus_set()
|
jpayne@68
|
51 self.bind('<Return>', self.ok) # dismiss dialog
|
jpayne@68
|
52 self.bind('<Escape>', self.ok) # dismiss dialog
|
jpayne@68
|
53 self._current_textview = None
|
jpayne@68
|
54 self._utest = _utest
|
jpayne@68
|
55
|
jpayne@68
|
56 if not _utest:
|
jpayne@68
|
57 self.deiconify()
|
jpayne@68
|
58 self.wait_window()
|
jpayne@68
|
59
|
jpayne@68
|
60 def create_widgets(self):
|
jpayne@68
|
61 frame = Frame(self, borderwidth=2, relief=SUNKEN)
|
jpayne@68
|
62 frame_buttons = Frame(self)
|
jpayne@68
|
63 frame_buttons.pack(side=BOTTOM, fill=X)
|
jpayne@68
|
64 frame.pack(side=TOP, expand=True, fill=BOTH)
|
jpayne@68
|
65 self.button_ok = Button(frame_buttons, text='Close',
|
jpayne@68
|
66 command=self.ok)
|
jpayne@68
|
67 self.button_ok.pack(padx=5, pady=5)
|
jpayne@68
|
68
|
jpayne@68
|
69 frame_background = Frame(frame, bg=self.bg)
|
jpayne@68
|
70 frame_background.pack(expand=True, fill=BOTH)
|
jpayne@68
|
71
|
jpayne@68
|
72 header = Label(frame_background, text='IDLE', fg=self.fg,
|
jpayne@68
|
73 bg=self.bg, font=('courier', 24, 'bold'))
|
jpayne@68
|
74 header.grid(row=0, column=0, sticky=E, padx=10, pady=10)
|
jpayne@68
|
75
|
jpayne@68
|
76 tk_patchlevel = self.tk.call('info', 'patchlevel')
|
jpayne@68
|
77 ext = '.png' if tk_patchlevel >= '8.6' else '.gif'
|
jpayne@68
|
78 icon = os.path.join(os.path.abspath(os.path.dirname(__file__)),
|
jpayne@68
|
79 'Icons', f'idle_48{ext}')
|
jpayne@68
|
80 self.icon_image = PhotoImage(master=self._root(), file=icon)
|
jpayne@68
|
81 logo = Label(frame_background, image=self.icon_image, bg=self.bg)
|
jpayne@68
|
82 logo.grid(row=0, column=0, sticky=W, rowspan=2, padx=10, pady=10)
|
jpayne@68
|
83
|
jpayne@68
|
84 byline_text = "Python's Integrated Development\nand Learning Environment" + 5*'\n'
|
jpayne@68
|
85 byline = Label(frame_background, text=byline_text, justify=LEFT,
|
jpayne@68
|
86 fg=self.fg, bg=self.bg)
|
jpayne@68
|
87 byline.grid(row=2, column=0, sticky=W, columnspan=3, padx=10, pady=5)
|
jpayne@68
|
88 email = Label(frame_background, text='email: idle-dev@python.org',
|
jpayne@68
|
89 justify=LEFT, fg=self.fg, bg=self.bg)
|
jpayne@68
|
90 email.grid(row=6, column=0, columnspan=2, sticky=W, padx=10, pady=0)
|
jpayne@68
|
91 docs = Label(frame_background, text='https://docs.python.org/' +
|
jpayne@68
|
92 python_version()[:3] + '/library/idle.html',
|
jpayne@68
|
93 justify=LEFT, fg=self.fg, bg=self.bg)
|
jpayne@68
|
94 docs.grid(row=7, column=0, columnspan=2, sticky=W, padx=10, pady=0)
|
jpayne@68
|
95
|
jpayne@68
|
96 Frame(frame_background, borderwidth=1, relief=SUNKEN,
|
jpayne@68
|
97 height=2, bg=self.bg).grid(row=8, column=0, sticky=EW,
|
jpayne@68
|
98 columnspan=3, padx=5, pady=5)
|
jpayne@68
|
99
|
jpayne@68
|
100 pyver = Label(frame_background,
|
jpayne@68
|
101 text='Python version: ' + python_version(),
|
jpayne@68
|
102 fg=self.fg, bg=self.bg)
|
jpayne@68
|
103 pyver.grid(row=9, column=0, sticky=W, padx=10, pady=0)
|
jpayne@68
|
104 tkver = Label(frame_background, text='Tk version: ' + tk_patchlevel,
|
jpayne@68
|
105 fg=self.fg, bg=self.bg)
|
jpayne@68
|
106 tkver.grid(row=9, column=1, sticky=W, padx=2, pady=0)
|
jpayne@68
|
107 py_buttons = Frame(frame_background, bg=self.bg)
|
jpayne@68
|
108 py_buttons.grid(row=10, column=0, columnspan=2, sticky=NSEW)
|
jpayne@68
|
109 self.py_license = Button(py_buttons, text='License', width=8,
|
jpayne@68
|
110 highlightbackground=self.bg,
|
jpayne@68
|
111 command=self.show_py_license)
|
jpayne@68
|
112 self.py_license.pack(side=LEFT, padx=10, pady=10)
|
jpayne@68
|
113 self.py_copyright = Button(py_buttons, text='Copyright', width=8,
|
jpayne@68
|
114 highlightbackground=self.bg,
|
jpayne@68
|
115 command=self.show_py_copyright)
|
jpayne@68
|
116 self.py_copyright.pack(side=LEFT, padx=10, pady=10)
|
jpayne@68
|
117 self.py_credits = Button(py_buttons, text='Credits', width=8,
|
jpayne@68
|
118 highlightbackground=self.bg,
|
jpayne@68
|
119 command=self.show_py_credits)
|
jpayne@68
|
120 self.py_credits.pack(side=LEFT, padx=10, pady=10)
|
jpayne@68
|
121
|
jpayne@68
|
122 Frame(frame_background, borderwidth=1, relief=SUNKEN,
|
jpayne@68
|
123 height=2, bg=self.bg).grid(row=11, column=0, sticky=EW,
|
jpayne@68
|
124 columnspan=3, padx=5, pady=5)
|
jpayne@68
|
125
|
jpayne@68
|
126 idlever = Label(frame_background,
|
jpayne@68
|
127 text='IDLE version: ' + python_version(),
|
jpayne@68
|
128 fg=self.fg, bg=self.bg)
|
jpayne@68
|
129 idlever.grid(row=12, column=0, sticky=W, padx=10, pady=0)
|
jpayne@68
|
130 idle_buttons = Frame(frame_background, bg=self.bg)
|
jpayne@68
|
131 idle_buttons.grid(row=13, column=0, columnspan=3, sticky=NSEW)
|
jpayne@68
|
132 self.readme = Button(idle_buttons, text='README', width=8,
|
jpayne@68
|
133 highlightbackground=self.bg,
|
jpayne@68
|
134 command=self.show_readme)
|
jpayne@68
|
135 self.readme.pack(side=LEFT, padx=10, pady=10)
|
jpayne@68
|
136 self.idle_news = Button(idle_buttons, text='NEWS', width=8,
|
jpayne@68
|
137 highlightbackground=self.bg,
|
jpayne@68
|
138 command=self.show_idle_news)
|
jpayne@68
|
139 self.idle_news.pack(side=LEFT, padx=10, pady=10)
|
jpayne@68
|
140 self.idle_credits = Button(idle_buttons, text='Credits', width=8,
|
jpayne@68
|
141 highlightbackground=self.bg,
|
jpayne@68
|
142 command=self.show_idle_credits)
|
jpayne@68
|
143 self.idle_credits.pack(side=LEFT, padx=10, pady=10)
|
jpayne@68
|
144
|
jpayne@68
|
145 # License, copyright, and credits are of type _sitebuiltins._Printer
|
jpayne@68
|
146 def show_py_license(self):
|
jpayne@68
|
147 "Handle License button event."
|
jpayne@68
|
148 self.display_printer_text('About - License', license)
|
jpayne@68
|
149
|
jpayne@68
|
150 def show_py_copyright(self):
|
jpayne@68
|
151 "Handle Copyright button event."
|
jpayne@68
|
152 self.display_printer_text('About - Copyright', copyright)
|
jpayne@68
|
153
|
jpayne@68
|
154 def show_py_credits(self):
|
jpayne@68
|
155 "Handle Python Credits button event."
|
jpayne@68
|
156 self.display_printer_text('About - Python Credits', credits)
|
jpayne@68
|
157
|
jpayne@68
|
158 # Encode CREDITS.txt to utf-8 for proper version of Loewis.
|
jpayne@68
|
159 # Specify others as ascii until need utf-8, so catch errors.
|
jpayne@68
|
160 def show_idle_credits(self):
|
jpayne@68
|
161 "Handle Idle Credits button event."
|
jpayne@68
|
162 self.display_file_text('About - Credits', 'CREDITS.txt', 'utf-8')
|
jpayne@68
|
163
|
jpayne@68
|
164 def show_readme(self):
|
jpayne@68
|
165 "Handle Readme button event."
|
jpayne@68
|
166 self.display_file_text('About - Readme', 'README.txt', 'ascii')
|
jpayne@68
|
167
|
jpayne@68
|
168 def show_idle_news(self):
|
jpayne@68
|
169 "Handle News button event."
|
jpayne@68
|
170 self.display_file_text('About - NEWS', 'NEWS.txt', 'utf-8')
|
jpayne@68
|
171
|
jpayne@68
|
172 def display_printer_text(self, title, printer):
|
jpayne@68
|
173 """Create textview for built-in constants.
|
jpayne@68
|
174
|
jpayne@68
|
175 Built-in constants have type _sitebuiltins._Printer. The
|
jpayne@68
|
176 text is extracted from the built-in and then sent to a text
|
jpayne@68
|
177 viewer with self as the parent and title as the title of
|
jpayne@68
|
178 the popup.
|
jpayne@68
|
179 """
|
jpayne@68
|
180 printer._Printer__setup()
|
jpayne@68
|
181 text = '\n'.join(printer._Printer__lines)
|
jpayne@68
|
182 self._current_textview = textview.view_text(
|
jpayne@68
|
183 self, title, text, _utest=self._utest)
|
jpayne@68
|
184
|
jpayne@68
|
185 def display_file_text(self, title, filename, encoding=None):
|
jpayne@68
|
186 """Create textview for filename.
|
jpayne@68
|
187
|
jpayne@68
|
188 The filename needs to be in the current directory. The path
|
jpayne@68
|
189 is sent to a text viewer with self as the parent, title as
|
jpayne@68
|
190 the title of the popup, and the file encoding.
|
jpayne@68
|
191 """
|
jpayne@68
|
192 fn = os.path.join(os.path.abspath(os.path.dirname(__file__)), filename)
|
jpayne@68
|
193 self._current_textview = textview.view_file(
|
jpayne@68
|
194 self, title, fn, encoding, _utest=self._utest)
|
jpayne@68
|
195
|
jpayne@68
|
196 def ok(self, event=None):
|
jpayne@68
|
197 "Dismiss help_about dialog."
|
jpayne@68
|
198 self.grab_release()
|
jpayne@68
|
199 self.destroy()
|
jpayne@68
|
200
|
jpayne@68
|
201
|
jpayne@68
|
202 if __name__ == '__main__':
|
jpayne@68
|
203 from unittest import main
|
jpayne@68
|
204 main('idlelib.idle_test.test_help_about', verbosity=2, exit=False)
|
jpayne@68
|
205
|
jpayne@68
|
206 from idlelib.idle_test.htest import run
|
jpayne@68
|
207 run(AboutDialog)
|