jpayne@69: """About Dialog for IDLE jpayne@69: jpayne@69: """ jpayne@69: import os jpayne@69: import sys jpayne@69: from platform import python_version, architecture jpayne@69: jpayne@69: from tkinter import Toplevel, Frame, Label, Button, PhotoImage jpayne@69: from tkinter import SUNKEN, TOP, BOTTOM, LEFT, X, BOTH, W, EW, NSEW, E jpayne@69: jpayne@69: from idlelib import textview jpayne@69: jpayne@69: jpayne@69: def build_bits(): jpayne@69: "Return bits for platform." jpayne@69: if sys.platform == 'darwin': jpayne@69: return '64' if sys.maxsize > 2**32 else '32' jpayne@69: else: jpayne@69: return architecture()[0][:2] jpayne@69: jpayne@69: jpayne@69: class AboutDialog(Toplevel): jpayne@69: """Modal about dialog for idle jpayne@69: jpayne@69: """ jpayne@69: def __init__(self, parent, title=None, *, _htest=False, _utest=False): jpayne@69: """Create popup, do not return until tk widget destroyed. jpayne@69: jpayne@69: parent - parent of this dialog jpayne@69: title - string which is title of popup dialog jpayne@69: _htest - bool, change box location when running htest jpayne@69: _utest - bool, don't wait_window when running unittest jpayne@69: """ jpayne@69: Toplevel.__init__(self, parent) jpayne@69: self.configure(borderwidth=5) jpayne@69: # place dialog below parent if running htest jpayne@69: self.geometry("+%d+%d" % ( jpayne@69: parent.winfo_rootx()+30, jpayne@69: parent.winfo_rooty()+(30 if not _htest else 100))) jpayne@69: self.bg = "#bbbbbb" jpayne@69: self.fg = "#000000" jpayne@69: self.create_widgets() jpayne@69: self.resizable(height=False, width=False) jpayne@69: self.title(title or jpayne@69: f'About IDLE {python_version()} ({build_bits()} bit)') jpayne@69: self.transient(parent) jpayne@69: self.grab_set() jpayne@69: self.protocol("WM_DELETE_WINDOW", self.ok) jpayne@69: self.parent = parent jpayne@69: self.button_ok.focus_set() jpayne@69: self.bind('', self.ok) # dismiss dialog jpayne@69: self.bind('', self.ok) # dismiss dialog jpayne@69: self._current_textview = None jpayne@69: self._utest = _utest jpayne@69: jpayne@69: if not _utest: jpayne@69: self.deiconify() jpayne@69: self.wait_window() jpayne@69: jpayne@69: def create_widgets(self): jpayne@69: frame = Frame(self, borderwidth=2, relief=SUNKEN) jpayne@69: frame_buttons = Frame(self) jpayne@69: frame_buttons.pack(side=BOTTOM, fill=X) jpayne@69: frame.pack(side=TOP, expand=True, fill=BOTH) jpayne@69: self.button_ok = Button(frame_buttons, text='Close', jpayne@69: command=self.ok) jpayne@69: self.button_ok.pack(padx=5, pady=5) jpayne@69: jpayne@69: frame_background = Frame(frame, bg=self.bg) jpayne@69: frame_background.pack(expand=True, fill=BOTH) jpayne@69: jpayne@69: header = Label(frame_background, text='IDLE', fg=self.fg, jpayne@69: bg=self.bg, font=('courier', 24, 'bold')) jpayne@69: header.grid(row=0, column=0, sticky=E, padx=10, pady=10) jpayne@69: jpayne@69: tk_patchlevel = self.tk.call('info', 'patchlevel') jpayne@69: ext = '.png' if tk_patchlevel >= '8.6' else '.gif' jpayne@69: icon = os.path.join(os.path.abspath(os.path.dirname(__file__)), jpayne@69: 'Icons', f'idle_48{ext}') jpayne@69: self.icon_image = PhotoImage(master=self._root(), file=icon) jpayne@69: logo = Label(frame_background, image=self.icon_image, bg=self.bg) jpayne@69: logo.grid(row=0, column=0, sticky=W, rowspan=2, padx=10, pady=10) jpayne@69: jpayne@69: byline_text = "Python's Integrated Development\nand Learning Environment" + 5*'\n' jpayne@69: byline = Label(frame_background, text=byline_text, justify=LEFT, jpayne@69: fg=self.fg, bg=self.bg) jpayne@69: byline.grid(row=2, column=0, sticky=W, columnspan=3, padx=10, pady=5) jpayne@69: email = Label(frame_background, text='email: idle-dev@python.org', jpayne@69: justify=LEFT, fg=self.fg, bg=self.bg) jpayne@69: email.grid(row=6, column=0, columnspan=2, sticky=W, padx=10, pady=0) jpayne@69: docs = Label(frame_background, text='https://docs.python.org/' + jpayne@69: python_version()[:3] + '/library/idle.html', jpayne@69: justify=LEFT, fg=self.fg, bg=self.bg) jpayne@69: docs.grid(row=7, column=0, columnspan=2, sticky=W, padx=10, pady=0) jpayne@69: jpayne@69: Frame(frame_background, borderwidth=1, relief=SUNKEN, jpayne@69: height=2, bg=self.bg).grid(row=8, column=0, sticky=EW, jpayne@69: columnspan=3, padx=5, pady=5) jpayne@69: jpayne@69: pyver = Label(frame_background, jpayne@69: text='Python version: ' + python_version(), jpayne@69: fg=self.fg, bg=self.bg) jpayne@69: pyver.grid(row=9, column=0, sticky=W, padx=10, pady=0) jpayne@69: tkver = Label(frame_background, text='Tk version: ' + tk_patchlevel, jpayne@69: fg=self.fg, bg=self.bg) jpayne@69: tkver.grid(row=9, column=1, sticky=W, padx=2, pady=0) jpayne@69: py_buttons = Frame(frame_background, bg=self.bg) jpayne@69: py_buttons.grid(row=10, column=0, columnspan=2, sticky=NSEW) jpayne@69: self.py_license = Button(py_buttons, text='License', width=8, jpayne@69: highlightbackground=self.bg, jpayne@69: command=self.show_py_license) jpayne@69: self.py_license.pack(side=LEFT, padx=10, pady=10) jpayne@69: self.py_copyright = Button(py_buttons, text='Copyright', width=8, jpayne@69: highlightbackground=self.bg, jpayne@69: command=self.show_py_copyright) jpayne@69: self.py_copyright.pack(side=LEFT, padx=10, pady=10) jpayne@69: self.py_credits = Button(py_buttons, text='Credits', width=8, jpayne@69: highlightbackground=self.bg, jpayne@69: command=self.show_py_credits) jpayne@69: self.py_credits.pack(side=LEFT, padx=10, pady=10) jpayne@69: jpayne@69: Frame(frame_background, borderwidth=1, relief=SUNKEN, jpayne@69: height=2, bg=self.bg).grid(row=11, column=0, sticky=EW, jpayne@69: columnspan=3, padx=5, pady=5) jpayne@69: jpayne@69: idlever = Label(frame_background, jpayne@69: text='IDLE version: ' + python_version(), jpayne@69: fg=self.fg, bg=self.bg) jpayne@69: idlever.grid(row=12, column=0, sticky=W, padx=10, pady=0) jpayne@69: idle_buttons = Frame(frame_background, bg=self.bg) jpayne@69: idle_buttons.grid(row=13, column=0, columnspan=3, sticky=NSEW) jpayne@69: self.readme = Button(idle_buttons, text='README', width=8, jpayne@69: highlightbackground=self.bg, jpayne@69: command=self.show_readme) jpayne@69: self.readme.pack(side=LEFT, padx=10, pady=10) jpayne@69: self.idle_news = Button(idle_buttons, text='NEWS', width=8, jpayne@69: highlightbackground=self.bg, jpayne@69: command=self.show_idle_news) jpayne@69: self.idle_news.pack(side=LEFT, padx=10, pady=10) jpayne@69: self.idle_credits = Button(idle_buttons, text='Credits', width=8, jpayne@69: highlightbackground=self.bg, jpayne@69: command=self.show_idle_credits) jpayne@69: self.idle_credits.pack(side=LEFT, padx=10, pady=10) jpayne@69: jpayne@69: # License, copyright, and credits are of type _sitebuiltins._Printer jpayne@69: def show_py_license(self): jpayne@69: "Handle License button event." jpayne@69: self.display_printer_text('About - License', license) jpayne@69: jpayne@69: def show_py_copyright(self): jpayne@69: "Handle Copyright button event." jpayne@69: self.display_printer_text('About - Copyright', copyright) jpayne@69: jpayne@69: def show_py_credits(self): jpayne@69: "Handle Python Credits button event." jpayne@69: self.display_printer_text('About - Python Credits', credits) jpayne@69: jpayne@69: # Encode CREDITS.txt to utf-8 for proper version of Loewis. jpayne@69: # Specify others as ascii until need utf-8, so catch errors. jpayne@69: def show_idle_credits(self): jpayne@69: "Handle Idle Credits button event." jpayne@69: self.display_file_text('About - Credits', 'CREDITS.txt', 'utf-8') jpayne@69: jpayne@69: def show_readme(self): jpayne@69: "Handle Readme button event." jpayne@69: self.display_file_text('About - Readme', 'README.txt', 'ascii') jpayne@69: jpayne@69: def show_idle_news(self): jpayne@69: "Handle News button event." jpayne@69: self.display_file_text('About - NEWS', 'NEWS.txt', 'utf-8') jpayne@69: jpayne@69: def display_printer_text(self, title, printer): jpayne@69: """Create textview for built-in constants. jpayne@69: jpayne@69: Built-in constants have type _sitebuiltins._Printer. The jpayne@69: text is extracted from the built-in and then sent to a text jpayne@69: viewer with self as the parent and title as the title of jpayne@69: the popup. jpayne@69: """ jpayne@69: printer._Printer__setup() jpayne@69: text = '\n'.join(printer._Printer__lines) jpayne@69: self._current_textview = textview.view_text( jpayne@69: self, title, text, _utest=self._utest) jpayne@69: jpayne@69: def display_file_text(self, title, filename, encoding=None): jpayne@69: """Create textview for filename. jpayne@69: jpayne@69: The filename needs to be in the current directory. The path jpayne@69: is sent to a text viewer with self as the parent, title as jpayne@69: the title of the popup, and the file encoding. jpayne@69: """ jpayne@69: fn = os.path.join(os.path.abspath(os.path.dirname(__file__)), filename) jpayne@69: self._current_textview = textview.view_file( jpayne@69: self, title, fn, encoding, _utest=self._utest) jpayne@69: jpayne@69: def ok(self, event=None): jpayne@69: "Dismiss help_about dialog." jpayne@69: self.grab_release() jpayne@69: self.destroy() jpayne@69: jpayne@69: jpayne@69: if __name__ == '__main__': jpayne@69: from unittest import main jpayne@69: main('idlelib.idle_test.test_help_about', verbosity=2, exit=False) jpayne@69: jpayne@69: from idlelib.idle_test.htest import run jpayne@69: run(AboutDialog)