Kurt B. Kaiser | 09cb74b | 2003-06-12 04:20:56 +0000 | [diff] [blame] | 1 | """About Dialog for IDLE |
| 2 | |
Steven M. Gava | 44d3d1a | 2001-07-31 06:59:02 +0000 | [diff] [blame] | 3 | """ |
Neal Norwitz | 539594f | 2002-11-30 19:12:41 +0000 | [diff] [blame] | 4 | |
Steven M. Gava | 44d3d1a | 2001-07-31 06:59:02 +0000 | [diff] [blame] | 5 | from Tkinter import * |
Steven M. Gava | 885c0bb | 2001-07-31 10:44:35 +0000 | [diff] [blame] | 6 | import string, os |
Steven M. Gava | 44d3d1a | 2001-07-31 06:59:02 +0000 | [diff] [blame] | 7 | import textView |
| 8 | import idlever |
Neal Norwitz | 539594f | 2002-11-30 19:12:41 +0000 | [diff] [blame] | 9 | |
Steven M. Gava | 44d3d1a | 2001-07-31 06:59:02 +0000 | [diff] [blame] | 10 | class AboutDialog(Toplevel): |
Kurt B. Kaiser | 09cb74b | 2003-06-12 04:20:56 +0000 | [diff] [blame] | 11 | """Modal about dialog for idle |
| 12 | |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 13 | """ |
Steven M. Gava | 885c0bb | 2001-07-31 10:44:35 +0000 | [diff] [blame] | 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, |
Kurt B. Kaiser | 09cb74b | 2003-06-12 04:20:56 +0000 | [diff] [blame] | 18 | parent.winfo_rooty()+30)) |
| 19 | self.bg = "#707070" |
| 20 | self.fg = "#ffffff" |
Steven M. Gava | 885c0bb | 2001-07-31 10:44:35 +0000 | [diff] [blame] | 21 | self.CreateWidgets() |
Kurt B. Kaiser | 09cb74b | 2003-06-12 04:20:56 +0000 | [diff] [blame] | 22 | self.resizable(height=FALSE, width=FALSE) |
Steven M. Gava | 885c0bb | 2001-07-31 10:44:35 +0000 | [diff] [blame] | 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() |
Steven M. Gava | 885c0bb | 2001-07-31 10:44:35 +0000 | [diff] [blame] | 29 | self.bind('<Return>',self.Ok) #dismiss dialog |
| 30 | self.bind('<Escape>',self.Ok) #dismiss dialog |
| 31 | self.wait_window() |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 32 | |
Steven M. Gava | 885c0bb | 2001-07-31 10:44:35 +0000 | [diff] [blame] | 33 | def CreateWidgets(self): |
Kurt B. Kaiser | 09cb74b | 2003-06-12 04:20:56 +0000 | [diff] [blame] | 34 | frameMain = Frame(self, borderwidth=2, relief=SUNKEN) |
Steven M. Gava | 885c0bb | 2001-07-31 10:44:35 +0000 | [diff] [blame] | 35 | frameButtons = Frame(self) |
Kurt B. Kaiser | 09cb74b | 2003-06-12 04:20:56 +0000 | [diff] [blame] | 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) |
Kurt B. Kaiser | 7345375 | 2003-06-16 18:46:42 +0000 | [diff] [blame] | 57 | labelEmail.grid(row=6, column=0, columnspan=2, |
| 58 | sticky=W, padx=10, pady=0) |
Kurt B. Kaiser | 09cb74b | 2003-06-12 04:20:56 +0000 | [diff] [blame] | 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 (?!?) |
Walter Dörwald | 70a6b49 | 2004-02-12 17:35:32 +0000 | [diff] [blame] | 69 | tkVer = repr(TkVersion).split('.') |
Steven M. Gava | 885c0bb | 2001-07-31 10:44:35 +0000 | [diff] [blame] | 70 | tkVer[len(tkVer)-1] = str('%.3g' % (float('.'+tkVer[len(tkVer)-1])))[2:] |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 71 | if tkVer[len(tkVer)-1] == '': |
Steven M. Gava | 885c0bb | 2001-07-31 10:44:35 +0000 | [diff] [blame] | 72 | tkVer[len(tkVer)-1] = '0' |
| 73 | tkVer = string.join(tkVer,'.') |
Kurt B. Kaiser | 09cb74b | 2003-06-12 04:20:56 +0000 | [diff] [blame] | 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) |
Kurt B. Kaiser | 7345375 | 2003-06-16 18:46:42 +0000 | [diff] [blame] | 94 | idle_v = Label(frameBg, text='IDLE version: ' + idlever.IDLE_VERSION, |
Kurt B. Kaiser | 09cb74b | 2003-06-12 04:20:56 +0000 | [diff] [blame] | 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) |
Steven M. Gava | 885c0bb | 2001-07-31 10:44:35 +0000 | [diff] [blame] | 111 | |
| 112 | def ShowLicense(self): |
Kurt B. Kaiser | 09cb74b | 2003-06-12 04:20:56 +0000 | [diff] [blame] | 113 | self.display_printer_text(license, 'About - License') |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 114 | |
Kurt B. Kaiser | 09cb74b | 2003-06-12 04:20:56 +0000 | [diff] [blame] | 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): |
Martin v. Löwis | 424a415 | 2003-06-15 22:28:05 +0000 | [diff] [blame] | 122 | self.ViewFile('About - Credits','CREDITS.txt', 'iso-8859-1') |
Steven M. Gava | 885c0bb | 2001-07-31 10:44:35 +0000 | [diff] [blame] | 123 | |
Kurt B. Kaiser | 09cb74b | 2003-06-12 04:20:56 +0000 | [diff] [blame] | 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 | |
Martin v. Löwis | 424a415 | 2003-06-15 22:28:05 +0000 | [diff] [blame] | 135 | def ViewFile(self, viewTitle, viewFile, encoding=None): |
Kurt B. Kaiser | 7345375 | 2003-06-16 18:46:42 +0000 | [diff] [blame] | 136 | fn = os.path.join(os.path.abspath(os.path.dirname(__file__)), viewFile) |
Martin v. Löwis | 424a415 | 2003-06-15 22:28:05 +0000 | [diff] [blame] | 137 | if encoding: |
| 138 | import codecs |
| 139 | try: |
| 140 | textFile = codecs.open(fn, 'r') |
| 141 | except IOError: |
Neal Norwitz | 9920430 | 2003-10-28 21:57:10 +0000 | [diff] [blame] | 142 | import tkMessageBox |
Martin v. Löwis | 424a415 | 2003-06-15 22:28:05 +0000 | [diff] [blame] | 143 | tkMessageBox.showerror(title='File Load Error', |
Walter Dörwald | 70a6b49 | 2004-02-12 17:35:32 +0000 | [diff] [blame] | 144 | message='Unable to load file %r .' % (fn,), |
Neal Norwitz | 9920430 | 2003-10-28 21:57:10 +0000 | [diff] [blame] | 145 | parent=self) |
Martin v. Löwis | 424a415 | 2003-06-15 22:28:05 +0000 | [diff] [blame] | 146 | return |
| 147 | else: |
| 148 | data = textFile.read() |
| 149 | else: |
| 150 | data = None |
| 151 | textView.TextViewer(self, viewTitle, fn, data=data) |
Steven M. Gava | 885c0bb | 2001-07-31 10:44:35 +0000 | [diff] [blame] | 152 | |
| 153 | def Ok(self, event=None): |
| 154 | self.destroy() |
Kurt B. Kaiser | 6655e4b | 2002-12-31 16:03:23 +0000 | [diff] [blame] | 155 | |
Steven M. Gava | 44d3d1a | 2001-07-31 06:59:02 +0000 | [diff] [blame] | 156 | if __name__ == '__main__': |
Kurt B. Kaiser | 09cb74b | 2003-06-12 04:20:56 +0000 | [diff] [blame] | 157 | # test the dialog |
| 158 | root = Tk() |
Steven M. Gava | 885c0bb | 2001-07-31 10:44:35 +0000 | [diff] [blame] | 159 | def run(): |
| 160 | import aboutDialog |
Kurt B. Kaiser | 7345375 | 2003-06-16 18:46:42 +0000 | [diff] [blame] | 161 | aboutDialog.AboutDialog(root, 'About') |
Kurt B. Kaiser | 09cb74b | 2003-06-12 04:20:56 +0000 | [diff] [blame] | 162 | Button(root, text='Dialog', command=run).pack() |
Steven M. Gava | 885c0bb | 2001-07-31 10:44:35 +0000 | [diff] [blame] | 163 | root.mainloop() |