[Python-checkins] r63232 - in sandbox/trunk/ttk-gsoc: Lib/lib-tk/Ttk.py Lib/tkinter/ttk.py README samples/dirbrowser.py
guilherme.polo
python-checkins at python.org
Wed May 14 23:08:07 CEST 2008
Author: guilherme.polo
Date: Wed May 14 23:08:07 2008
New Revision: 63232
Log:
Updated ttk module to support the env var TILE_LIBRARY used by custom
tile installations.
Updated samples/dirbrowser so it works correctly under Windows.
Removed the XXX comment at Treeview's insert after considering the
option "values" special enough to not fit under _format_optdict.
Updated README to match where I've tested this module and samples.
Modified:
sandbox/trunk/ttk-gsoc/Lib/lib-tk/Ttk.py
sandbox/trunk/ttk-gsoc/Lib/tkinter/ttk.py
sandbox/trunk/ttk-gsoc/README
sandbox/trunk/ttk-gsoc/samples/dirbrowser.py
Modified: sandbox/trunk/ttk-gsoc/Lib/lib-tk/Ttk.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/Lib/lib-tk/Ttk.py (original)
+++ sandbox/trunk/ttk-gsoc/Lib/lib-tk/Ttk.py Wed May 14 23:08:07 2008
@@ -26,18 +26,23 @@
# Verify if Tk is new enough to not need Tile checking
REQUIRE_TILE = True if Tkinter.TkVersion < 8.5 else False
-# XXX Looking at FixTk.py it seems something like TILE_LIBRARY env check
-# should be added there and possibly here before tile package check.
def _loadttk(loadtk):
- # Extend default Tkinter.Tk._loadtk method so we can be sure that
- # Ttk is available for use, or not.
+ # This extends the default Tkinter.Tk._loadtk method so we can be
+ # sure that Ttk is available for use, or not.
def f(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)
# XXX Maybe I should catch a possible TclError and display
# a Warning telling Ttk won't be available ? Or maybe I
- # shouldn't be doing this at all, the users could then
- # write the next line
+ # shouldn't even be doing all this.
self.tk.eval('package require tile')
return f
@@ -1147,7 +1152,7 @@
is generated."""
opts, values = _format_optdict(kw, ignore='values'), kw.get('values')
# values may need special formatting if any value contain a space
- if values: # XXX maybe this could fit into _format_optdict
+ if values:
opts += ("-values",
' '.join(('{%s}' if ' ' in v else '%s') % v for v in values))
if iid:
Modified: sandbox/trunk/ttk-gsoc/Lib/tkinter/ttk.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/Lib/tkinter/ttk.py (original)
+++ sandbox/trunk/ttk-gsoc/Lib/tkinter/ttk.py Wed May 14 23:08:07 2008
@@ -26,18 +26,23 @@
# Verify if Tk is new enough to not need Tile checking
REQUIRE_TILE = True if Tkinter.TkVersion < 8.5 else False
-# XXX Looking at FixTk.py it seems something like TILE_LIBRARY env check
-# should be added there and possibly here before tile package check.
def _loadttk(loadtk):
- # Extend default Tkinter.Tk._loadtk method so we can be sure that
- # Ttk is available for use, or not.
+ # This extends the default Tkinter.Tk._loadtk method so we can be
+ # sure that Ttk is available for use, or not.
def f(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)
# XXX Maybe I should catch a possible TclError and display
# a Warning telling Ttk won't be available ? Or maybe I
- # shouldn't be doing this at all, the users could then
- # write the next line
+ # shouldn't even be doing all this.
self.tk.eval('package require tile')
return f
@@ -1147,8 +1152,8 @@
is generated."""
opts, values = _format_optdict(kw, ignore='values'), kw.get('values')
# values may need special formatting if any value contain a space
- if values: # XXX maybe this could fit into _format_optdict
- opts += ("-values",
+ if values:
+ opts += ("-values",
' '.join(('{%s}' if ' ' in v else '%s') % v for v in values))
if iid:
res = self.tk.call(self._w, "insert", parent, index, "-id", iid,
Modified: sandbox/trunk/ttk-gsoc/README
==============================================================================
--- sandbox/trunk/ttk-gsoc/README (original)
+++ sandbox/trunk/ttk-gsoc/README Wed May 14 23:08:07 2008
@@ -4,7 +4,7 @@
You will need Python with a _tkinter compiled against Tcl/Tk 8.5
otherwise Tile[1] has to be installed. I have tested it under Linux
with python 2.5.2 (Ubuntu package), python-trunk, release25-maint and
-py3k repos.
+py3k repos and under Windows XP with python 2.5.1.
Given that you meet the requirements, you should be able to run the
samples passing the appropriate PYTHONPATH (ttk-gsoc/Lib/lib-tk for
@@ -13,7 +13,9 @@
[1] I've tested it with Tile 0.8.2 and it works, but I would recommend
upgrading to Tcl/Tk 8.5 so you get antialiased fonts and other
- nice features.
+ nice features. If you are testing this wrapper with Tile, it will
+ look for the environment variable TILE_LIBRARY, which you can set
+ to your tile library path if you installed it in a custom place.
Reading the Documentation
Modified: sandbox/trunk/ttk-gsoc/samples/dirbrowser.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/samples/dirbrowser.py (original)
+++ sandbox/trunk/ttk-gsoc/samples/dirbrowser.py Wed May 14 23:08:07 2008
@@ -24,26 +24,25 @@
special_dirs = [] if parent else glob.glob('.') + glob.glob('..')
for p in special_dirs + os.listdir(path):
- p = os.path.join(path, p)
- if os.path.isdir(p):
- type = "directory"
- elif os.path.isfile(p):
- type = "file"
+ ptype = None
+ p = os.path.join(path, p).replace('\\', '/')
+ if os.path.isdir(p): ptype = "directory"
+ elif os.path.isfile(p): ptype = "file"
fname = os.path.split(p)[1]
- id = tree.insert(node, "end", text=fname, values=[p, type])
+ id = tree.insert(node, "end", text=fname, values=[p, ptype])
- if type == 'directory':
+ if ptype == 'directory':
if fname not in ('.', '..'):
tree.insert(id, 0, text="dummy")
tree.item(id, text=fname)
- elif type == 'file':
+ elif ptype == 'file':
size = os.stat(p).st_size
tree.set(id, "size", "%d bytes" % size)
def populate_roots(tree):
- dir = os.path.abspath('.')
+ dir = os.path.abspath('.').replace('\\', '/')
node = tree.insert('', 'end', text=dir, values=[dir, "directory"])
populate_tree(tree, node)
@@ -57,13 +56,9 @@
if tree.parent(node):
path = os.path.abspath(tree.set(node, "fullpath"))
if os.path.isdir(path):
- try:
- os.chdir(path)
- except OSError, e:
- print e
- else:
- tree.delete(tree.get_children(''))
- populate_roots(tree)
+ os.chdir(path)
+ tree.delete(tree.get_children(''))
+ populate_roots(tree)
root = Tkinter.Tk()
More information about the Python-checkins
mailing list