Debian Codegraph @

cpython27/Lib/idlelib/aboutDialog.py

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