home *** CD-ROM | disk | FTP | other *** search
/ Freelog Special Freeware 31 / FreelogHS31.iso / Texte / scribus / scribus-1.3.3.9-win32-install.exe / tcl / tix8.1 / pref / WmDefault.py < prev    next >
Text File  |  2001-12-08  |  4KB  |  97 lines

  1. # -*- mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
  2. #
  3. #    $Id: WmDefault.py,v 1.1.2.1 2001/12/09 02:52:40 idiscovery Exp $
  4. #
  5.  
  6.  
  7. """One of the bad things about Tk/Tkinter is that it does not pick up
  8. the current color and font scheme from the prevailing CDE/KDE/GNOME/Windows 
  9. window manager scheme.
  10.  
  11. One of the good things about Tk/Tkinter is that it is not tied to one
  12. particular widget set so it could pick up the current color and font scheme 
  13. from the prevailing CDE/KDE/GNOME/Windows window manager scheme.
  14.  
  15. The WmDefault package is for making Tk/Tkinter applications use the 
  16. prevailing CDE/KDE/GNOME/Windows scheme. It tries to find the files
  17. and/or settings that the current window manager is using, and then
  18. sets the Tk options database accordingly.
  19.  
  20. Download the latest version of wm_default from http://tix.sourceforge.net
  21. either as a part of the standard Tix distribution, or as a part of the
  22. Tix Applications: http://tix.sourceforge.net/Tide. wm_default does not
  23. require Tix, but is Tix enabled.
  24. """
  25.  
  26. import os, sys, traceback, string
  27. import tkMessageBox
  28.  
  29. def setup(root, wm=''):
  30.     """1) find the files and/or settings (::wm_default::setup).
  31.     Takes one optional argument: wm, the name of the window manager
  32.     as a string, if known. One of: windows gnome kde1 kde2 cde kde.
  33.     """
  34.     try:
  35.         try:
  36.             # Make sure Tcl/Tk knows wm_default is installed
  37.             root.tk.eval("package require wm_default")
  38.         except:
  39.             # Try again with this directory on the Tcl/Tk path
  40.             dir = os.path.dirname (self.__file__)
  41.             root.tk.eval('global auto_path; lappend auto_path {%s}' % dir)
  42.             root.tk.eval("package require wm_default")
  43.     except:
  44.         t, v, tb = sys.exc_info()
  45.         text = "Error loading WmDefault\n"
  46.         for line in traceback.format_exception(t,v,tb): text = text + line + '\n'
  47.         try:
  48.             tkMessageBox.showerror ('WmDefault Error', text)
  49.         except:
  50.             sys.stderr.write( text )
  51.  
  52.     return root.tk.call('::wm_default::setup', wm)
  53.  
  54. def addoptions(root, cnf=None, **kw):
  55.     """2) Setting the Tk options database (::wm_default::addoptions).
  56.     You can override the settings in 1) by adding your values to the
  57.     call to addoptions().
  58.     """
  59.     if cnf is None:
  60.         return root.tk.splitlist(root.tk.call('::wm_default::addoptions'))
  61.     return root.tk.splitlist(
  62.         apply(root.tk.call,
  63.               ('::wm_default::addoptions',) + root._options(cnf,kw)))
  64.  
  65. def getoptions(root):
  66.     """Returns the current settings, as a dictionary.
  67.     """
  68.     words = root.tk.splitlist(root.tk.call('::wm_default::getoptions'))
  69.     dict = {}
  70.     for i in range(0, len(words), 2):
  71.         key = words[i]
  72.         value = words[i+1]
  73.         dict[key] = value
  74.     return dict
  75.  
  76. def parray(root):
  77.     """Returns a string of the current settings, one value-pair per line.
  78.     """
  79.     return root.tk.call('::wm_default::parray')
  80.  
  81. if __name__ == "__main__":
  82.     dir = ""
  83.     if len(sys.argv) > 0:
  84.         # Assume the name of the file containing the tixinspect Tcl source
  85.         # is the same as argument on the command line with .tcl
  86.     dir = os.path.dirname(sys.argv[0])
  87.     if not dir or not os.path.isdir(dir) or not os.path.isabs(dir):
  88.         # Or, assume it's in the same directory as this one:
  89.         dir = os.getcwd()
  90.     import Tkinter
  91.     root = Tkinter.Tk()
  92.     setup(root)
  93.     addoptions(root, {'foreground': 'red'})
  94.     retval = getoptions(root)
  95.     print retval
  96.  
  97.