blob: 1e75cae689d41a1289363cfeb08574ceccff97c2 [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):
Guido van Rossumc4570481998-03-20 20:45:49 +000018 self.master = master
Guido van Rossum1e8c8a21997-07-19 20:02:36 +000019 self.options = options
Guido van Rossum3179b361998-10-12 20:40:47 +000020 if not master and options.get('parent'):
21 self.master = options['parent']
Guido van Rossum1e8c8a21997-07-19 20:02:36 +000022
23 def _fixoptions(self):
24 pass # hook
25
26 def _fixresult(self, widget, result):
27 return result # hook
28
29 def show(self, **options):
30
31 # update instance options
Guido van Rossumc4570481998-03-20 20:45:49 +000032 for k, v in options.items():
33 self.options[k] = v
Guido van Rossum1e8c8a21997-07-19 20:02:36 +000034
35 self._fixoptions()
36
Guido van Rossum1530c871997-08-14 14:17:28 +000037 # we need a dummy widget to properly process the options
Guido van Rossum1e8c8a21997-07-19 20:02:36 +000038 # (at least as long as we use Tkinter 1.63)
39 w = Frame(self.master)
40
41 try:
42
Raymond Hettingerff41c482003-04-06 09:01:11 +000043 s = w.tk.call(self.command, *w._options(self.options))
Guido van Rossum1e8c8a21997-07-19 20:02:36 +000044
45 s = self._fixresult(w, s)
46
47 finally:
48
49 try:
50 # get rid of the widget
51 w.destroy()
52 except:
53 pass
54
55 return s