[Python-checkins] python/dist/src/Lib/lib-tk Tkinter.py, 1.178, 1.179

david_ascher at users.sourceforge.net david_ascher at users.sourceforge.net
Wed Feb 18 00:59:55 EST 2004


Update of /cvsroot/python/python/dist/src/Lib/lib-tk
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24617/dist/src/Lib/lib-tk

Modified Files:
	Tkinter.py 
Log Message:
Implementation of patch 869468

Allow the user to create Tkinter.Tcl objects which are
just like Tkinter.Tk objects except that they do not
initialize Tk. This is useful in circumstances where the
script is being run on machines that do not have an X
server running -- in those cases, Tk initialization fails,
even if no window is ever created.

Includes documentation change and tests.

Tested on Linux, Solaris and Windows.

Reviewed by Martin von Loewis.


Index: Tkinter.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/lib-tk/Tkinter.py,v
retrieving revision 1.178
retrieving revision 1.179
diff -C2 -d -r1.178 -r1.179
*** Tkinter.py	12 Feb 2004 17:35:09 -0000	1.178
--- Tkinter.py	18 Feb 2004 05:59:53 -0000	1.179
***************
*** 1547,1551 ****
      of an appliation. It has an associated Tcl interpreter."""
      _w = '.'
!     def __init__(self, screenName=None, baseName=None, className='Tk'):
          """Return a new Toplevel widget on screen SCREENNAME. A new Tcl interpreter will
          be created. BASENAME will be used for the identification of the profile file (see
--- 1547,1551 ----
      of an appliation. It has an associated Tcl interpreter."""
      _w = '.'
!     def __init__(self, screenName=None, baseName=None, className='Tk', useTk=1):
          """Return a new Toplevel widget on screen SCREENNAME. A new Tcl interpreter will
          be created. BASENAME will be used for the identification of the profile file (see
***************
*** 1553,1559 ****
          It is constructed from sys.argv[0] without extensions if None is given. CLASSNAME
          is the name of the widget class."""
-         global _default_root
          self.master = None
          self.children = {}
          if baseName is None:
              import sys, os
--- 1553,1562 ----
          It is constructed from sys.argv[0] without extensions if None is given. CLASSNAME
          is the name of the widget class."""
          self.master = None
          self.children = {}
+         self._tkloaded = 0
+         # to avoid recursions in the getattr code in case of failure, we
+         # ensure that self.tk is always _something_.
+         self.tk = None  
          if baseName is None:
              import sys, os
***************
*** 1562,1567 ****
              if ext not in ('.py', '.pyc', '.pyo'):
                  baseName = baseName + ext
!         self.tk = _tkinter.create(screenName, baseName, className)
!         self.tk.wantobjects(wantobjects)
          if _MacOS and hasattr(_MacOS, 'SchedParams'):
              # Disable event scanning except for Command-Period
--- 1565,1580 ----
              if ext not in ('.py', '.pyc', '.pyo'):
                  baseName = baseName + ext
!         interactive = 0
!         self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk)
!         if useTk:
!             self._loadtk()
!         self.readprofile(baseName, className)
!     def loadtk(self):
!         if not self._tkloaded:
!             self.tk.loadtk()
!             self._loadtk()
!     def _loadtk(self):
!         self._tkloaded = 1
!         global _default_root
          if _MacOS and hasattr(_MacOS, 'SchedParams'):
              # Disable event scanning except for Command-Period
***************
*** 1588,1592 ****
          self.tk.createcommand('tkerror', _tkerror)
          self.tk.createcommand('exit', _exit)
-         self.readprofile(baseName, className)
          if _support_default_root and not _default_root:
              _default_root = self
--- 1601,1604 ----
***************
*** 1630,1633 ****
--- 1642,1654 ----
          sys.last_traceback = tb
          traceback.print_exception(exc, val, tb)
+     def __getattr__(self, attr):
+         "Delegate attribute access to the interpreter object"
+         return getattr(self.tk, attr)
+     def __hasattr__(self, attr):
+         "Delegate attribute access to the interpreter object"
+         return hasattr(self.tk, attr)
+     def __delattr__(self, attr):
+         "Delegate attribute access to the interpreter object"
+         return delattr(self.tk, attr)
  
  # Ideally, the classes Pack, Place and Grid disappear, the
***************
*** 1645,1648 ****
--- 1666,1673 ----
  # copied into the Pack, Place or Grid class.
  
+ 
+ def Tcl(screenName=None, baseName=None, className='Tk', useTk=0):
+     return Tk(screenName, baseName, className, useTk)
+ 
  class Pack:
      """Geometry manager Pack.




More information about the Python-checkins mailing list