Added 'description' class attribute to every command class (to help the
[python/dscho.git] / Lib / lib-tk / tkCommonDialog.py
blob55cf0646cb1ea7318427afbb7b753d213e606c23
2 # Instant Python
3 # $Id$
5 # base class for tk common dialogues
7 # this module provides a base class for accessing the common
8 # dialogues available in Tk 4.2 and newer. use tkFileDialog,
9 # tkColorChooser, and tkMessageBox to access the individual
10 # dialogs.
12 # written by Fredrik Lundh, May 1997
15 from Tkinter import *
16 import os
18 class Dialog:
20 command = None
22 def __init__(self, master=None, **options):
24 # FIXME: should this be placed on the module level instead?
25 if TkVersion < 4.2:
26 raise TclError, "this module requires Tk 4.2 or newer"
28 self.master = master
29 self.options = options
30 if not master and options.get('parent'):
31 self.master = options['parent']
33 def _fixoptions(self):
34 pass # hook
36 def _fixresult(self, widget, result):
37 return result # hook
39 def show(self, **options):
41 # update instance options
42 for k, v in options.items():
43 self.options[k] = v
45 self._fixoptions()
47 # we need a dummy widget to properly process the options
48 # (at least as long as we use Tkinter 1.63)
49 w = Frame(self.master)
51 try:
53 s = apply(w.tk.call, (self.command,) + w._options(self.options))
55 s = self._fixresult(w, s)
57 finally:
59 try:
60 # get rid of the widget
61 w.destroy()
62 except:
63 pass
65 return s