blob: 7fe1ab81ee530212e7bb618255d41b6c96ea5ec8 [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
Georg Brandl14fc4272008-05-17 18:39:55 +00005from tkinter import *
Neal Norwitz9d72bb42007-04-17 08:48:32 +00006import os
Guido van Rossum36e0a922007-07-20 04:05:57 +00007
Kurt B. Kaiser2d7f6a02007-08-22 23:01:33 +00008from idlelib import textView
9from idlelib import idlever
Neal Norwitz539594f2002-11-30 19:12:41 +000010
Steven M. Gava44d3d1a2001-07-31 06:59:02 +000011class AboutDialog(Toplevel):
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +000012 """Modal about dialog for idle
13
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +000014 """
Steven M. Gava885c0bb2001-07-31 10:44:35 +000015 def __init__(self,parent,title):
16 Toplevel.__init__(self, parent)
17 self.configure(borderwidth=5)
18 self.geometry("+%d+%d" % (parent.winfo_rootx()+30,
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +000019 parent.winfo_rooty()+30))
20 self.bg = "#707070"
21 self.fg = "#ffffff"
Steven M. Gava885c0bb2001-07-31 10:44:35 +000022 self.CreateWidgets()
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +000023 self.resizable(height=FALSE, width=FALSE)
Steven M. Gava885c0bb2001-07-31 10:44:35 +000024 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()
Steven M. Gava885c0bb2001-07-31 10:44:35 +000030 self.bind('<Return>',self.Ok) #dismiss dialog
31 self.bind('<Escape>',self.Ok) #dismiss dialog
32 self.wait_window()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +000033
Steven M. Gava885c0bb2001-07-31 10:44:35 +000034 def CreateWidgets(self):
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +000035 frameMain = Frame(self, borderwidth=2, relief=SUNKEN)
Steven M. Gava885c0bb2001-07-31 10:44:35 +000036 frameButtons = Frame(self)
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +000037 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)
Kurt B. Kaiser73453752003-06-16 18:46:42 +000058 labelEmail.grid(row=6, column=0, columnspan=2,
59 sticky=W, padx=10, pady=0)
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +000060 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)
Roger Serwy0803a392013-04-08 20:57:13 -050069 tkVer = self.tk.call('info', 'patchlevel')
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +000070 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)
Kurt B. Kaiser73453752003-06-16 18:46:42 +000090 idle_v = Label(frameBg, text='IDLE version: ' + idlever.IDLE_VERSION,
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +000091 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)
Steven M. Gava885c0bb2001-07-31 10:44:35 +0000107
108 def ShowLicense(self):
Guido van Rossum8ce8a782007-11-01 19:42:39 +0000109 self.display_printer_text('About - License', license)
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000110
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +0000111 def ShowCopyright(self):
Guido van Rossum8ce8a782007-11-01 19:42:39 +0000112 self.display_printer_text('About - Copyright', copyright)
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +0000113
114 def ShowPythonCredits(self):
Guido van Rossum8ce8a782007-11-01 19:42:39 +0000115 self.display_printer_text('About - Python Credits', credits)
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +0000116
117 def ShowIDLECredits(self):
Guido van Rossum8ce8a782007-11-01 19:42:39 +0000118 self.display_file_text('About - Credits', 'CREDITS.txt', 'iso-8859-1')
Steven M. Gava885c0bb2001-07-31 10:44:35 +0000119
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +0000120 def ShowIDLEAbout(self):
Guido van Rossum8ce8a782007-11-01 19:42:39 +0000121 self.display_file_text('About - Readme', 'README.txt')
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +0000122
123 def ShowIDLENEWS(self):
Guido van Rossum8ce8a782007-11-01 19:42:39 +0000124 self.display_file_text('About - NEWS', 'NEWS.txt')
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +0000125
Guido van Rossum8ce8a782007-11-01 19:42:39 +0000126 def display_printer_text(self, title, printer):
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +0000127 printer._Printer__setup()
Guido van Rossum8ce8a782007-11-01 19:42:39 +0000128 text = '\n'.join(printer._Printer__lines)
129 textView.view_text(self, title, text)
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +0000130
Guido van Rossum8ce8a782007-11-01 19:42:39 +0000131 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)
Steven M. Gava885c0bb2001-07-31 10:44:35 +0000134
135 def Ok(self, event=None):
136 self.destroy()
Kurt B. Kaiser6655e4b2002-12-31 16:03:23 +0000137
Steven M. Gava44d3d1a2001-07-31 06:59:02 +0000138if __name__ == '__main__':
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +0000139 # test the dialog
140 root = Tk()
Steven M. Gava885c0bb2001-07-31 10:44:35 +0000141 def run():
Kurt B. Kaiser2d7f6a02007-08-22 23:01:33 +0000142 from idlelib import aboutDialog
Kurt B. Kaiser73453752003-06-16 18:46:42 +0000143 aboutDialog.AboutDialog(root, 'About')
Kurt B. Kaiser09cb74b2003-06-12 04:20:56 +0000144 Button(root, text='Dialog', command=run).pack()
Steven M. Gava885c0bb2001-07-31 10:44:35 +0000145 root.mainloop()