Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v8plus / lib / python2.4 / idlelib / aboutDialog.py
CommitLineData
920dae64
AT
1"""About Dialog for IDLE
2
3"""
4
5from Tkinter import *
6import string, os
7import textView
8import idlever
9
10class AboutDialog(Toplevel):
11 """Modal about dialog for idle
12
13 """
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))
19 self.bg = "#707070"
20 self.fg = "#ffffff"
21 self.CreateWidgets()
22 self.resizable(height=FALSE, width=FALSE)
23 self.title(title)
24 self.transient(parent)
25 self.grab_set()
26 self.protocol("WM_DELETE_WINDOW", self.Ok)
27 self.parent = parent
28 self.buttonOk.focus_set()
29 self.bind('<Return>',self.Ok) #dismiss dialog
30 self.bind('<Escape>',self.Ok) #dismiss dialog
31 self.wait_window()
32
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',
39 command=self.Ok)
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,
50 # padx=0, pady=3)
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)
111
112 def ShowLicense(self):
113 self.display_printer_text(license, 'About - License')
114
115 def ShowCopyright(self):
116 self.display_printer_text(copyright, 'About - Copyright')
117
118 def ShowPythonCredits(self):
119 self.display_printer_text(credits, 'About - Python Credits')
120
121 def ShowIDLECredits(self):
122 self.ViewFile('About - Credits','CREDITS.txt', 'iso-8859-1')
123
124 def ShowIDLEAbout(self):
125 self.ViewFile('About - Readme', 'README.txt')
126
127 def ShowIDLENEWS(self):
128 self.ViewFile('About - NEWS', 'NEWS.txt')
129
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)
134
135 def ViewFile(self, viewTitle, viewFile, encoding=None):
136 fn = os.path.join(os.path.abspath(os.path.dirname(__file__)), viewFile)
137 if encoding:
138 import codecs
139 try:
140 textFile = codecs.open(fn, 'r')
141 except IOError:
142 import tkMessageBox
143 tkMessageBox.showerror(title='File Load Error',
144 message='Unable to load file %r .' % (fn,),
145 parent=self)
146 return
147 else:
148 data = textFile.read()
149 else:
150 data = None
151 textView.TextViewer(self, viewTitle, fn, data=data)
152
153 def Ok(self, event=None):
154 self.destroy()
155
156if __name__ == '__main__':
157 # test the dialog
158 root = Tk()
159 def run():
160 import aboutDialog
161 aboutDialog.AboutDialog(root, 'About')
162 Button(root, text='Dialog', command=run).pack()
163 root.mainloop()