1 """About Dialog for IDLE
10 class AboutDialog(Toplevel
):
11 """Modal about dialog for idle
14 def __init__(self
,parent
,title
):
15 Toplevel
.__init
__(self
, parent
)
16 self
.configure(borderwidth
=5)
17 self
.geometry("+%d+%d" % (parent
.winfo_rootx()+30,
18 parent
.winfo_rooty()+30))
22 self
.resizable(height
=FALSE
, width
=FALSE
)
24 self
.transient(parent
)
26 self
.protocol("WM_DELETE_WINDOW", self
.Ok
)
28 self
.buttonOk
.focus_set()
29 self
.bind('<Return>',self
.Ok
) #dismiss dialog
30 self
.bind('<Escape>',self
.Ok
) #dismiss dialog
33 def CreateWidgets(self
):
34 frameMain
= Frame(self
, borderwidth
=2, relief
=SUNKEN
)
35 frameButtons
= Frame(self
)
36 frameButtons
.pack(side
=BOTTOM
, fill
=X
)
37 frameMain
.pack(side
=TOP
, expand
=TRUE
, fill
=BOTH
)
38 self
.buttonOk
= Button(frameButtons
, text
='Close',
40 self
.buttonOk
.pack(padx
=5, pady
=5)
41 #self.picture = Image('photo', data=self.pictureData)
42 frameBg
= Frame(frameMain
, bg
=self
.bg
)
43 frameBg
.pack(expand
=TRUE
, fill
=BOTH
)
44 labelTitle
= Label(frameBg
, text
='IDLE', fg
=self
.fg
, bg
=self
.bg
,
45 font
=('courier', 24, 'bold'))
46 labelTitle
.grid(row
=0, column
=0, sticky
=W
, padx
=10, pady
=10)
47 #labelPicture = Label(frameBg, text='[picture]')
48 #image=self.picture, bg=self.bg)
49 #labelPicture.grid(row=1, column=1, sticky=W, rowspan=2,
51 byline
= "Python's Integrated DeveLopment Environment" + 5*'\n'
52 labelDesc
= Label(frameBg
, text
=byline
, justify
=LEFT
,
53 fg
=self
.fg
, bg
=self
.bg
)
54 labelDesc
.grid(row
=2, column
=0, sticky
=W
, columnspan
=3, padx
=10, pady
=5)
55 labelEmail
= Label(frameBg
, text
='email: idle-dev@python.org',
56 justify
=LEFT
, fg
=self
.fg
, bg
=self
.bg
)
57 labelEmail
.grid(row
=6, column
=0, columnspan
=2,
58 sticky
=W
, padx
=10, pady
=0)
59 labelWWW
= Label(frameBg
, text
='www: http://www.python.org/idle/',
60 justify
=LEFT
, fg
=self
.fg
, bg
=self
.bg
)
61 labelWWW
.grid(row
=7, column
=0, columnspan
=2, sticky
=W
, padx
=10, pady
=0)
62 Frame(frameBg
, borderwidth
=1, relief
=SUNKEN
,
63 height
=2, bg
=self
.bg
).grid(row
=8, column
=0, sticky
=EW
,
64 columnspan
=3, padx
=5, pady
=5)
65 labelPythonVer
= Label(frameBg
, text
='Python version: ' + \
66 sys
.version
.split()[0], fg
=self
.fg
, bg
=self
.bg
)
67 labelPythonVer
.grid(row
=9, column
=0, sticky
=W
, padx
=10, pady
=0)
68 # handle weird tk version num in windoze python >= 1.6 (?!?)
69 tkVer
= repr(TkVersion
).split('.')
70 tkVer
[len(tkVer
)-1] = str('%.3g' % (float('.'+tkVer
[len(tkVer
)-1])))[2:]
71 if tkVer
[len(tkVer
)-1] == '':
72 tkVer
[len(tkVer
)-1] = '0'
73 tkVer
= string
.join(tkVer
,'.')
74 labelTkVer
= Label(frameBg
, text
='Tk version: '+
75 tkVer
, fg
=self
.fg
, bg
=self
.bg
)
76 labelTkVer
.grid(row
=9, column
=1, sticky
=W
, padx
=2, pady
=0)
77 py_button_f
= Frame(frameBg
, bg
=self
.bg
)
78 py_button_f
.grid(row
=10, column
=0, columnspan
=2, sticky
=NSEW
)
79 buttonLicense
= Button(py_button_f
, text
='License', width
=8,
80 highlightbackground
=self
.bg
,
81 command
=self
.ShowLicense
)
82 buttonLicense
.pack(side
=LEFT
, padx
=10, pady
=10)
83 buttonCopyright
= Button(py_button_f
, text
='Copyright', width
=8,
84 highlightbackground
=self
.bg
,
85 command
=self
.ShowCopyright
)
86 buttonCopyright
.pack(side
=LEFT
, padx
=10, pady
=10)
87 buttonCredits
= Button(py_button_f
, text
='Credits', width
=8,
88 highlightbackground
=self
.bg
,
89 command
=self
.ShowPythonCredits
)
90 buttonCredits
.pack(side
=LEFT
, padx
=10, pady
=10)
91 Frame(frameBg
, borderwidth
=1, relief
=SUNKEN
,
92 height
=2, bg
=self
.bg
).grid(row
=11, column
=0, sticky
=EW
,
93 columnspan
=3, padx
=5, pady
=5)
94 idle_v
= Label(frameBg
, text
='IDLE version: ' + idlever
.IDLE_VERSION
,
95 fg
=self
.fg
, bg
=self
.bg
)
96 idle_v
.grid(row
=12, column
=0, sticky
=W
, padx
=10, pady
=0)
97 idle_button_f
= Frame(frameBg
, bg
=self
.bg
)
98 idle_button_f
.grid(row
=13, column
=0, columnspan
=3, sticky
=NSEW
)
99 idle_about_b
= Button(idle_button_f
, text
='README', width
=8,
100 highlightbackground
=self
.bg
,
101 command
=self
.ShowIDLEAbout
)
102 idle_about_b
.pack(side
=LEFT
, padx
=10, pady
=10)
103 idle_news_b
= Button(idle_button_f
, text
='NEWS', width
=8,
104 highlightbackground
=self
.bg
,
105 command
=self
.ShowIDLENEWS
)
106 idle_news_b
.pack(side
=LEFT
, padx
=10, pady
=10)
107 idle_credits_b
= Button(idle_button_f
, text
='Credits', width
=8,
108 highlightbackground
=self
.bg
,
109 command
=self
.ShowIDLECredits
)
110 idle_credits_b
.pack(side
=LEFT
, padx
=10, pady
=10)
112 def ShowLicense(self
):
113 self
.display_printer_text(license
, 'About - License')
115 def ShowCopyright(self
):
116 self
.display_printer_text(copyright
, 'About - Copyright')
118 def ShowPythonCredits(self
):
119 self
.display_printer_text(credits
, 'About - Python Credits')
121 def ShowIDLECredits(self
):
122 self
.ViewFile('About - Credits','CREDITS.txt', 'iso-8859-1')
124 def ShowIDLEAbout(self
):
125 self
.ViewFile('About - Readme', 'README.txt')
127 def ShowIDLENEWS(self
):
128 self
.ViewFile('About - NEWS', 'NEWS.txt')
130 def display_printer_text(self
, printer
, title
):
131 printer
._Printer
__setup
()
132 data
= '\n'.join(printer
._Printer
__lines
)
133 textView
.TextViewer(self
, title
, None, data
)
135 def ViewFile(self
, viewTitle
, viewFile
, encoding
=None):
136 fn
= os
.path
.join(os
.path
.abspath(os
.path
.dirname(__file__
)), viewFile
)
140 textFile
= codecs
.open(fn
, 'r')
143 tkMessageBox
.showerror(title
='File Load Error',
144 message
='Unable to load file %r .' % (fn
,),
148 data
= textFile
.read()
151 textView
.TextViewer(self
, viewTitle
, fn
, data
=data
)
153 def Ok(self
, event
=None):
156 if __name__
== '__main__':
161 aboutDialog
.AboutDialog(root
, 'About')
162 Button(root
, text
='Dialog', command
=run
).pack()