blob: 019aacbd0faa20711bb9a2617a1f5f9751304959 [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
csabella9a02ae32017-06-26 22:28:58 -04005import sys
6from platform import python_version, architecture
Terry Jan Reedybfbaa6b2016-08-31 00:50:55 -04007
csabellad352d682017-06-23 12:00:29 -04008from tkinter import Toplevel, Frame, Label, Button, PhotoImage
9from tkinter import SUNKEN, TOP, BOTTOM, LEFT, X, BOTH, W, EW, NSEW, E
Terry Jan Reedybfbaa6b2016-08-31 00:50:55 -040010
Terry Jan Reedy6fa5bdc2016-05-28 13:22:31 -040011from idlelib import textview
Neal Norwitz539594f2002-11-30 19:12:41 +000012
Miss Islington (bot)03c7b352021-09-10 14:34:07 -070013version = python_version()
14
Terry Jan Reedybfbaa6b2016-08-31 00:50:55 -040015
csabella9a02ae32017-06-26 22:28:58 -040016def build_bits():
17 "Return bits for platform."
18 if sys.platform == 'darwin':
19 return '64' if sys.maxsize > 2**32 else '32'
20 else:
21 return architecture()[0][:2]
22
23
Steven M. Gava44d3d1a2001-07-31 06:59:02 +000024class AboutDialog(Toplevel):
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +000025 """Modal about dialog for idle
26
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +000027 """
Terry Jan Reedybfebfd82017-09-30 17:37:53 -040028 def __init__(self, parent, title=None, *, _htest=False, _utest=False):
csabella5a346d52017-05-27 15:49:26 -040029 """Create popup, do not return until tk widget destroyed.
30
31 parent - parent of this dialog
32 title - string which is title of popup dialog
Terry Jan Reedy1b392ff2014-05-24 18:48:18 -040033 _htest - bool, change box location when running htest
mlouielu054e0912017-05-22 06:19:35 +080034 _utest - bool, don't wait_window when running unittest
Terry Jan Reedy1b392ff2014-05-24 18:48:18 -040035 """
Steven M. Gava885c0bb2001-07-31 10:44:35 +000036 Toplevel.__init__(self, parent)
37 self.configure(borderwidth=5)
Terry Jan Reedy1b392ff2014-05-24 18:48:18 -040038 # place dialog below parent if running htest
39 self.geometry("+%d+%d" % (
40 parent.winfo_rootx()+30,
41 parent.winfo_rooty()+(30 if not _htest else 100)))
csabella9a02ae32017-06-26 22:28:58 -040042 self.bg = "#bbbbbb"
43 self.fg = "#000000"
csabella5a346d52017-05-27 15:49:26 -040044 self.create_widgets()
45 self.resizable(height=False, width=False)
csabella9a02ae32017-06-26 22:28:58 -040046 self.title(title or
Miss Islington (bot)03c7b352021-09-10 14:34:07 -070047 f'About IDLE {version} ({build_bits()} bit)')
Steven M. Gava885c0bb2001-07-31 10:44:35 +000048 self.transient(parent)
49 self.grab_set()
csabella5a346d52017-05-27 15:49:26 -040050 self.protocol("WM_DELETE_WINDOW", self.ok)
Steven M. Gava885c0bb2001-07-31 10:44:35 +000051 self.parent = parent
csabella5a346d52017-05-27 15:49:26 -040052 self.button_ok.focus_set()
53 self.bind('<Return>', self.ok) # dismiss dialog
54 self.bind('<Escape>', self.ok) # dismiss dialog
mlouielu054e0912017-05-22 06:19:35 +080055 self._current_textview = None
56 self._utest = _utest
57
58 if not _utest:
59 self.deiconify()
60 self.wait_window()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +000061
csabella5a346d52017-05-27 15:49:26 -040062 def create_widgets(self):
csabella5a346d52017-05-27 15:49:26 -040063 frame = Frame(self, borderwidth=2, relief=SUNKEN)
64 frame_buttons = Frame(self)
65 frame_buttons.pack(side=BOTTOM, fill=X)
66 frame.pack(side=TOP, expand=True, fill=BOTH)
67 self.button_ok = Button(frame_buttons, text='Close',
68 command=self.ok)
69 self.button_ok.pack(padx=5, pady=5)
70
71 frame_background = Frame(frame, bg=self.bg)
72 frame_background.pack(expand=True, fill=BOTH)
73
74 header = Label(frame_background, text='IDLE', fg=self.fg,
75 bg=self.bg, font=('courier', 24, 'bold'))
csabellad352d682017-06-23 12:00:29 -040076 header.grid(row=0, column=0, sticky=E, padx=10, pady=10)
77
78 tk_patchlevel = self.tk.call('info', 'patchlevel')
79 ext = '.png' if tk_patchlevel >= '8.6' else '.gif'
80 icon = os.path.join(os.path.abspath(os.path.dirname(__file__)),
81 'Icons', f'idle_48{ext}')
82 self.icon_image = PhotoImage(master=self._root(), file=icon)
83 logo = Label(frame_background, image=self.icon_image, bg=self.bg)
84 logo.grid(row=0, column=0, sticky=W, rowspan=2, padx=10, pady=10)
85
Mark Roseman592eda12017-06-27 19:42:10 -070086 byline_text = "Python's Integrated Development\nand Learning Environment" + 5*'\n'
csabella5a346d52017-05-27 15:49:26 -040087 byline = Label(frame_background, text=byline_text, justify=LEFT,
88 fg=self.fg, bg=self.bg)
89 byline.grid(row=2, column=0, sticky=W, columnspan=3, padx=10, pady=5)
90 email = Label(frame_background, text='email: idle-dev@python.org',
91 justify=LEFT, fg=self.fg, bg=self.bg)
92 email.grid(row=6, column=0, columnspan=2, sticky=W, padx=10, pady=0)
Miss Islington (bot)03c7b352021-09-10 14:34:07 -070093 docs = Label(frame_background, text="https://docs.python.org/"
94 f"{version[:version.rindex('.')]}/library/idle.html",
csabella5a346d52017-05-27 15:49:26 -040095 justify=LEFT, fg=self.fg, bg=self.bg)
96 docs.grid(row=7, column=0, columnspan=2, sticky=W, padx=10, pady=0)
97
98 Frame(frame_background, borderwidth=1, relief=SUNKEN,
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +000099 height=2, bg=self.bg).grid(row=8, column=0, sticky=EW,
100 columnspan=3, padx=5, pady=5)
csabella5a346d52017-05-27 15:49:26 -0400101
csabella18ede062017-06-23 20:00:58 -0400102 pyver = Label(frame_background,
Miss Islington (bot)03c7b352021-09-10 14:34:07 -0700103 text='Python version: ' + version,
csabella5a346d52017-05-27 15:49:26 -0400104 fg=self.fg, bg=self.bg)
105 pyver.grid(row=9, column=0, sticky=W, padx=10, pady=0)
csabella5a346d52017-05-27 15:49:26 -0400106 tkver = Label(frame_background, text='Tk version: ' + tk_patchlevel,
107 fg=self.fg, bg=self.bg)
108 tkver.grid(row=9, column=1, sticky=W, padx=2, pady=0)
109 py_buttons = Frame(frame_background, bg=self.bg)
110 py_buttons.grid(row=10, column=0, columnspan=2, sticky=NSEW)
111 self.py_license = Button(py_buttons, text='License', width=8,
112 highlightbackground=self.bg,
113 command=self.show_py_license)
114 self.py_license.pack(side=LEFT, padx=10, pady=10)
115 self.py_copyright = Button(py_buttons, text='Copyright', width=8,
116 highlightbackground=self.bg,
117 command=self.show_py_copyright)
118 self.py_copyright.pack(side=LEFT, padx=10, pady=10)
119 self.py_credits = Button(py_buttons, text='Credits', width=8,
120 highlightbackground=self.bg,
121 command=self.show_py_credits)
122 self.py_credits.pack(side=LEFT, padx=10, pady=10)
123
124 Frame(frame_background, borderwidth=1, relief=SUNKEN,
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +0000125 height=2, bg=self.bg).grid(row=11, column=0, sticky=EW,
126 columnspan=3, padx=5, pady=5)
Steven M. Gava885c0bb2001-07-31 10:44:35 +0000127
csabella18ede062017-06-23 20:00:58 -0400128 idlever = Label(frame_background,
Miss Islington (bot)03c7b352021-09-10 14:34:07 -0700129 text='IDLE version: ' + version,
csabella5a346d52017-05-27 15:49:26 -0400130 fg=self.fg, bg=self.bg)
131 idlever.grid(row=12, column=0, sticky=W, padx=10, pady=0)
132 idle_buttons = Frame(frame_background, bg=self.bg)
133 idle_buttons.grid(row=13, column=0, columnspan=3, sticky=NSEW)
134 self.readme = Button(idle_buttons, text='README', width=8,
135 highlightbackground=self.bg,
136 command=self.show_readme)
137 self.readme.pack(side=LEFT, padx=10, pady=10)
138 self.idle_news = Button(idle_buttons, text='NEWS', width=8,
139 highlightbackground=self.bg,
140 command=self.show_idle_news)
141 self.idle_news.pack(side=LEFT, padx=10, pady=10)
142 self.idle_credits = Button(idle_buttons, text='Credits', width=8,
143 highlightbackground=self.bg,
144 command=self.show_idle_credits)
145 self.idle_credits.pack(side=LEFT, padx=10, pady=10)
146
147 # License, copyright, and credits are of type _sitebuiltins._Printer
148 def show_py_license(self):
149 "Handle License button event."
Guido van Rossum8ce8a782007-11-01 19:42:39 +0000150 self.display_printer_text('About - License', license)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000151
csabella5a346d52017-05-27 15:49:26 -0400152 def show_py_copyright(self):
153 "Handle Copyright button event."
Guido van Rossum8ce8a782007-11-01 19:42:39 +0000154 self.display_printer_text('About - Copyright', copyright)
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +0000155
csabella5a346d52017-05-27 15:49:26 -0400156 def show_py_credits(self):
157 "Handle Python Credits button event."
Guido van Rossum8ce8a782007-11-01 19:42:39 +0000158 self.display_printer_text('About - Python Credits', credits)
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +0000159
Terry Jan Reedy35676512016-01-16 23:44:04 -0500160 # Encode CREDITS.txt to utf-8 for proper version of Loewis.
161 # Specify others as ascii until need utf-8, so catch errors.
csabella5a346d52017-05-27 15:49:26 -0400162 def show_idle_credits(self):
163 "Handle Idle Credits button event."
Terry Jan Reedy35676512016-01-16 23:44:04 -0500164 self.display_file_text('About - Credits', 'CREDITS.txt', 'utf-8')
Steven M. Gava885c0bb2001-07-31 10:44:35 +0000165
csabella5a346d52017-05-27 15:49:26 -0400166 def show_readme(self):
167 "Handle Readme button event."
Terry Jan Reedy35676512016-01-16 23:44:04 -0500168 self.display_file_text('About - Readme', 'README.txt', 'ascii')
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +0000169
csabella5a346d52017-05-27 15:49:26 -0400170 def show_idle_news(self):
171 "Handle News button event."
Terry Jan Reedy6ff7a142016-06-22 03:55:20 -0400172 self.display_file_text('About - NEWS', 'NEWS.txt', 'utf-8')
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +0000173
Guido van Rossum8ce8a782007-11-01 19:42:39 +0000174 def display_printer_text(self, title, printer):
csabella5a346d52017-05-27 15:49:26 -0400175 """Create textview for built-in constants.
176
177 Built-in constants have type _sitebuiltins._Printer. The
178 text is extracted from the built-in and then sent to a text
179 viewer with self as the parent and title as the title of
180 the popup.
181 """
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +0000182 printer._Printer__setup()
Guido van Rossum8ce8a782007-11-01 19:42:39 +0000183 text = '\n'.join(printer._Printer__lines)
mlouielu054e0912017-05-22 06:19:35 +0800184 self._current_textview = textview.view_text(
185 self, title, text, _utest=self._utest)
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +0000186
Guido van Rossum8ce8a782007-11-01 19:42:39 +0000187 def display_file_text(self, title, filename, encoding=None):
csabella5a346d52017-05-27 15:49:26 -0400188 """Create textview for filename.
189
190 The filename needs to be in the current directory. The path
191 is sent to a text viewer with self as the parent, title as
192 the title of the popup, and the file encoding.
193 """
Guido van Rossum8ce8a782007-11-01 19:42:39 +0000194 fn = os.path.join(os.path.abspath(os.path.dirname(__file__)), filename)
mlouielu054e0912017-05-22 06:19:35 +0800195 self._current_textview = textview.view_file(
196 self, title, fn, encoding, _utest=self._utest)
Steven M. Gava885c0bb2001-07-31 10:44:35 +0000197
csabella5a346d52017-05-27 15:49:26 -0400198 def ok(self, event=None):
199 "Dismiss help_about dialog."
Tal Einat10ea9402018-08-02 09:18:29 +0300200 self.grab_release()
Steven M. Gava885c0bb2001-07-31 10:44:35 +0000201 self.destroy()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000202
Terry Jan Reedybfbaa6b2016-08-31 00:50:55 -0400203
Steven M. Gava44d3d1a2001-07-31 06:59:02 +0000204if __name__ == '__main__':
Terry Jan Reedyea3dc802018-06-18 04:47:59 -0400205 from unittest import main
206 main('idlelib.idle_test.test_help_about', verbosity=2, exit=False)
207
Terry Jan Reedy06313b72014-05-11 23:32:32 -0400208 from idlelib.idle_test.htest import run
209 run(AboutDialog)