PyXR

c:\python24\lib \ idlelib \ aboutDialog.py



0001 """About Dialog for IDLE
0002 
0003 """
0004 
0005 from Tkinter import *
0006 import string, os
0007 import textView
0008 import idlever
0009 
0010 class AboutDialog(Toplevel):
0011     """Modal about dialog for idle
0012 
0013     """
0014     def __init__(self,parent,title):
0015         Toplevel.__init__(self, parent)
0016         self.configure(borderwidth=5)
0017         self.geometry("+%d+%d" % (parent.winfo_rootx()+30,
0018                                   parent.winfo_rooty()+30))
0019         self.bg = "#707070"
0020         self.fg = "#ffffff"
0021         self.CreateWidgets()
0022         self.resizable(height=FALSE, width=FALSE)
0023         self.title(title)
0024         self.transient(parent)
0025         self.grab_set()
0026         self.protocol("WM_DELETE_WINDOW", self.Ok)
0027         self.parent = parent
0028         self.buttonOk.focus_set()
0029         self.bind('<Return>',self.Ok) #dismiss dialog
0030         self.bind('<Escape>',self.Ok) #dismiss dialog
0031         self.wait_window()
0032 
0033     def CreateWidgets(self):
0034         frameMain = Frame(self, borderwidth=2, relief=SUNKEN)
0035         frameButtons = Frame(self)
0036         frameButtons.pack(side=BOTTOM, fill=X)
0037         frameMain.pack(side=TOP, expand=TRUE, fill=BOTH)
0038         self.buttonOk = Button(frameButtons, text='Close',
0039                                command=self.Ok)
0040         self.buttonOk.pack(padx=5, pady=5)
0041         #self.picture = Image('photo', data=self.pictureData)
0042         frameBg = Frame(frameMain, bg=self.bg)
0043         frameBg.pack(expand=TRUE, fill=BOTH)
0044         labelTitle = Label(frameBg, text='IDLE', fg=self.fg, bg=self.bg,
0045                            font=('courier', 24, 'bold'))
0046         labelTitle.grid(row=0, column=0, sticky=W, padx=10, pady=10)
0047         #labelPicture = Label(frameBg, text='[picture]')
0048         #image=self.picture, bg=self.bg)
0049         #labelPicture.grid(row=1, column=1, sticky=W, rowspan=2,
0050         #                  padx=0, pady=3)
0051         byline = "Python's Integrated DeveLopment Environment" + 5*'\n'
0052         labelDesc = Label(frameBg, text=byline, justify=LEFT,
0053                           fg=self.fg, bg=self.bg)
0054         labelDesc.grid(row=2, column=0, sticky=W, columnspan=3, padx=10, pady=5)
0055         labelEmail = Label(frameBg, text='email:  idle-dev@python.org',
0056                            justify=LEFT, fg=self.fg, bg=self.bg)
0057         labelEmail.grid(row=6, column=0, columnspan=2,
0058                         sticky=W, padx=10, pady=0)
0059         labelWWW = Label(frameBg, text='www:  http://www.python.org/idle/',
0060                          justify=LEFT, fg=self.fg, bg=self.bg)
0061         labelWWW.grid(row=7, column=0, columnspan=2, sticky=W, padx=10, pady=0)
0062         Frame(frameBg, borderwidth=1, relief=SUNKEN,
0063               height=2, bg=self.bg).grid(row=8, column=0, sticky=EW,
0064                                          columnspan=3, padx=5, pady=5)
0065         labelPythonVer = Label(frameBg, text='Python version:  ' + \
0066                                sys.version.split()[0], fg=self.fg, bg=self.bg)
0067         labelPythonVer.grid(row=9, column=0, sticky=W, padx=10, pady=0)
0068         # handle weird tk version num in windoze python >= 1.6 (?!?)
0069         tkVer = repr(TkVersion).split('.')
0070         tkVer[len(tkVer)-1] = str('%.3g' % (float('.'+tkVer[len(tkVer)-1])))[2:]
0071         if tkVer[len(tkVer)-1] == '':
0072             tkVer[len(tkVer)-1] = '0'
0073         tkVer = string.join(tkVer,'.')
0074         labelTkVer = Label(frameBg, text='Tk version:  '+
0075                            tkVer, fg=self.fg, bg=self.bg)
0076         labelTkVer.grid(row=9, column=1, sticky=W, padx=2, pady=0)
0077         py_button_f = Frame(frameBg, bg=self.bg)
0078         py_button_f.grid(row=10, column=0, columnspan=2, sticky=NSEW)
0079         buttonLicense = Button(py_button_f, text='License', width=8,
0080                                highlightbackground=self.bg,
0081                                command=self.ShowLicense)
0082         buttonLicense.pack(side=LEFT, padx=10, pady=10)
0083         buttonCopyright = Button(py_button_f, text='Copyright', width=8,
0084                                  highlightbackground=self.bg,
0085                                  command=self.ShowCopyright)
0086         buttonCopyright.pack(side=LEFT, padx=10, pady=10)
0087         buttonCredits = Button(py_button_f, text='Credits', width=8,
0088                                highlightbackground=self.bg,
0089                                command=self.ShowPythonCredits)
0090         buttonCredits.pack(side=LEFT, padx=10, pady=10)
0091         Frame(frameBg, borderwidth=1, relief=SUNKEN,
0092               height=2, bg=self.bg).grid(row=11, column=0, sticky=EW,
0093                                          columnspan=3, padx=5, pady=5)
0094         idle_v = Label(frameBg, text='IDLE version:   ' + idlever.IDLE_VERSION,
0095                        fg=self.fg, bg=self.bg)
0096         idle_v.grid(row=12, column=0, sticky=W, padx=10, pady=0)
0097         idle_button_f = Frame(frameBg, bg=self.bg)
0098         idle_button_f.grid(row=13, column=0, columnspan=3, sticky=NSEW)
0099         idle_about_b = Button(idle_button_f, text='README', width=8,
0100                                 highlightbackground=self.bg,
0101                                 command=self.ShowIDLEAbout)
0102         idle_about_b.pack(side=LEFT, padx=10, pady=10)
0103         idle_news_b = Button(idle_button_f, text='NEWS', width=8,
0104                                 highlightbackground=self.bg,
0105                                 command=self.ShowIDLENEWS)
0106         idle_news_b.pack(side=LEFT, padx=10, pady=10)
0107         idle_credits_b = Button(idle_button_f, text='Credits', width=8,
0108                                 highlightbackground=self.bg,
0109                                 command=self.ShowIDLECredits)
0110         idle_credits_b.pack(side=LEFT, padx=10, pady=10)
0111 
0112     def ShowLicense(self):
0113         self.display_printer_text(license, 'About - License')
0114 
0115     def ShowCopyright(self):
0116         self.display_printer_text(copyright, 'About - Copyright')
0117 
0118     def ShowPythonCredits(self):
0119         self.display_printer_text(credits, 'About - Python Credits')
0120 
0121     def ShowIDLECredits(self):
0122         self.ViewFile('About - Credits','CREDITS.txt', 'iso-8859-1')
0123 
0124     def ShowIDLEAbout(self):
0125         self.ViewFile('About - Readme', 'README.txt')
0126 
0127     def ShowIDLENEWS(self):
0128         self.ViewFile('About - NEWS', 'NEWS.txt')
0129 
0130     def display_printer_text(self, printer, title):
0131         printer._Printer__setup()
0132         data = '\n'.join(printer._Printer__lines)
0133         textView.TextViewer(self, title, None, data)
0134 
0135     def ViewFile(self, viewTitle, viewFile, encoding=None):
0136         fn = os.path.join(os.path.abspath(os.path.dirname(__file__)), viewFile)
0137         if encoding:
0138             import codecs
0139             try:
0140                 textFile = codecs.open(fn, 'r')
0141             except IOError:
0142                 import tkMessageBox
0143                 tkMessageBox.showerror(title='File Load Error',
0144                                        message='Unable to load file %r .' % (fn,),
0145                                        parent=self)
0146                 return
0147             else:
0148                 data = textFile.read()
0149         else:
0150             data = None
0151         textView.TextViewer(self, viewTitle, fn, data=data)
0152 
0153     def Ok(self, event=None):
0154         self.destroy()
0155 
0156 if __name__ == '__main__':
0157     # test the dialog
0158     root = Tk()
0159     def run():
0160         import aboutDialog
0161         aboutDialog.AboutDialog(root, 'About')
0162     Button(root, text='Dialog', command=run).pack()
0163     root.mainloop()
0164 

Generated by PyXR 0.9.4
SourceForge.net Logo