blob: d2688dba9b547129ed398ac95b08faa1f42911c4 [file] [log] [blame]
Guido van Rossum1e8c8a21997-07-19 20:02:36 +00001# base class for tk common dialogues
2#
3# this module provides a base class for accessing the common
Georg Brandl14fc4272008-05-17 18:39:55 +00004# dialogues available in Tk 4.2 and newer. use filedialog,
5# colorchooser, and messagebox to access the individual
Guido van Rossum1e8c8a21997-07-19 20:02:36 +00006# dialogs.
7#
8# written by Fredrik Lundh, May 1997
9#
10
Georg Brandl14fc4272008-05-17 18:39:55 +000011from tkinter import *
Guido van Rossum1e8c8a21997-07-19 20:02:36 +000012
13class Dialog:
14
15 command = None
16
17 def __init__(self, master=None, **options):
18
19 # FIXME: should this be placed on the module level instead?
20 if TkVersion < 4.2:
Collin Winterce36ad82007-08-30 01:19:48 +000021 raise TclError("this module requires Tk 4.2 or newer")
Guido van Rossum1e8c8a21997-07-19 20:02:36 +000022
Guido van Rossumc4570481998-03-20 20:45:49 +000023 self.master = master
Guido van Rossum1e8c8a21997-07-19 20:02:36 +000024 self.options = options
Guido van Rossum3179b361998-10-12 20:40:47 +000025 if not master and options.get('parent'):
26 self.master = options['parent']
Guido van Rossum1e8c8a21997-07-19 20:02:36 +000027
28 def _fixoptions(self):
29 pass # hook
30
31 def _fixresult(self, widget, result):
32 return result # hook
33
34 def show(self, **options):
35
36 # update instance options
Guido van Rossumc4570481998-03-20 20:45:49 +000037 for k, v in options.items():
38 self.options[k] = v
Guido van Rossum1e8c8a21997-07-19 20:02:36 +000039
40 self._fixoptions()
41
Guido van Rossum1530c871997-08-14 14:17:28 +000042 # we need a dummy widget to properly process the options
Guido van Rossum1e8c8a21997-07-19 20:02:36 +000043 # (at least as long as we use Tkinter 1.63)
44 w = Frame(self.master)
45
46 try:
47
Raymond Hettingerff41c482003-04-06 09:01:11 +000048 s = w.tk.call(self.command, *w._options(self.options))
Guido van Rossum1e8c8a21997-07-19 20:02:36 +000049
50 s = self._fixresult(w, s)
51
52 finally:
53
54 try:
55 # get rid of the widget
56 w.destroy()
57 except:
58 pass
59
60 return s