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