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

guilherme.polo python-checkins at python.org
Tue May 6 23:56:35 CEST 2008


Author: guilherme.polo
Date: Tue May  6 23:56:34 2008
New Revision: 62781

Log:
map and configure (Ttk Style) output is according to what they expect 
as input now.

Improved samples/roundframe.py a bit.


Modified:
   sandbox/trunk/ttk-gsoc/Lib/lib-tk/Ttk.py
   sandbox/trunk/ttk-gsoc/samples/roundframe.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	Tue May  6 23:56:34 2008
@@ -101,7 +101,7 @@
 
 def _format_layoutdict(layout, indent=2, child=False):
     """Formats a layout dict so we can pass the result to ttk::style 
-    layout and ttk::style map.
+    layout and ttk::style settings.
     
     E.g.:
       {"Menubutton.background": None,
@@ -182,11 +182,23 @@
     return '\n'.join(script)
 
 def _dict_from_tcltuple(t):
-    """Break tuple in pairs then build the return dict.
+    """Break tuple in pairs, format it properly, then build the return 
+    dict.
 
     t is expected to contain an even number of elements."""
-    opts = (t[i * 2:i * 2 + 2] for i in range(len(t) / 2))
+    opts = []
+    for i in range(len(t) / 2):
+        opt, value = t[i * 2:i * 2 + 2]
+        if isinstance(value, basestring):
+            if value.find(' ') != -1: # could be padding returned by configure
+                value = map(int, value.split())
+
+        elif hasattr(value, "__len__"):
+            # possibly a StateSpec object returned by map
+            value = [[str(value[0]).split(), value[1]]]
 
+        opts.append((opt, value))
+    
     # note that the '-' prefixing options will be removed
     return dict((str(opt[0])[1:], opt[1]) for opt in opts)
 
@@ -226,8 +238,8 @@
         
         Each key in kw is an option and each value is either a string or
         a sequence identifying the value for that option."""
-        opts = _format_optdict(kw)
-        return self.tk.call(self._name, "configure", style, *opts)
+        return _dict_from_tcltuple(self.tk.call(self._name, "configure", style,
+                                                *(_format_optdict(kw))))
 
 
     def map(self, style, **kw):
@@ -238,7 +250,8 @@
         and a value, grouped in yet another sequence. Note that a group of 
         states is expected to be a sequence, otherwise a single string 
         should be passed as state."""
-        return self.tk.call(self._name, "map", style, *(_format_mapdict(kw)))
+        return _dict_from_tcltuple(self.tk.call(self._name, "map", style, 
+                                                *(_format_mapdict(kw))))
 
 
     def lookup(self, style, option, state=None, default=None):
@@ -285,11 +298,11 @@
                     where the first item is the layout name, and the other
                     is a LAYOUT.
         """
+        # XXX returned layout should be formatted according to the accepted
+        #     layoutspec
         lspec = None
         if layoutspec:
             lspec = _format_layoutdict(layoutspec)[0]
-        # XXX returned layout should be formatted according to the accepted
-        #     layoutspec
         return self.tk.call(self._name, "layout", style, lspec)
 
 
@@ -1093,7 +1106,7 @@
         It is illegal to move an item under one of its descendants. If
         index is less than or equal to zero, item is moved to the 
         beginning, if greater than or equal to the number of children,
-        it is moved to the end. If it was detached it is reattached."""
+        it is moved to the end. If item was detached it is reattached."""
         self.tk.call(self._w, "move", item, parent, index)
 
     reattach = move # A sensible method name for reattaching detached items

Modified: sandbox/trunk/ttk-gsoc/samples/roundframe.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/samples/roundframe.py	(original)
+++ sandbox/trunk/ttk-gsoc/samples/roundframe.py	Tue May  6 23:56:34 2008
@@ -97,9 +97,14 @@
 frame2 = Ttk.Frame(style="RoundedFrame", padding=10)
 frame2.pack(fill='both', expand=1)
 
-btn = Ttk.Button(frame, text='Test')
-btn.pack()
-btn.bind("<FocusIn>", lambda evt: frame.state(["focus"]))
-btn.bind("<FocusOut>", lambda evt: frame.state(["!focus"]))
+entry = Ttk.Entry(frame, text='Test')
+entry.pack(fill='x')
+entry.bind("<FocusIn>", lambda evt: frame.state(["focus"]))
+entry.bind("<FocusOut>", lambda evt: frame.state(["!focus"]))
+
+text = Tkinter.Text(frame2)
+text.pack()
+text.bind("<FocusIn>", lambda evt: frame2.state(["focus"]))
+text.bind("<FocusOut>", lambda evt: frame2.state(["!focus"]))
 
 root.mainloop()


More information about the Python-checkins mailing list