ยปCore Development>Code coverage>Lib/idlelib/help_about.py

Python code coverage for Lib/idlelib/help_about.py

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