[Python-checkins] r62607 - in sandbox/trunk/ttk-gsoc: Doc/library/ttk.rst Lib/lib-tk/Ttk.py samples/widget_state.py
guilherme.polo
python-checkins at python.org
Wed Apr 30 23:28:25 CEST 2008
Author: guilherme.polo
Date: Wed Apr 30 23:28:25 2008
New Revision: 62607
Log:
Modified Widget methods state and instate so they expect statespec
to be a sequence, and method state returns a tuple now.
Modified:
sandbox/trunk/ttk-gsoc/Doc/library/ttk.rst
sandbox/trunk/ttk-gsoc/Lib/lib-tk/Ttk.py
sandbox/trunk/ttk-gsoc/samples/widget_state.py
Modified: sandbox/trunk/ttk-gsoc/Doc/library/ttk.rst
==============================================================================
--- sandbox/trunk/ttk-gsoc/Doc/library/ttk.rst (original)
+++ sandbox/trunk/ttk-gsoc/Doc/library/ttk.rst Wed Apr 30 23:28:25 2008
@@ -115,18 +115,19 @@
.. method:: instate(statespec[, callback=None], *args]])
Test the widget's state. If a callback is not specified, returns 1
- if the widget state matches statespec and 0 otherwise. If callback
+ if the widget state matches *statespec* and 0 otherwise. If callback
is specified then it is called with args if widget state matches
- statespec.
+ *statespec*.
.. method:: state([statespec=None])
- Modify or inquire widget state. If statespec is specified, sets the
- widget state according to it and return a new statespec indicating
- which flags were changed. If statespec is not especified, returns
- a list of the currently-enabled state flags.
+ Modify or inquire widget state. If *statespec* is specified, sets the
+ widget state according to it and return a new *statespec* indicating
+ which flags were changed. If *statespec* is not especified, returns
+ the currently-enabled state flags.
+ Note that *statespec* is always expected to be a sequence.
Widget States
^^^^^^^^^^^^^
@@ -160,8 +161,8 @@
| invalid | The widget's value is invalid |
+------------+-------------------------------------------------------------+
- A state specification is a list of state names, optionally prefixed with an
- exclamation point indicating that the bit is off.
+ A state specification is a sequence of state names, optionally prefixed with
+ an exclamation point indicating that the bit is off.
New Widgets
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 Wed Apr 30 23:28:25 2008
@@ -197,17 +197,14 @@
Tkinter.Widget.__init__(self, master, widgetName, cnf, kw, extra)
- # XXX statespec is said to be a list of state names, but right now both
- # functions expects and returns (state method) a string with the states.
-
def instate(self, statespec, callback=None, *args):
"""Test the widget's state.
If callback is not especified, returns 1 if the widget state
matches statespec and 0 otherwise. If callback is specified,
then it will be invoked with *args if the widget state matches
- statespec."""
- ret = self.tk.call(self._w, "instate", statespec)
+ statespec. statespec is expected to be a sequence."""
+ ret = self.tk.call(self._w, "instate", ' '.join(statespec))
if ret and callback:
return callback(*args)
@@ -219,8 +216,13 @@
Widget state is returned if statespec is None, otherwise it is
set according to the statespec flags and then a new state spec
- is returned indicating which flags were changed."""
- return self.tk.call(self._w, "state", statespec)
+ is returned indicating which flags were changed. statespec is
+ expected to be a sequence."""
+ if statespec is None:
+ statespec = ''
+
+ return self.tk.splitlist(
+ str(self.tk.call(self._w, "state", ' '.join(statespec))))
class Button(Widget):
@@ -239,7 +241,6 @@
command, default, width
"""
-
Widget.__init__(self, master, "ttk::button", cnf, kw)
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 Wed Apr 30 23:28:25 2008
@@ -8,7 +8,7 @@
states.append("!" + state)
def reset_state(widget):
- nostate = ' '.join(states[len(states) / 2:])
+ nostate = states[len(states) / 2:]
widget.state(nostate)
class App(Ttk.Frame):
@@ -54,7 +54,7 @@
# set new widget state
for widget in self.update_widgets:
reset_state(widget) # remove any previous state from the widget
- widget.state(' '.join(goodstates))
+ widget.state(goodstates)
# update Ttk Button font size
self._set_font(font_extra)
More information about the Python-checkins
mailing list