Commit fa8fba96 authored by Guilherme Polo's avatar Guilherme Polo

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.
........
parent b2071f86
...@@ -4,15 +4,9 @@ import unittest ...@@ -4,15 +4,9 @@ import unittest
import os import os
import _tkinter import _tkinter
from test import support from test import support
from tkinter import Tk, Tcl from tkinter import Tcl
from _tkinter import TclError from _tkinter import TclError
# Restore Tkinter.Tk._loadtk that may have been overridden by ttk.
# If this is not done then this test may fail for reasons related
# to ttk only (like failing to load the tile package).
from tkinter.ttk import __loadtk__
Tk._loadtk = __loadtk__
class TkinterTest(unittest.TestCase): class TkinterTest(unittest.TestCase):
......
...@@ -29,15 +29,10 @@ import tkinter ...@@ -29,15 +29,10 @@ import tkinter
_flatten = tkinter._flatten _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 _REQUIRE_TILE = True if tkinter.TkVersion < 8.5 else False
def _loadttk(loadtk): def _load_tile(master):
# 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: if _REQUIRE_TILE:
import os import os
tilelib = os.environ.get('TILE_LIBRARY') tilelib = os.environ.get('TILE_LIBRARY')
...@@ -45,16 +40,29 @@ def _loadttk(loadtk): ...@@ -45,16 +40,29 @@ def _loadttk(loadtk):
# append custom tile path to the the list of directories that # append custom tile path to the the list of directories that
# Tcl uses when attempting to resolve packages with the package # Tcl uses when attempting to resolve packages with the package
# command # command
self.tk.eval('global auto_path; ' master.tk.eval(
'global auto_path; '
'lappend auto_path {%s}' % tilelib) 'lappend auto_path {%s}' % tilelib)
self.tk.eval('package require tile') # TclError may be raised here
return _wrapper 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.
# Store the original tkinter.Tk._loadtk before replacing it just in case If it is not allowed to use the default root and master is None,
# someone wants to restore it. RuntimeError is raised."""
__loadtk__ = tkinter.Tk._loadtk if master is None:
tkinter.Tk._loadtk = _loadttk(tkinter.Tk._loadtk) 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): def _format_optdict(optdict, script=False, ignore=None):
...@@ -366,12 +374,11 @@ class Style(object): ...@@ -366,12 +374,11 @@ class Style(object):
_name = "ttk::style" _name = "ttk::style"
def __init__(self, master=None): def __init__(self, master=None):
if master is None: master = _setup_master(master)
if tkinter._support_default_root:
master = tkinter._default_root or tkinter.Tk() if not getattr(master, '_tile_loaded', False):
else: # Load tile now, if needed
raise RuntimeError("No master specified and tkinter is " _load_tile(master)
"configured to not support default master")
self.master = master self.master = master
self.tk = self.master.tk self.tk = self.master.tk
...@@ -548,6 +555,10 @@ class Widget(tkinter.Widget): ...@@ -548,6 +555,10 @@ class Widget(tkinter.Widget):
active, disabled, focus, pressed, selected, background, active, disabled, focus, pressed, selected, background,
readonly, alternate, invalid 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) tkinter.Widget.__init__(self, master, widgetname, kw=kw)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment