blob: c1210612e67abb91ea8e84cab23527de1d249462 [file] [log] [blame]
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +00001"""About Dialog for IDLE
2
Steven M. Gava44d3d1a2001-07-31 06:59:02 +00003"""
Neal Norwitz539594f2002-11-30 19:12:41 +00004
Steven M. Gava44d3d1a2001-07-31 06:59:02 +00005from Tkinter import *
Steven M. Gava885c0bb2001-07-31 10:44:35 +00006import string, os
Steven M. Gava44d3d1a2001-07-31 06:59:02 +00007import textView
8import idlever
Neal Norwitz539594f2002-11-30 19:12:41 +00009
Steven M. Gava44d3d1a2001-07-31 06:59:02 +000010class AboutDialog(Toplevel):
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +000011 """Modal about dialog for idle
12
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +000013 """
Steven M. Gava885c0bb2001-07-31 10:44:35 +000014 def __init__(self,parent,title):
15 Toplevel.__init__(self, parent)
16 self.configure(borderwidth=5)
17 self.geometry("+%d+%d" % (parent.winfo_rootx()+30,
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +000018 parent.winfo_rooty()+30))
19 self.bg = "#707070"
20 self.fg = "#ffffff"
Steven M. Gava885c0bb2001-07-31 10:44:35 +000021 self.CreateWidgets()
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +000022 self.resizable(height=FALSE, width=FALSE)
Steven M. Gava885c0bb2001-07-31 10:44:35 +000023 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()
Steven M. Gava885c0bb2001-07-31 10:44:35 +000029 self.bind('<Return>',self.Ok) #dismiss dialog
30 self.bind('<Escape>',self.Ok) #dismiss dialog
31 self.wait_window()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +000032
Steven M. Gava885c0bb2001-07-31 10:44:35 +000033 def CreateWidgets(self):
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +000034 frameMain = Frame(self, borderwidth=2, relief=SUNKEN)
Steven M. Gava885c0bb2001-07-31 10:44:35 +000035 frameButtons = Frame(self)
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +000036 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)
Kurt B. Kaiser73453752003-06-16 18:46:42 +000057 labelEmail.grid(row=6, column=0, columnspan=2,
58 sticky=W, padx=10, pady=0)
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +000059 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 (?!?)
Walter Dörwald70a6b492004-02-12 17:35:32 +000069 tkVer = repr(TkVersion).split('.')
Steven M. Gava885c0bb2001-07-31 10:44:35 +000070 tkVer[len(tkVer)-1] = str('%.3g' % (float('.'+tkVer[len(tkVer)-1])))[2:]
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +000071 if tkVer[len(tkVer)-1] == '':
Steven M. Gava885c0bb2001-07-31 10:44:35 +000072 tkVer[len(tkVer)-1] = '0'
73 tkVer = string.join(tkVer,'.')
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +000074 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)
Kurt B. Kaiser73453752003-06-16 18:46:42 +000094 idle_v = Label(frameBg, text='IDLE version: ' + idlever.IDLE_VERSION,
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +000095 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)
Steven M. Gava885c0bb2001-07-31 10:44:35 +0000111
112 def ShowLicense(self):
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +0000113 self.display_printer_text(license, 'About - License')
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000114
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +0000115 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):
Martin v. Löwis424a4152003-06-15 22:28:05 +0000122 self.ViewFile('About - Credits','CREDITS.txt', 'iso-8859-1')
Steven M. Gava885c0bb2001-07-31 10:44:35 +0000123
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +0000124 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
Martin v. Löwis424a4152003-06-15 22:28:05 +0000135 def ViewFile(self, viewTitle, viewFile, encoding=None):
Kurt B. Kaiser73453752003-06-16 18:46:42 +0000136 fn = os.path.join(os.path.abspath(os.path.dirname(__file__)), viewFile)
Martin v. Löwis424a4152003-06-15 22:28:05 +0000137 if encoding:
138 import codecs
139 try:
140 textFile = codecs.open(fn, 'r')
141 except IOError:
Neal Norwitz99204302003-10-28 21:57:10 +0000142 import tkMessageBox
Martin v. Löwis424a4152003-06-15 22:28:05 +0000143 tkMessageBox.showerror(title='File Load Error',
Walter Dörwald70a6b492004-02-12 17:35:32 +0000144 message='Unable to load file %r .' % (fn,),
Neal Norwitz99204302003-10-28 21:57:10 +0000145 parent=self)
Martin v. Löwis424a4152003-06-15 22:28:05 +0000146 return
147 else:
148 data = textFile.read()
149 else:
150 data = None
151 textView.TextViewer(self, viewTitle, fn, data=data)
Steven M. Gava885c0bb2001-07-31 10:44:35 +0000152
153 def Ok(self, event=None):
154 self.destroy()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000155
Steven M. Gava44d3d1a2001-07-31 06:59:02 +0000156if __name__ == '__main__':
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +0000157 # test the dialog
158 root = Tk()
Steven M. Gava885c0bb2001-07-31 10:44:35 +0000159 def run():
160 import aboutDialog
Kurt B. Kaiser73453752003-06-16 18:46:42 +0000161 aboutDialog.AboutDialog(root, 'About')
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +0000162 Button(root, text='Dialog', command=run).pack()
Steven M. Gava885c0bb2001-07-31 10:44:35 +0000163 root.mainloop()