ยปCore Development>Code coverage>Lib/tkinter/commondialog.py

Python code coverage for Lib/tkinter/commondialog.py

#countcontent
1n/a# base class for tk common dialogues
2n/a#
3n/a# this module provides a base class for accessing the common
4n/a# dialogues available in Tk 4.2 and newer. use filedialog,
5n/a# colorchooser, and messagebox to access the individual
6n/a# dialogs.
7n/a#
8n/a# written by Fredrik Lundh, May 1997
9n/a#
10n/a
11n/afrom tkinter import *
12n/a
13n/aclass Dialog:
14n/a
15n/a command = None
16n/a
17n/a def __init__(self, master=None, **options):
18n/a self.master = master
19n/a self.options = options
20n/a if not master and options.get('parent'):
21n/a self.master = options['parent']
22n/a
23n/a def _fixoptions(self):
24n/a pass # hook
25n/a
26n/a def _fixresult(self, widget, result):
27n/a return result # hook
28n/a
29n/a def show(self, **options):
30n/a
31n/a # update instance options
32n/a for k, v in options.items():
33n/a self.options[k] = v
34n/a
35n/a self._fixoptions()
36n/a
37n/a # we need a dummy widget to properly process the options
38n/a # (at least as long as we use Tkinter 1.63)
39n/a w = Frame(self.master)
40n/a
41n/a try:
42n/a
43n/a s = w.tk.call(self.command, *w._options(self.options))
44n/a
45n/a s = self._fixresult(w, s)
46n/a
47n/a finally:
48n/a
49n/a try:
50n/a # get rid of the widget
51n/a w.destroy()
52n/a except:
53n/a pass
54n/a
55n/a return s