annotate Lib/lib-tk/tkCommonDialog.py @ 80661:94de77bd0b4b 2.7

Issue #16194: document imp.load_dynamic problems when read several extension modules from the same binary object file.
author Andrew Svetlov <andrew.svetlov@gmail.com>
date Thu, 29 Nov 2012 19:51:28 +0200
parents b53604fad54b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5869
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 # base class for tk common dialogues
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 #
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 # this module provides a base class for accessing the common
47183
b53604fad54b Tkinter rename reversal: remove tkinter package, adapt imports and docs.
Georg Brandl <georg@python.org>
parents: 47182
diff changeset
4 # dialogues available in Tk 4.2 and newer. use tkFileDialog,
b53604fad54b Tkinter rename reversal: remove tkinter package, adapt imports and docs.
Georg Brandl <georg@python.org>
parents: 47182
diff changeset
5 # tkColorChooser, and tkMessageBox to access the individual
5869
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 # dialogs.
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 #
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 # written by Fredrik Lundh, May 1997
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 #
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
10
47183
b53604fad54b Tkinter rename reversal: remove tkinter package, adapt imports and docs.
Georg Brandl <georg@python.org>
parents: 47182
diff changeset
11 from Tkinter import *
5869
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
12
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 class Dialog:
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
14
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 command = None
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
16
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 def __init__(self, master=None, **options):
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
18
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 # FIXME: should this be placed on the module level instead?
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 if TkVersion < 4.2:
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 raise TclError, "this module requires Tk 4.2 or newer"
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
22
7731
9c37ed8868b9 Give in to the tab police.
Guido van Rossum <guido@python.org>
parents: 6013
diff changeset
23 self.master = master
5869
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 self.options = options
9331
75237ca56aff When no master widget is specified, use options['parent'] if it exists.
Guido van Rossum <guido@python.org>
parents: 7731
diff changeset
25 if not master and options.get('parent'):
75237ca56aff When no master widget is specified, use options['parent'] if it exists.
Guido van Rossum <guido@python.org>
parents: 7731
diff changeset
26 self.master = options['parent']
5869
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
27
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 def _fixoptions(self):
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 pass # hook
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
30
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 def _fixresult(self, widget, result):
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 return result # hook
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
33
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 def show(self, **options):
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
35
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 # update instance options
7731
9c37ed8868b9 Give in to the tab police.
Guido van Rossum <guido@python.org>
parents: 6013
diff changeset
37 for k, v in options.items():
9c37ed8868b9 Give in to the tab police.
Guido van Rossum <guido@python.org>
parents: 6013
diff changeset
38 self.options[k] = v
5869
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
39
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 self._fixoptions()
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
41
6013
0b5a23ea7515 Fred Lundh's latest versions.
Guido van Rossum <guido@python.org>
parents: 5869
diff changeset
42 # we need a dummy widget to properly process the options
5869
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 # (at least as long as we use Tkinter 1.63)
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 w = Frame(self.master)
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
45
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 try:
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
47
28513
90c77b8af1a4 SF patch #701494: more apply removals
Raymond Hettinger <python@rcn.com>
parents: 21965
diff changeset
48 s = w.tk.call(self.command, *w._options(self.options))
5869
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
49
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 s = self._fixresult(w, s)
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
51
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 finally:
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
53
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 try:
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 # get rid of the widget
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 w.destroy()
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 except:
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 pass
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
59
f2bf7bcf8b8b New dialog routines (Fred Lundh)
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 return s