0001 # 0002 # Instant Python 0003 # $Id: tkCommonDialog.py,v 1.7 2003/04/06 09:00:53 rhettinger Exp $ 0004 # 0005 # base class for tk common dialogues 0006 # 0007 # this module provides a base class for accessing the common 0008 # dialogues available in Tk 4.2 and newer. use tkFileDialog, 0009 # tkColorChooser, and tkMessageBox to access the individual 0010 # dialogs. 0011 # 0012 # written by Fredrik Lundh, May 1997 0013 # 0014 0015 from Tkinter import * 0016 0017 class Dialog: 0018 0019 command = None 0020 0021 def __init__(self, master=None, **options): 0022 0023 # FIXME: should this be placed on the module level instead? 0024 if TkVersion < 4.2: 0025 raise TclError, "this module requires Tk 4.2 or newer" 0026 0027 self.master = master 0028 self.options = options 0029 if not master and options.get('parent'): 0030 self.master = options['parent'] 0031 0032 def _fixoptions(self): 0033 pass # hook 0034 0035 def _fixresult(self, widget, result): 0036 return result # hook 0037 0038 def show(self, **options): 0039 0040 # update instance options 0041 for k, v in options.items(): 0042 self.options[k] = v 0043 0044 self._fixoptions() 0045 0046 # we need a dummy widget to properly process the options 0047 # (at least as long as we use Tkinter 1.63) 0048 w = Frame(self.master) 0049 0050 try: 0051 0052 s = w.tk.call(self.command, *w._options(self.options)) 0053 0054 s = self._fixresult(w, s) 0055 0056 finally: 0057 0058 try: 0059 # get rid of the widget 0060 w.destroy() 0061 except: 0062 pass 0063 0064 return s 0065
Generated by PyXR 0.9.4