home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 April / PCWorld_2001-04_cd.bin / Software / TemaCD / webclean / !!!python!!! / BeOpen-Python-2.0.exe / TKCOMMONDIALOG.PY < prev    next >
Encoding:
Python Source  |  2000-09-28  |  1.6 KB  |  67 lines

  1. #
  2. # Instant Python
  3. # $Id: tkCommonDialog.py,v 1.4 1998/10/12 20:40:47 guido Exp $
  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.  
  15. from Tkinter import *
  16. import os
  17.  
  18. class 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.  
  28.         self.master  = master
  29.         self.options = options
  30.         if not master and options.get('parent'):
  31.             self.master = options['parent']
  32.  
  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
  42.         for k, v in options.items():
  43.             self.options[k] = v
  44.  
  45.         self._fixoptions()
  46.  
  47.         # we need a dummy widget to properly process the options
  48.         # (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
  66.  
  67.