[Python-checkins] r62621 - sandbox/trunk/ttk-gsoc/Lib/lib-tk/Ttk.py

guilherme.polo python-checkins at python.org
Thu May 1 23:54:18 CEST 2008


Author: guilherme.polo
Date: Thu May  1 23:54:18 2008
New Revision: 62621

Log:
Updated some comments in _format_mapdict so they are more accurate 
and moved code for checking script argument to function's top so it
isn't checked for every (key, value) in mapdict.


Modified:
   sandbox/trunk/ttk-gsoc/Lib/lib-tk/Ttk.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  1 23:54:18 2008
@@ -56,33 +56,28 @@
 def _format_mapdict(mapdict, script=False):
     """Formats mapdict to pass it to tk.call.
     
-    E.g.:
+    E.g. (script=False):
       {'background': [('active", 'white'), ('focus', 'blue')]} returns:
       ('-background', 'active white focus blue')"""
+    # if caller passes a Tcl script to tk.call, all the values need to 
+    # be grouped into words (arguments to a command in Tcl dialect)
+    format = "%s" if not script else "{%s}"
 
     opts = []
-
     for opt, value in mapdict.iteritems():
 
         opt_val = []
         # each value in mapdict is expected to be a sequence, where each item
-        # is a another sequence containg a state (or several) and a value 
-        # for it
+        # is another sequence containg a state (or several) and a value for it
         for state, val in value:
             if not isinstance(state, basestring):
-                # lets believe it is a sequence and format these multiple 
-                # states according to Tk documentation
+                # lets believe it is a sequence and group these multiple states
                 state = "{%s}" % ' '.join(state) 
 
             opt_val.append("%s %s" % (state, val))
 
-        if script: 
-            # theme_settings passes a Tcl script to tk.call, so it needs
-            # a Tcl formatting
-            opts.append(("-%s" % opt, "[list %s]" % ' '.join(opt_val)))
-        else:
-            opts.append(("-%s" % opt, ' '.join(opt_val)))
-
+        opts.append(("-%s" % opt, format % ' '.join(opt_val)))
+    
     return Tkinter._flatten(opts)
 
 
@@ -99,6 +94,7 @@
 
         self.tk = master.tk
 
+
     def configure(self, style, **kw):
         """Sets the default value of the specified option(s) in style.
         


More information about the Python-checkins mailing list