[Python-checkins] r63509 - in sandbox/trunk/ttk-gsoc: samples/mac_searchentry.py samples/roundframe.py samples/widget_state.py src/2.x/ttk.py src/3.x/ttk.py
guilherme.polo
python-checkins at python.org
Tue May 20 19:40:12 CEST 2008
Author: guilherme.polo
Date: Tue May 20 19:40:11 2008
New Revision: 63509
Log:
Some janitor work.
Modified:
sandbox/trunk/ttk-gsoc/samples/mac_searchentry.py
sandbox/trunk/ttk-gsoc/samples/roundframe.py
sandbox/trunk/ttk-gsoc/samples/widget_state.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 Tue May 20 19:40:11 2008
@@ -57,8 +57,8 @@
style = ttk.Style()
-style.element_create("Search.field", "image", "search1", ("focus", "search2"),
- border=[22, 7, 14], sticky="ew")
+style.element_create("Search.field", "image", "search1",
+ (("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/roundframe.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/samples/roundframe.py (original)
+++ sandbox/trunk/ttk-gsoc/samples/roundframe.py Tue May 20 19:40:11 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/samples/widget_state.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/samples/widget_state.py (original)
+++ sandbox/trunk/ttk-gsoc/samples/widget_state.py Tue May 20 19:40:11 2008
@@ -4,8 +4,8 @@
import ttk
PY3K = True if sys.version_info[0] > 2 else False
-states = ['active', 'disabled', 'focus', 'pressed', 'selected',
- 'background', 'readonly', 'alternate', 'invalid']
+states = ['active', 'disabled', 'focus', 'pressed', 'selected',
+ 'background', 'readonly', 'alternate', 'invalid']
for state in states[:]:
states.append("!" + state)
@@ -32,12 +32,12 @@
self.base_fsize = int(fsize[1 if fsize[0] == '-' else 0:])
# a list to hold all the widgets that will have their states changed
- self.update_widgets = []
+ self.update_widgets = []
self._setup_widgets()
def _set_font(self, extra=0):
- self.style.configure("TButton", font="%s %s%d" % (self.font_family,
+ self.style.configure("TButton", font="%s %s%d" % (self.font_family,
self.fsize_prefix, self.base_fsize + extra))
def _new_state(self, widget, newtext):
@@ -46,7 +46,7 @@
if not newtext:
goodstates = ["disabled"]
font_extra = 0
- else:
+ else:
# set widget state according to what has been entered in the entry
newstates = set(newtext.split()) # eliminate duplicates
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 Tue May 20 19:40:11 2008
@@ -68,7 +68,7 @@
# value is expected to be a sequence
value = format % ' '.join(map(str, value))
- if script and isinstance(value, basestring) and not value:
+ if script and value == '':
value = '{}' # empty string in Python is equivalent to {} in Tcl
opts.append(("-%s" % opt, value))
@@ -229,9 +229,7 @@
argc += 1
elemargs = eopts[1:argc]
- elemkw = {}
- if argc < len(eopts) and eopts[argc]:
- elemkw = eopts[argc]
+ elemkw = eopts[argc] if argc < len(eopts) and eopts[argc] else {}
spec, opts = _format_elemcreate(etype, True, *elemargs, **elemkw)
script.append("ttk::style element create %s %s %s %s" % (
@@ -239,44 +237,45 @@
return '\n'.join(script)
-def _dict_from_tcltuple(t, cut_minus=True):
+def _dict_from_tcltuple(ttuple, cut_minus=True):
"""Break tuple in pairs, format it properly, then build the return
- dict.
+ dict. If cut_minus is True, the supposed '-' prefixing options will
+ be removed.
- t is expected to contain an even number of elements."""
+ ttuple is expected to contain an even number of elements."""
opts = []
- for i in range(len(t) / 2):
- opt, val = t[i * 2:i * 2 + 2]
- if isinstance(val, basestring):
- if val.find(' ') != -1: # could be the padding option
- val = map(int, val.split())
-
- elif hasattr(val, "__len__") and hasattr(val[0], "typename"):
- val = list(val)
- for x in range(len(val)):
- if getattr(val[x], 'typename', None) == 'StateSpec':
- val[x] = str(val[x]).split()
+ opt_start = 1 if cut_minus else 0
- opts.append((str(opt), val))
+ for i in range(len(ttuple) / 2):
+ opt, val = ttuple[i * 2:i * 2 + 2]
- # the supposed '-' prefixing options will be removed if cut_minus is True.
- return dict((opt[1 if cut_minus else 0:], val) for opt, val in opts)
+ if hasattr(val, "find") and val.find(' ') != - 1:
+ # this could be the padding option
+ val = map(int, val.split())
-def _list_from_layouttuple(t):
+ elif val and hasattr(val, "__len__") and hasattr(val[0], "typename"):
+ split_it = lambda ob: getattr(ob, 'typename', None) == 'StateSpec'
+ val = [str(v).split() if split_it(v) else v for v in val]
+
+ opts.append((str(opt)[opt_start:], val))
+
+ return dict(opts)
+
+def _list_from_layouttuple(ltuple):
"""Construct a list from the tuple returned by ttk::layout, this is
somewhat the reverse of _format_layoutlist."""
res = []
- indx = 0
- while indx < len(t):
- name = t[indx]
+ indx = 0
+ while indx < len(ltuple):
+ name = ltuple[indx]
opts = {}
res.append((name, opts))
indx += 1
# grab name's options
- while indx < len(t):
- opt, val = t[indx:indx + 2]
+ while indx < len(ltuple):
+ opt, val = ltuple[indx:indx + 2]
if not opt.startswith('-'): # found next name
break
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 Tue May 20 19:40:11 2008
@@ -68,7 +68,7 @@
# value is expected to be a sequence
value = format % ' '.join(map(str, value))
- if script and isinstance(value, str) and not value:
+ if script and value == '':
value = '{}' # empty string in Python is equivalent to {} in Tcl
opts.append(("-%s" % opt, value))
@@ -229,9 +229,7 @@
argc += 1
elemargs = eopts[1:argc]
- elemkw = {}
- if argc < len(eopts) and eopts[argc]:
- elemkw = eopts[argc]
+ elemkw = eopts[argc] if argc < len(eopts) and eopts[argc] else {}
spec, opts = _format_elemcreate(etype, True, *elemargs, **elemkw)
script.append("ttk::style element create %s %s %s %s" % (
@@ -239,44 +237,45 @@
return '\n'.join(script)
-def _dict_from_tcltuple(t, cut_minus=True):
+def _dict_from_tcltuple(ttuple, cut_minus=True):
"""Break tuple in pairs, format it properly, then build the return
- dict.
+ dict. If cut_minus is True, the supposed '-' prefixing options will
+ be removed.
- t is expected to contain an even number of elements."""
+ ttuple is expected to contain an even number of elements."""
opts = []
- for i in range(len(t) // 2):
- opt, val = t[i * 2:i * 2 + 2]
- if isinstance(val, str):
- if val.find(' ') != -1: # could be the padding option
- val = list(map(int, val.split()))
-
- elif hasattr(val, "__len__") and hasattr(val[0], "typename"):
- val = list(val)
- for x in range(len(val)):
- if getattr(val[x], 'typename', None) == 'StateSpec':
- val[x] = str(val[x]).split()
+ opt_start = 1 if cut_minus else 0
- opts.append((str(opt), val))
+ for i in range(len(ttuple) // 2):
+ opt, val = ttuple[i * 2:i * 2 + 2]
- # the supposed '-' prefixing options will be removed if cut_minus is True.
- return dict((opt[1 if cut_minus else 0:], val) for opt, val in opts)
+ if hasattr(val, "find") and val.find(' ') != - 1:
+ # this could be the padding option
+ val = list(map(int, val.split()))
-def _list_from_layouttuple(t):
+ elif val and hasattr(val, "__len__") and hasattr(val[0], "typename"):
+ split_it = lambda ob: getattr(ob, 'typename', None) == 'StateSpec'
+ val = [str(v).split() if split_it(v) else v for v in val]
+
+ opts.append((str(opt)[opt_start:], val))
+
+ return dict(opts)
+
+def _list_from_layouttuple(ltuple):
"""Construct a list from the tuple returned by ttk::layout, this is
somewhat the reverse of _format_layoutlist."""
res = []
- indx = 0
- while indx < len(t):
- name = t[indx]
+ indx = 0
+ while indx < len(ltuple):
+ name = ltuple[indx]
opts = {}
res.append((name, opts))
indx += 1
# grab name's options
- while indx < len(t):
- opt, val = t[indx:indx + 2]
+ while indx < len(ltuple):
+ opt, val = ltuple[indx:indx + 2]
if not opt.startswith('-'): # found next name
break
More information about the Python-checkins
mailing list