[Python-checkins] r63319 - in sandbox/trunk/ttk-gsoc: Lib/lib-tk/Ttk.py samples/dirbrowser.py

guilherme.polo python-checkins at python.org
Thu May 15 15:37:49 CEST 2008


Author: guilherme.polo
Date: Thu May 15 15:37:48 2008
New Revision: 63319

Log:
Updated samples/dirbrowser so the scrollbars only show when needed.


Modified:
   sandbox/trunk/ttk-gsoc/Lib/lib-tk/Ttk.py
   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	Thu May 15 15:37:48 2008
@@ -364,15 +364,15 @@
                 # Microsoft Visual Styles API which is responsible for the 
                 # themed styles on Windows XP and Vista. 
                 # Availability: Tk 8.6, Windows XP and Vista.
-                className, partId = args[:2]
+                class_name, part_id = args[:2]
                 statemap = _format_mapdict({None: args[2:]})[1]
-                spec = "%s %s %s" % (className, partId, statemap)
+                spec = "%s %s %s" % (class_name, part_id, statemap)
 
             opts = _format_optdict(kw)
 
         elif etype == "from": # clone an element
             # it expects a themename and optionally an element to clone from,
-            # otherwise it will clone {} (empty)
+            # otherwise it will clone {} (empty element)
             spec = args[0] # theme name
             if len(args) > 1: # elementfrom specified
                 opts = (args[1], )
@@ -1098,7 +1098,7 @@
         Valid options/values are:
             text: text
                 The text to display in the column heading
-            image: imageName
+            image: image_name
                 Specifies an image to display to the right of the column
                 heading
             anchor: anchor  

Modified: sandbox/trunk/ttk-gsoc/samples/dirbrowser.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/samples/dirbrowser.py	(original)
+++ sandbox/trunk/ttk-gsoc/samples/dirbrowser.py	Thu May 15 15:37:48 2008
@@ -60,13 +60,25 @@
             tree.delete(tree.get_children(''))
             populate_roots(tree)
 
+def autoscroll(sbar, first, last):
+    """Hide and show scrollbar as needed.
+    
+    Code from Joe English (JE) at http://wiki.tcl.tk/950"""
+    first, last = float(first), float(last)
+    if first <= 0 and last >= 1:
+        sbar.grid_remove()
+    else:
+        sbar.grid()
+    sbar.set(first, last)
+
 root = Tkinter.Tk()
 
 vsb = ttk.Scrollbar(orient="vertical")
 hsb = ttk.Scrollbar(orient="horizontal")
 
 tree = ttk.Treeview(columns=("fullpath", "type", "size"), 
-    displaycolumns="size", yscroll=vsb.set, xscroll=hsb.set)
+    displaycolumns="size", yscrollcommand=lambda f, l: autoscroll(vsb, f, l),
+    xscrollcommand=lambda f, l:autoscroll(hsb, f, l))
 
 vsb['command'] = tree.yview
 hsb['command'] = tree.xview


More information about the Python-checkins mailing list