blob: 32b8a8bf308607fce641c767e65243fb9914bd21 [file] [log] [blame]
Guido van Rossum1e8c8a21997-07-19 20:02:36 +00001#
2# Instant Python
3# $Id$
4#
5# base class for tk common dialogues
6#
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.
11#
12# written by Fredrik Lundh, May 1997
13#
14
15from Tkinter import *
16import os
17
18class Dialog:
19
20 command = None
21
22 def __init__(self, master=None, **options):
23
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"
27
Guido van Rossumc4570481998-03-20 20:45:49 +000028 self.master = master
Guido van Rossum1e8c8a21997-07-19 20:02:36 +000029 self.options = options
Guido van Rossum3179b361998-10-12 20:40:47 +000030 if not master and options.get('parent'):
31 self.master = options['parent']
Guido van Rossum1e8c8a21997-07-19 20:02:36 +000032
33 def _fixoptions(self):
34 pass # hook
35
36 def _fixresult(self, widget, result):
37 return result # hook
38
39 def show(self, **options):
40
41 # update instance options
Guido van Rossumc4570481998-03-20 20:45:49 +000042 for k, v in options.items():
43 self.options[k] = v
Guido van Rossum1e8c8a21997-07-19 20:02:36 +000044
45 self._fixoptions()
46
Guido van Rossum1530c871997-08-14 14:17:28 +000047 # we need a dummy widget to properly process the options
Guido van Rossum1e8c8a21997-07-19 20:02:36 +000048 # (at least as long as we use Tkinter 1.63)
49 w = Frame(self.master)
50
51 try:
52
53 s = apply(w.tk.call, (self.command,) + w._options(self.options))
54
55 s = self._fixresult(w, s)
56
57 finally:
58
59 try:
60 # get rid of the widget
61 w.destroy()
62 except:
63 pass
64
65 return s