[Python-checkins] r63733 - in sandbox/trunk/ttk-gsoc: samples/mac_searchentry.py samples/notebook_closebtn.py samples/roundframe.py src/2.x/ttk.py src/3.x/ttk.py

guilherme.polo python-checkins at python.org
Mon May 26 23:50:52 CEST 2008


Author: guilherme.polo
Date: Mon May 26 23:50:51 2008
New Revision: 63733

Log:
Some janitor work and minor fixes

Modified:
   sandbox/trunk/ttk-gsoc/samples/mac_searchentry.py
   sandbox/trunk/ttk-gsoc/samples/notebook_closebtn.py
   sandbox/trunk/ttk-gsoc/samples/roundframe.py
   sandbox/trunk/ttk-gsoc/src/2.x/ttk.py
   sandbox/trunk/ttk-gsoc/src/3.x/ttk.py

Modified: sandbox/trunk/ttk-gsoc/samples/mac_searchentry.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/samples/mac_searchentry.py	(original)
+++ sandbox/trunk/ttk-gsoc/samples/mac_searchentry.py	Mon May 26 23:50:51 2008
@@ -58,7 +58,7 @@
 style = ttk.Style()
 
 style.element_create("Search.field", "image", "search1",
-    (("focus", ), "search2"), border=[22, 7, 14], sticky="ew")
+    ("focus", "search2"), border=[22, 7, 14], sticky="ew")
 
 style.layout("Search.entry", [
     ("Search.field", {"sticky": "nswe", "border": 1, "children":

Modified: sandbox/trunk/ttk-gsoc/samples/notebook_closebtn.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/samples/notebook_closebtn.py	(original)
+++ sandbox/trunk/ttk-gsoc/samples/notebook_closebtn.py	Mon May 26 23:50:51 2008
@@ -23,8 +23,8 @@
 style = ttk.Style()
 
 style.element_create("close", "image", "img_close",
-    (("active", "pressed", "!disabled"), "img_closepressed"),
-    (("active", "!disabled"), "img_closeactive"), border=8, sticky='')
+    ("active", "pressed", "!disabled", "img_closepressed"),
+    ("active", "!disabled", "img_closeactive"), border=8, sticky='')
 
 style.layout("ButtonNotebook", [("ButtonNotebook.client", {"sticky": "nswe"})])
 style.layout("ButtonNotebook.Tab", [

Modified: sandbox/trunk/ttk-gsoc/samples/roundframe.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/samples/roundframe.py	(original)
+++ sandbox/trunk/ttk-gsoc/samples/roundframe.py	Mon May 26 23:50:51 2008
@@ -91,7 +91,7 @@
 style = ttk.Style()
 
 style.element_create("RoundedFrame", "image", "frameBorder",
-    (("focus", ), "frameFocusBorder"), border=16, sticky="nsew")
+    ("focus", "frameFocusBorder"), border=16, sticky="nsew")
 
 style.layout("RoundedFrame", [("RoundedFrame", {"sticky": "nsew"})])
 style.configure("TEntry", borderwidth=0)

Modified: sandbox/trunk/ttk-gsoc/src/2.x/ttk.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/2.x/ttk.py	(original)
+++ sandbox/trunk/ttk-gsoc/src/2.x/ttk.py	Mon May 26 23:50:51 2008
@@ -62,10 +62,7 @@
         if ignore and opt in ignore:
             continue
 
-        # hasattr is used to guarantee that value is not an int, and isinstance
-        # guarantees it is not a string too
-        if hasattr(value, "__len__") and not isinstance(value, basestring):
-            # value is expected to be a sequence
+        if isinstance(value, (list, tuple)):
             value = format % ' '.join(map(str, value))
 
         if script and value == '':
@@ -93,16 +90,16 @@
 
         opt_val = []
         # each value in mapdict is expected to be a sequence, where each item
-        # is another sequence containing a state (or several) and a value for it
+        # is another sequence containing a state (or several) and a value
         for statespec in value:
             state, val = statespec[:-1], statespec[-1]
-            if not state:
-                # empty state denotes the "normal" state, format it to Tcl
-                state = "{}"
-            elif len(state) > 1: # group multiple states
+
+            if len(state) > 1: # group multiple states
                 state = "{%s}" % ' '.join(state)
-            else: # single state don't need any special formatting
-                state = state[0]
+            else: # single state
+                # if it is empty (something that evaluates to False), then
+                # format it to Tcl code to denote the "normal" state
+                state = state[0] or '{}'
 
             if not isinstance(val, basestring):
                 # val could be a list, tuple, etc which needs to be grouped
@@ -250,8 +247,7 @@
     opts = []
     opt_start = 1 if cut_minus else 0
 
-    for i in range(len(ttuple) / 2):
-        opt, val = ttuple[i * 2:i * 2 + 2]
+    for opt, val in zip(iter(ttuple[::2]), iter(ttuple[1::2])):
 
         if hasattr(val, 'find') and val.find(' ') != -1:
             # this could be the padding option ("left top right bottom")
@@ -269,7 +265,7 @@
     accepted statespec accepted by _format_mapdict."""
     split_it = lambda ob: getattr(ob, 'typename', None) == 'StateSpec'
     val = [str(val).split() if split_it(val) else val for val in stuple]
-    return [_flatten(val[i] + [val[i + 1]]) for i in range(0, len(val), 2)]
+    return [_flatten(spec) for spec in zip(iter(val[::2]), iter(val[1::2]))]
 
 def _list_from_layouttuple(ltuple):
     """Construct a list from the tuple returned by ttk::layout, this is
@@ -367,7 +363,7 @@
         or more states. If the default argument is set, it is used as
         a fallback value in case no specification for option is found."""
         state = ' '.join(state) if state else ''
-        option = '-' if not query_opt.startswith('-') else '' + option
+        option = '-' if not option.startswith('-') else '' + option
 
         return self.tk.call(self._name, "lookup", style, option, state, default)
 
@@ -584,7 +580,7 @@
     """Ttk Entry widget displays a one-line text string and allows that
     string to be edited by the user."""
 
-    def __init__(self, master=None, **kw):
+    def __init__(self, master=None, widget=None, **kw):
         """Constructs a Ttk Entry widget with the parent master.
 
         STANDARD OPTIONS
@@ -600,7 +596,7 @@
 
             none, key, focus, focusin, focusout, all
         """
-        Widget.__init__(self, master, "ttk::entry", kw)
+        Widget.__init__(self, master, widget or "ttk::entry", kw)
 
 
     def bbox(self, index):
@@ -622,7 +618,7 @@
         return self.tk.call(self._w, "validate")
 
 
-class Combobox(Widget, Entry):
+class Combobox(Entry):
     """Ttk Combobox widget combines a text field with a pop-down list of
     values."""
 
@@ -638,7 +634,7 @@
             exportselection, justify, height, postcommand, state,
             textvariable, values, width
         """
-        Widget.__init__(self, master, "ttk::combobox", kw)
+        Entry.__init__(self, master, "ttk::combobox", **kw)
 
 
     def current(self, newindex=None):

Modified: sandbox/trunk/ttk-gsoc/src/3.x/ttk.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/3.x/ttk.py	(original)
+++ sandbox/trunk/ttk-gsoc/src/3.x/ttk.py	Mon May 26 23:50:51 2008
@@ -62,10 +62,7 @@
         if ignore and opt in ignore:
             continue
 
-        # hasattr is used to guarantee that value is not an int, and isinstance
-        # guarantees it is not a string too
-        if hasattr(value, "__len__") and not isinstance(value, str):
-            # value is expected to be a sequence
+        if isinstance(value, (list, tuple)):
             value = format % ' '.join(map(str, value))
 
         if script and value == '':
@@ -93,16 +90,16 @@
 
         opt_val = []
         # each value in mapdict is expected to be a sequence, where each item
-        # is another sequence containing a state (or several) and a value for it
+        # is another sequence containing a state (or several) and a value
         for statespec in value:
             state, val = statespec[:-1], statespec[-1]
-            if not state:
-                # empty state denotes the "normal" state, format it to Tcl
-                state = "{}"
-            elif len(state) > 1: # group multiple states
+
+            if len(state) > 1: # group multiple states
                 state = "{%s}" % ' '.join(state)
-            else: # single state don't need any special formatting
-                state = state[0]
+            else: # single state
+                # if it is empty (something that evaluates to False), then
+                # format it to Tcl code to denote the "normal" state
+                state = state[0] or '{}'
 
             if not isinstance(val, str):
                 # val could be a list, tuple, etc which needs to be grouped
@@ -250,8 +247,7 @@
     opts = []
     opt_start = 1 if cut_minus else 0
 
-    for i in range(len(ttuple) // 2):
-        opt, val = ttuple[i * 2:i * 2 + 2]
+    for opt, val in zip(iter(ttuple[::2]), iter(ttuple[1::2])):
 
         if hasattr(val, 'find') and val.find(' ') != -1:
             # this could be the padding option ("left top right bottom")
@@ -269,7 +265,7 @@
     accepted statespec accepted by _format_mapdict."""
     split_it = lambda ob: getattr(ob, 'typename', None) == 'StateSpec'
     val = [str(val).split() if split_it(val) else val for val in stuple]
-    return [_flatten(val[i] + [val[i + 1]]) for i in range(0, len(val), 2)]
+    return [_flatten(spec) for spec in zip(iter(val[::2]), iter(val[1::2]))]
 
 def _list_from_layouttuple(ltuple):
     """Construct a list from the tuple returned by ttk::layout, this is
@@ -367,7 +363,7 @@
         or more states. If the default argument is set, it is used as
         a fallback value in case no specification for option is found."""
         state = ' '.join(state) if state else ''
-        option = '-' if not query_opt.startswith('-') else '' + option
+        option = '-' if not option.startswith('-') else '' + option
 
         return self.tk.call(self._name, "lookup", style, option, state, default)
 
@@ -584,7 +580,7 @@
     """Ttk Entry widget displays a one-line text string and allows that
     string to be edited by the user."""
 
-    def __init__(self, master=None, **kw):
+    def __init__(self, master=None, widget=None, **kw):
         """Constructs a Ttk Entry widget with the parent master.
 
         STANDARD OPTIONS
@@ -600,7 +596,7 @@
 
             none, key, focus, focusin, focusout, all
         """
-        Widget.__init__(self, master, "ttk::entry", kw)
+        Widget.__init__(self, master, widget or "ttk::entry", kw)
 
 
     def bbox(self, index):
@@ -622,7 +618,7 @@
         return self.tk.call(self._w, "validate")
 
 
-class Combobox(Widget, Entry):
+class Combobox(Entry):
     """Ttk Combobox widget combines a text field with a pop-down list of
     values."""
 
@@ -638,7 +634,7 @@
             exportselection, justify, height, postcommand, state,
             textvariable, values, width
         """
-        Widget.__init__(self, master, "ttk::combobox", kw)
+        Entry.__init__(self, master, "ttk::combobox", **kw)
 
 
     def current(self, newindex=None):


More information about the Python-checkins mailing list