blob: c4ec010ee6b34e382728b15d195d9d186a0d51e7 [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
Serhiy Storchakadc0d5712018-10-12 19:01:00 +030013
Guido van Rossum1e8c8a21997-07-19 20:02:36 +000014class Dialog:
15
16 command = None
17
18 def __init__(self, master=None, **options):
Guido van Rossumc4570481998-03-20 20:45:49 +000019 self.master = master
Guido van Rossum1e8c8a21997-07-19 20:02:36 +000020 self.options = options
Guido van Rossum3179b361998-10-12 20:40:47 +000021 if not master and options.get('parent'):
22 self.master = options['parent']
Guido van Rossum1e8c8a21997-07-19 20:02:36 +000023
24 def _fixoptions(self):
25 pass # hook
26
27 def _fixresult(self, widget, result):
28 return result # hook
29
30 def show(self, **options):
31
32 # update instance options
Guido van Rossumc4570481998-03-20 20:45:49 +000033 for k, v in options.items():
34 self.options[k] = v
Guido van Rossum1e8c8a21997-07-19 20:02:36 +000035
36 self._fixoptions()
37
Guido van Rossum1530c871997-08-14 14:17:28 +000038 # we need a dummy widget to properly process the options
Guido van Rossum1e8c8a21997-07-19 20:02:36 +000039 # (at least as long as we use Tkinter 1.63)
40 w = Frame(self.master)
41
42 try:
43
Raymond Hettingerff41c482003-04-06 09:01:11 +000044 s = w.tk.call(self.command, *w._options(self.options))
Guido van Rossum1e8c8a21997-07-19 20:02:36 +000045
46 s = self._fixresult(w, s)
47
48 finally:
49
50 try:
51 # get rid of the widget
52 w.destroy()
53 except:
54 pass
55
56 return s