blob: e65e67c47ee0d7560c78dd7fe16ee745a99e959c [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
Terry Jan Reedy296c66e2015-05-16 19:28:32 -04005from sys import 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 """
terryjreedy12cbd872017-06-10 02:53:19 -040017 def __init__(self, parent, title, _htest=False, _utest=False):
18 """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)
Steven M. Gava885c0bb2001-07-31 10:44:35 +000035 self.title(title)
36 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):
Terry Jan Reedy296c66e2015-05-16 19:28:32 -040051 release = version[:version.index(' ')]
terryjreedy12cbd872017-06-10 02:53:19 -040052 frame = Frame(self, borderwidth=2, relief=SUNKEN)
53 frame_buttons = Frame(self)
54 frame_buttons.pack(side=BOTTOM, fill=X)
55 frame.pack(side=TOP, expand=True, fill=BOTH)
56 self.button_ok = Button(frame_buttons, text='Close',
57 command=self.ok)
58 self.button_ok.pack(padx=5, pady=5)
59
60 frame_background = Frame(frame, bg=self.bg)
61 frame_background.pack(expand=True, fill=BOTH)
62
63 header = Label(frame_background, text='IDLE', fg=self.fg,
64 bg=self.bg, font=('courier', 24, 'bold'))
terryjreedy1b7474d2017-06-23 12:59:59 -040065 header.grid(row=0, column=0, sticky=E, padx=10, pady=10)
66
67 tk_patchlevel = self.tk.call('info', 'patchlevel')
68 ext = '.png' if tk_patchlevel >= '8.6' else '.gif'
69 icon = os.path.join(os.path.abspath(os.path.dirname(__file__)),
70 'Icons', f'idle_48{ext}')
71 self.icon_image = PhotoImage(master=self._root(), file=icon)
72 logo = Label(frame_background, image=self.icon_image, bg=self.bg)
73 logo.grid(row=0, column=0, sticky=W, rowspan=2, padx=10, pady=10)
74
terryjreedy12cbd872017-06-10 02:53:19 -040075 byline_text = "Python's Integrated DeveLopment Environment" + 5*'\n'
76 byline = Label(frame_background, text=byline_text, justify=LEFT,
77 fg=self.fg, bg=self.bg)
78 byline.grid(row=2, column=0, sticky=W, columnspan=3, padx=10, pady=5)
79 email = Label(frame_background, text='email: idle-dev@python.org',
80 justify=LEFT, fg=self.fg, bg=self.bg)
81 email.grid(row=6, column=0, columnspan=2, sticky=W, padx=10, pady=0)
82 docs = Label(frame_background, text='https://docs.python.org/' +
83 version[:3] + '/library/idle.html',
84 justify=LEFT, fg=self.fg, bg=self.bg)
85 docs.grid(row=7, column=0, columnspan=2, sticky=W, padx=10, pady=0)
86
87 Frame(frame_background, borderwidth=1, relief=SUNKEN,
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +000088 height=2, bg=self.bg).grid(row=8, column=0, sticky=EW,
89 columnspan=3, padx=5, pady=5)
terryjreedy12cbd872017-06-10 02:53:19 -040090
91 pyver = Label(frame_background, text='Python version: ' + release,
92 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
terryjreedy12cbd872017-06-10 02:53:19 -0400116 idlever = Label(frame_background, text='IDLE version: ' + release,
117 fg=self.fg, bg=self.bg)
118 idlever.grid(row=12, column=0, sticky=W, padx=10, pady=0)
119 idle_buttons = Frame(frame_background, bg=self.bg)
120 idle_buttons.grid(row=13, column=0, columnspan=3, sticky=NSEW)
121 self.readme = Button(idle_buttons, text='README', width=8,
122 highlightbackground=self.bg,
123 command=self.show_readme)
124 self.readme.pack(side=LEFT, padx=10, pady=10)
125 self.idle_news = Button(idle_buttons, text='NEWS', width=8,
126 highlightbackground=self.bg,
127 command=self.show_idle_news)
128 self.idle_news.pack(side=LEFT, padx=10, pady=10)
129 self.idle_credits = Button(idle_buttons, text='Credits', width=8,
130 highlightbackground=self.bg,
131 command=self.show_idle_credits)
132 self.idle_credits.pack(side=LEFT, padx=10, pady=10)
133
134 # License, copyright, and credits are of type _sitebuiltins._Printer
135 def show_py_license(self):
136 "Handle License button event."
Guido van Rossum8ce8a782007-11-01 19:42:39 +0000137 self.display_printer_text('About - License', license)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000138
terryjreedy12cbd872017-06-10 02:53:19 -0400139 def show_py_copyright(self):
140 "Handle Copyright button event."
Guido van Rossum8ce8a782007-11-01 19:42:39 +0000141 self.display_printer_text('About - Copyright', copyright)
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +0000142
terryjreedy12cbd872017-06-10 02:53:19 -0400143 def show_py_credits(self):
144 "Handle Python Credits button event."
Guido van Rossum8ce8a782007-11-01 19:42:39 +0000145 self.display_printer_text('About - Python Credits', credits)
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +0000146
Terry Jan Reedy35676512016-01-16 23:44:04 -0500147 # Encode CREDITS.txt to utf-8 for proper version of Loewis.
148 # Specify others as ascii until need utf-8, so catch errors.
terryjreedy12cbd872017-06-10 02:53:19 -0400149 def show_idle_credits(self):
150 "Handle Idle Credits button event."
Terry Jan Reedy35676512016-01-16 23:44:04 -0500151 self.display_file_text('About - Credits', 'CREDITS.txt', 'utf-8')
Steven M. Gava885c0bb2001-07-31 10:44:35 +0000152
terryjreedy12cbd872017-06-10 02:53:19 -0400153 def show_readme(self):
154 "Handle Readme button event."
Terry Jan Reedy35676512016-01-16 23:44:04 -0500155 self.display_file_text('About - Readme', 'README.txt', 'ascii')
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +0000156
terryjreedy12cbd872017-06-10 02:53:19 -0400157 def show_idle_news(self):
158 "Handle News button event."
Terry Jan Reedy6ff7a142016-06-22 03:55:20 -0400159 self.display_file_text('About - NEWS', 'NEWS.txt', 'utf-8')
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +0000160
Guido van Rossum8ce8a782007-11-01 19:42:39 +0000161 def display_printer_text(self, title, printer):
terryjreedy12cbd872017-06-10 02:53:19 -0400162 """Create textview for built-in constants.
163
164 Built-in constants have type _sitebuiltins._Printer. The
165 text is extracted from the built-in and then sent to a text
166 viewer with self as the parent and title as the title of
167 the popup.
168 """
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +0000169 printer._Printer__setup()
Guido van Rossum8ce8a782007-11-01 19:42:39 +0000170 text = '\n'.join(printer._Printer__lines)
terryjreedy12cbd872017-06-10 02:53:19 -0400171 self._current_textview = textview.view_text(
172 self, title, text, _utest=self._utest)
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +0000173
Guido van Rossum8ce8a782007-11-01 19:42:39 +0000174 def display_file_text(self, title, filename, encoding=None):
terryjreedy12cbd872017-06-10 02:53:19 -0400175 """Create textview for filename.
Steven M. Gava885c0bb2001-07-31 10:44:35 +0000176
terryjreedy12cbd872017-06-10 02:53:19 -0400177 The filename needs to be in the current directory. The path
178 is sent to a text viewer with self as the parent, title as
179 the title of the popup, and the file encoding.
180 """
181 fn = os.path.join(os.path.abspath(os.path.dirname(__file__)), filename)
182 self._current_textview = textview.view_file(
183 self, title, fn, encoding, _utest=self._utest)
184
185 def ok(self, event=None):
186 "Dismiss help_about dialog."
Steven M. Gava885c0bb2001-07-31 10:44:35 +0000187 self.destroy()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000188
Terry Jan Reedybfbaa6b2016-08-31 00:50:55 -0400189
Steven M. Gava44d3d1a2001-07-31 06:59:02 +0000190if __name__ == '__main__':
Terry Jan Reedydf1d34c2016-06-22 04:50:16 -0400191 import unittest
Terry Jan Reedy47e00e52016-06-22 05:49:15 -0400192 unittest.main('idlelib.idle_test.test_help_about', verbosity=2, exit=False)
Terry Jan Reedy06313b72014-05-11 23:32:32 -0400193 from idlelib.idle_test.htest import run
194 run(AboutDialog)