1 | n/a | """About Dialog for IDLE |
---|
2 | n/a | |
---|
3 | n/a | """ |
---|
4 | n/a | import os |
---|
5 | n/a | from sys import version |
---|
6 | n/a | |
---|
7 | n/a | from tkinter import * |
---|
8 | n/a | |
---|
9 | n/a | from idlelib import textview |
---|
10 | n/a | |
---|
11 | n/a | |
---|
12 | n/a | class AboutDialog(Toplevel): |
---|
13 | n/a | """Modal about dialog for idle |
---|
14 | n/a | |
---|
15 | n/a | """ |
---|
16 | n/a | def __init__(self, parent, title, _htest=False): |
---|
17 | n/a | """ |
---|
18 | n/a | _htest - bool, change box location when running htest |
---|
19 | n/a | """ |
---|
20 | n/a | Toplevel.__init__(self, parent) |
---|
21 | n/a | self.configure(borderwidth=5) |
---|
22 | n/a | # place dialog below parent if running htest |
---|
23 | n/a | self.geometry("+%d+%d" % ( |
---|
24 | n/a | parent.winfo_rootx()+30, |
---|
25 | n/a | parent.winfo_rooty()+(30 if not _htest else 100))) |
---|
26 | n/a | self.bg = "#707070" |
---|
27 | n/a | self.fg = "#ffffff" |
---|
28 | n/a | self.CreateWidgets() |
---|
29 | n/a | self.resizable(height=FALSE, width=FALSE) |
---|
30 | n/a | self.title(title) |
---|
31 | n/a | self.transient(parent) |
---|
32 | n/a | self.grab_set() |
---|
33 | n/a | self.protocol("WM_DELETE_WINDOW", self.Ok) |
---|
34 | n/a | self.parent = parent |
---|
35 | n/a | self.buttonOk.focus_set() |
---|
36 | n/a | self.bind('<Return>',self.Ok) #dismiss dialog |
---|
37 | n/a | self.bind('<Escape>',self.Ok) #dismiss dialog |
---|
38 | n/a | self.wait_window() |
---|
39 | n/a | |
---|
40 | n/a | def CreateWidgets(self): |
---|
41 | n/a | release = version[:version.index(' ')] |
---|
42 | n/a | frameMain = Frame(self, borderwidth=2, relief=SUNKEN) |
---|
43 | n/a | frameButtons = Frame(self) |
---|
44 | n/a | frameButtons.pack(side=BOTTOM, fill=X) |
---|
45 | n/a | frameMain.pack(side=TOP, expand=TRUE, fill=BOTH) |
---|
46 | n/a | self.buttonOk = Button(frameButtons, text='Close', |
---|
47 | n/a | command=self.Ok) |
---|
48 | n/a | self.buttonOk.pack(padx=5, pady=5) |
---|
49 | n/a | #self.picture = Image('photo', data=self.pictureData) |
---|
50 | n/a | frameBg = Frame(frameMain, bg=self.bg) |
---|
51 | n/a | frameBg.pack(expand=TRUE, fill=BOTH) |
---|
52 | n/a | labelTitle = Label(frameBg, text='IDLE', fg=self.fg, bg=self.bg, |
---|
53 | n/a | font=('courier', 24, 'bold')) |
---|
54 | n/a | labelTitle.grid(row=0, column=0, sticky=W, padx=10, pady=10) |
---|
55 | n/a | #labelPicture = Label(frameBg, text='[picture]') |
---|
56 | n/a | #image=self.picture, bg=self.bg) |
---|
57 | n/a | #labelPicture.grid(row=1, column=1, sticky=W, rowspan=2, |
---|
58 | n/a | # padx=0, pady=3) |
---|
59 | n/a | byline = "Python's Integrated DeveLopment Environment" + 5*'\n' |
---|
60 | n/a | labelDesc = Label(frameBg, text=byline, justify=LEFT, |
---|
61 | n/a | fg=self.fg, bg=self.bg) |
---|
62 | n/a | labelDesc.grid(row=2, column=0, sticky=W, columnspan=3, padx=10, pady=5) |
---|
63 | n/a | labelEmail = Label(frameBg, text='email: idle-dev@python.org', |
---|
64 | n/a | justify=LEFT, fg=self.fg, bg=self.bg) |
---|
65 | n/a | labelEmail.grid(row=6, column=0, columnspan=2, |
---|
66 | n/a | sticky=W, padx=10, pady=0) |
---|
67 | n/a | labelWWW = Label(frameBg, text='https://docs.python.org/' + |
---|
68 | n/a | version[:3] + '/library/idle.html', |
---|
69 | n/a | justify=LEFT, fg=self.fg, bg=self.bg) |
---|
70 | n/a | labelWWW.grid(row=7, column=0, columnspan=2, sticky=W, padx=10, pady=0) |
---|
71 | n/a | Frame(frameBg, borderwidth=1, relief=SUNKEN, |
---|
72 | n/a | height=2, bg=self.bg).grid(row=8, column=0, sticky=EW, |
---|
73 | n/a | columnspan=3, padx=5, pady=5) |
---|
74 | n/a | labelPythonVer = Label(frameBg, text='Python version: ' + |
---|
75 | n/a | release, fg=self.fg, bg=self.bg) |
---|
76 | n/a | labelPythonVer.grid(row=9, column=0, sticky=W, padx=10, pady=0) |
---|
77 | n/a | tkVer = self.tk.call('info', 'patchlevel') |
---|
78 | n/a | labelTkVer = Label(frameBg, text='Tk version: '+ |
---|
79 | n/a | tkVer, fg=self.fg, bg=self.bg) |
---|
80 | n/a | labelTkVer.grid(row=9, column=1, sticky=W, padx=2, pady=0) |
---|
81 | n/a | py_button_f = Frame(frameBg, bg=self.bg) |
---|
82 | n/a | py_button_f.grid(row=10, column=0, columnspan=2, sticky=NSEW) |
---|
83 | n/a | buttonLicense = Button(py_button_f, text='License', width=8, |
---|
84 | n/a | highlightbackground=self.bg, |
---|
85 | n/a | command=self.ShowLicense) |
---|
86 | n/a | buttonLicense.pack(side=LEFT, padx=10, pady=10) |
---|
87 | n/a | buttonCopyright = Button(py_button_f, text='Copyright', width=8, |
---|
88 | n/a | highlightbackground=self.bg, |
---|
89 | n/a | command=self.ShowCopyright) |
---|
90 | n/a | buttonCopyright.pack(side=LEFT, padx=10, pady=10) |
---|
91 | n/a | buttonCredits = Button(py_button_f, text='Credits', width=8, |
---|
92 | n/a | highlightbackground=self.bg, |
---|
93 | n/a | command=self.ShowPythonCredits) |
---|
94 | n/a | buttonCredits.pack(side=LEFT, padx=10, pady=10) |
---|
95 | n/a | Frame(frameBg, borderwidth=1, relief=SUNKEN, |
---|
96 | n/a | height=2, bg=self.bg).grid(row=11, column=0, sticky=EW, |
---|
97 | n/a | columnspan=3, padx=5, pady=5) |
---|
98 | n/a | idle_v = Label(frameBg, text='IDLE version: ' + release, |
---|
99 | n/a | fg=self.fg, bg=self.bg) |
---|
100 | n/a | idle_v.grid(row=12, column=0, sticky=W, padx=10, pady=0) |
---|
101 | n/a | idle_button_f = Frame(frameBg, bg=self.bg) |
---|
102 | n/a | idle_button_f.grid(row=13, column=0, columnspan=3, sticky=NSEW) |
---|
103 | n/a | idle_about_b = Button(idle_button_f, text='README', width=8, |
---|
104 | n/a | highlightbackground=self.bg, |
---|
105 | n/a | command=self.ShowIDLEAbout) |
---|
106 | n/a | idle_about_b.pack(side=LEFT, padx=10, pady=10) |
---|
107 | n/a | idle_news_b = Button(idle_button_f, text='NEWS', width=8, |
---|
108 | n/a | highlightbackground=self.bg, |
---|
109 | n/a | command=self.ShowIDLENEWS) |
---|
110 | n/a | idle_news_b.pack(side=LEFT, padx=10, pady=10) |
---|
111 | n/a | idle_credits_b = Button(idle_button_f, text='Credits', width=8, |
---|
112 | n/a | highlightbackground=self.bg, |
---|
113 | n/a | command=self.ShowIDLECredits) |
---|
114 | n/a | idle_credits_b.pack(side=LEFT, padx=10, pady=10) |
---|
115 | n/a | |
---|
116 | n/a | # License, et all, are of type _sitebuiltins._Printer |
---|
117 | n/a | def ShowLicense(self): |
---|
118 | n/a | self.display_printer_text('About - License', license) |
---|
119 | n/a | |
---|
120 | n/a | def ShowCopyright(self): |
---|
121 | n/a | self.display_printer_text('About - Copyright', copyright) |
---|
122 | n/a | |
---|
123 | n/a | def ShowPythonCredits(self): |
---|
124 | n/a | self.display_printer_text('About - Python Credits', credits) |
---|
125 | n/a | |
---|
126 | n/a | # Encode CREDITS.txt to utf-8 for proper version of Loewis. |
---|
127 | n/a | # Specify others as ascii until need utf-8, so catch errors. |
---|
128 | n/a | def ShowIDLECredits(self): |
---|
129 | n/a | self.display_file_text('About - Credits', 'CREDITS.txt', 'utf-8') |
---|
130 | n/a | |
---|
131 | n/a | def ShowIDLEAbout(self): |
---|
132 | n/a | self.display_file_text('About - Readme', 'README.txt', 'ascii') |
---|
133 | n/a | |
---|
134 | n/a | def ShowIDLENEWS(self): |
---|
135 | n/a | self.display_file_text('About - NEWS', 'NEWS.txt', 'utf-8') |
---|
136 | n/a | |
---|
137 | n/a | def display_printer_text(self, title, printer): |
---|
138 | n/a | printer._Printer__setup() |
---|
139 | n/a | text = '\n'.join(printer._Printer__lines) |
---|
140 | n/a | textview.view_text(self, title, text) |
---|
141 | n/a | |
---|
142 | n/a | def display_file_text(self, title, filename, encoding=None): |
---|
143 | n/a | fn = os.path.join(os.path.abspath(os.path.dirname(__file__)), filename) |
---|
144 | n/a | textview.view_file(self, title, fn, encoding) |
---|
145 | n/a | |
---|
146 | n/a | def Ok(self, event=None): |
---|
147 | n/a | self.destroy() |
---|
148 | n/a | |
---|
149 | n/a | |
---|
150 | n/a | if __name__ == '__main__': |
---|
151 | n/a | import unittest |
---|
152 | n/a | unittest.main('idlelib.idle_test.test_help_about', verbosity=2, exit=False) |
---|
153 | n/a | from idlelib.idle_test.htest import run |
---|
154 | n/a | run(AboutDialog) |
---|