[Python-checkins] r66221 - in sandbox/trunk/ttk-gsoc/src: 2.x/test/test_functions.py 2.x/ttk.py 3.x/test/test_functions.py 3.x/ttk.py
guilherme.polo
python-checkins at python.org
Thu Sep 4 18:46:22 CEST 2008
Author: guilherme.polo
Date: Thu Sep 4 18:46:22 2008
New Revision: 66221
Log:
Fixed issue 4: http://code.google.com/p/python-ttk/issues/detail?id=4
The special code at Treeview.insert has been moved to _format_optdict, test
added.
Modified:
sandbox/trunk/ttk-gsoc/src/2.x/test/test_functions.py
sandbox/trunk/ttk-gsoc/src/2.x/ttk.py
sandbox/trunk/ttk-gsoc/src/3.x/test/test_functions.py
sandbox/trunk/ttk-gsoc/src/3.x/ttk.py
Modified: sandbox/trunk/ttk-gsoc/src/2.x/test/test_functions.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/2.x/test/test_functions.py (original)
+++ sandbox/trunk/ttk-gsoc/src/2.x/test/test_functions.py Thu Sep 4 18:46:22 2008
@@ -66,6 +66,12 @@
# opts should remain unchanged
self.failUnlessEqual(opts, orig_opts)
+ # passing values with spaces inside a tuple/list
+ check_against(
+ ttk._format_optdict(
+ {'option': ('one two', 'three')}),
+ {'-option': '{one two} three'})
+
# ignore an option
amount_opts = len(ttk._format_optdict(opts, ignore=(u'á'))) / 2
self.failUnlessEqual(amount_opts, len(opts) - 1)
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 Thu Sep 4 18:46:22 2008
@@ -12,7 +12,7 @@
of the widgets appearance lies at Themes.
"""
-__version__ = "0.2.5"
+__version__ = "0.2.6"
__author__ = "Guilherme Polo <ggpolo at gmail.com>"
@@ -73,7 +73,11 @@
v.append(unicode(val) if val else '{}')
else:
v.append(str(val))
- value = format % ' '.join(v)
+
+ # format v according to the script option, but also check for
+ # space in any value in v in order to group them correctly
+ value = format % ' '.join(
+ ('{%s}' if ' ' in val else '%s') % val for val in v)
if script and value == '':
value = '{}' # empty string in Python is equivalent to {} in Tcl
@@ -1324,12 +1328,7 @@
is specified, it is used as the item identifier, iid must not
already exist in the tree. Otherwise, a new unique identifier
is generated."""
- opts, values = _format_optdict(kw, ignore='values'), kw.get('values')
- # values may need special formatting if any value contains a space
- if values:
- values = map(unicode, values)
- opts += ("-values",
- ' '.join(('{%s}' if ' ' in v else '%s') % v for v in values))
+ opts = _format_optdict(kw)
if iid:
res = self.tk.call(self._w, "insert", parent, index, "-id", iid,
*opts)
Modified: sandbox/trunk/ttk-gsoc/src/3.x/test/test_functions.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/3.x/test/test_functions.py (original)
+++ sandbox/trunk/ttk-gsoc/src/3.x/test/test_functions.py Thu Sep 4 18:46:22 2008
@@ -66,6 +66,12 @@
# opts should remain unchanged
self.failUnlessEqual(opts, orig_opts)
+ # passing values with spaces inside a tuple/list
+ check_against(
+ ttk._format_optdict(
+ {'option': ('one two', 'three')}),
+ {'-option': '{one two} three'})
+
# ignore an option
amount_opts = len(ttk._format_optdict(opts, ignore=('á'))) / 2
self.failUnlessEqual(amount_opts, len(opts) - 1)
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 Thu Sep 4 18:46:22 2008
@@ -12,7 +12,7 @@
of the widgets appearance lies at Themes.
"""
-__version__ = "0.2.5"
+__version__ = "0.2.6"
__author__ = "Guilherme Polo <ggpolo at gmail.com>"
@@ -73,7 +73,11 @@
v.append(str(val) if val else '{}')
else:
v.append(str(val))
- value = format % ' '.join(v)
+
+ # format v according to the script option, but also check for
+ # space in any value in v in order to group them correctly
+ value = format % ' '.join(
+ ('{%s}' if ' ' in val else '%s') % val for val in v)
if script and value == '':
value = '{}' # empty string in Python is equivalent to {} in Tcl
@@ -1324,12 +1328,7 @@
is specified, it is used as the item identifier, iid must not
already exist in the tree. Otherwise, a new unique identifier
is generated."""
- opts, values = _format_optdict(kw, ignore='values'), kw.get('values')
- # values may need special formatting if any value contains a space
- if values:
- values = map(str, values)
- opts += ("-values",
- ' '.join(('{%s}' if ' ' in v else '%s') % v for v in values))
+ opts = _format_optdict(kw)
if iid:
res = self.tk.call(self._w, "insert", parent, index, "-id", iid,
*opts)
More information about the Python-checkins
mailing list