summaryrefslogtreecommitdiffstats
path: root/Lib/tkinter
diff options
context:
space:
mode:
authorGuilherme Polo <ggpolo@gmail.com>2009-02-07 02:33:47 (GMT)
committerGuilherme Polo <ggpolo@gmail.com>2009-02-07 02:33:47 (GMT)
commitfa8fba96a6af233d36cbe9b3d42832d6f071e50b (patch)
tree5fea90016b07fccc19d79e35b51287c026ac6bc2 /Lib/tkinter
parentb2071f86844d24685cd916fe5955236f2685d75c (diff)
downloadcpython-fa8fba96a6af233d36cbe9b3d42832d6f071e50b.zip
cpython-fa8fba96a6af233d36cbe9b3d42832d6f071e50b.tar.gz
cpython-fa8fba96a6af233d36cbe9b3d42832d6f071e50b.tar.bz2
Merged revisions 69404 via svnmerge from
svn+ssh://pythondev/python/trunk ........ r69404 | guilherme.polo | 2009-02-07 00:20:29 -0200 (Sat, 07 Feb 2009) | 2 lines Eliminated the need to use ttk.__loadtk__ and the problems related it. ........
Diffstat (limited to 'Lib/tkinter')
-rw-r--r--Lib/tkinter/ttk.py71
1 files changed, 41 insertions, 30 deletions
diff --git a/Lib/tkinter/ttk.py b/Lib/tkinter/ttk.py
index 82420aa..89a9bf1 100644
--- a/Lib/tkinter/ttk.py
+++ b/Lib/tkinter/ttk.py
@@ -29,32 +29,40 @@ import tkinter
_flatten = tkinter._flatten
-# Verify if Tk is new enough to not need Tile checking
+# Verify if Tk is new enough to not need the Tile package
_REQUIRE_TILE = True if tkinter.TkVersion < 8.5 else False
-def _loadttk(loadtk):
- # This extends the default tkinter.Tk._loadtk method so we can be
- # sure that ttk is available for use, or not.
- def _wrapper(self):
- loadtk(self)
-
- if _REQUIRE_TILE:
- import os
- tilelib = os.environ.get('TILE_LIBRARY')
- if tilelib:
- # append custom tile path to the the list of directories that
- # Tcl uses when attempting to resolve packages with the package
- # command
- self.tk.eval('global auto_path; '
- 'lappend auto_path {%s}' % tilelib)
- self.tk.eval('package require tile') # TclError may be raised here
-
- return _wrapper
-
-# Store the original tkinter.Tk._loadtk before replacing it just in case
-# someone wants to restore it.
-__loadtk__ = tkinter.Tk._loadtk
-tkinter.Tk._loadtk = _loadttk(tkinter.Tk._loadtk)
+def _load_tile(master):
+ if _REQUIRE_TILE:
+ import os
+ tilelib = os.environ.get('TILE_LIBRARY')
+ if tilelib:
+ # append custom tile path to the the list of directories that
+ # Tcl uses when attempting to resolve packages with the package
+ # command
+ master.tk.eval(
+ 'global auto_path; '
+ 'lappend auto_path {%s}' % tilelib)
+
+ master.tk.eval('package require tile') # TclError may be raised here
+ master._tile_loaded = True
+
+
+def _setup_master(master=None):
+ """If master is not None, itself is returned. If master is None,
+ the default master is returned if there is one, otherwise a new
+ master is created and returned.
+
+ If it is not allowed to use the default root and master is None,
+ RuntimeError is raised."""
+ if master is None:
+ if tkinter._support_default_root:
+ master = tkinter._default_root or tkinter.Tk()
+ else:
+ raise RuntimeError(
+ "No master specified and tkinter is "
+ "configured to not support default root")
+ return master
def _format_optdict(optdict, script=False, ignore=None):
@@ -366,12 +374,11 @@ class Style(object):
_name = "ttk::style"
def __init__(self, master=None):
- if master is None:
- if tkinter._support_default_root:
- master = tkinter._default_root or tkinter.Tk()
- else:
- raise RuntimeError("No master specified and tkinter is "
- "configured to not support default master")
+ master = _setup_master(master)
+
+ if not getattr(master, '_tile_loaded', False):
+ # Load tile now, if needed
+ _load_tile(master)
self.master = master
self.tk = self.master.tk
@@ -548,6 +555,10 @@ class Widget(tkinter.Widget):
active, disabled, focus, pressed, selected, background,
readonly, alternate, invalid
"""
+ master = _setup_master(master)
+ if not getattr(master, '_tile_loaded', False):
+ # Load tile now, if needed
+ _load_tile(master)
tkinter.Widget.__init__(self, master, widgetname, kw=kw)