[Python-checkins] r66068 - in sandbox/trunk/ttk-gsoc: Doc/library/ttk.rst src/2.x/test/test_base_widget.py src/2.x/test/test_treeview.py src/2.x/ttk.py src/3.x/test/test_base_widget.py src/3.x/test/test_treeview.py src/3.x/ttk.py

guilherme.polo python-checkins at python.org
Sat Aug 30 15:19:17 CEST 2008


Author: guilherme.polo
Date: Sat Aug 30 15:19:17 2008
New Revision: 66068

Log:
Updated instate signature and documentation in ttk.rst;
Updated ttk.py to ensure that either True/False is returned from Widget.instate;
Removed some identity checks in test_treeview;
Added a test for base widget methods (instate and state for now).


Added:
   sandbox/trunk/ttk-gsoc/src/2.x/test/test_base_widget.py
   sandbox/trunk/ttk-gsoc/src/3.x/test/test_base_widget.py
Modified:
   sandbox/trunk/ttk-gsoc/Doc/library/ttk.rst
   sandbox/trunk/ttk-gsoc/src/2.x/test/test_treeview.py
   sandbox/trunk/ttk-gsoc/src/2.x/ttk.py
   sandbox/trunk/ttk-gsoc/src/3.x/test/test_treeview.py
   sandbox/trunk/ttk-gsoc/src/3.x/ttk.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	Sat Aug 30 15:19:17 2008
@@ -259,10 +259,10 @@
       *x* and *y* are pixel coordinates relative to the widget.
 
 
-   .. method:: instate(statespec[, callback=None[, *args]])
+   .. method:: instate(statespec[, callback=None[, *args[, **kwargs]]])
 
-      Test the widget's state. If a callback is not specified, returns 1
-      if the widget state matches *statespec* and 0 otherwise. If callback
+      Test the widget's state. If a callback is not specified, returns True
+      if the widget state matches *statespec* and False otherwise. If callback
       is specified then it is called with args if widget state matches
       *statespec*.
 
@@ -1094,7 +1094,7 @@
    .. method:: tag_bind(tagname[, sequence=None[, callback=None]])
 
       Bind a callback for the given event *sequence* to the tag *tagname*.
-      When an event is delivered to an item, the *callback*s for each of the
+      When an event is delivered to an item, the *callbacks* for each of the
       item's tags option are called.
 
 

Added: sandbox/trunk/ttk-gsoc/src/2.x/test/test_base_widget.py
==============================================================================
--- (empty file)
+++ sandbox/trunk/ttk-gsoc/src/2.x/test/test_base_widget.py	Sat Aug 30 15:19:17 2008
@@ -0,0 +1,53 @@
+import sys
+import unittest
+import Tkinter
+import ttk
+
+import support
+
+class WidgetTest(unittest.TestCase):
+    """Tests methods available in every ttk widget."""
+
+    def setUp(self):
+        self.widget = ttk.Button()
+        self.widget.pack()
+        self.widget.wait_visibility()
+
+    def tearDown(self):
+        self.widget.destroy()
+
+
+    def test_widget_state(self):
+        # XXX not sure about the portability of all these tests
+        self.failUnlessEqual(self.widget.state(), ())
+        self.failUnlessEqual(self.widget.instate(['!disabled']), True)
+
+        # changing from !disabled to disabled
+        self.failUnlessEqual(self.widget.state(['disabled']), ('!disabled', ))
+        # no state change
+        self.failUnlessEqual(self.widget.state(['disabled']), ())
+        # change back to !disable but also active
+        self.failUnlessEqual(self.widget.state(['!disabled', 'active']),
+            ('!active', 'disabled'))
+        # no state changes, again
+        self.failUnlessEqual(self.widget.state(['!disabled', 'active']), ())
+        self.failUnlessEqual(self.widget.state(['active', '!disabled']), ())
+
+        def test_cb(arg1, **kw):
+            return arg1, kw
+        self.failUnlessEqual(self.widget.instate(['!disabled'],
+            test_cb, "hi", **{"msg": "there"}),
+            ('hi', {'msg': 'there'}))
+
+        # attempt to set invalid statespec
+        self.failUnlessRaises(Tkinter.TclError, self.widget.instate,
+            ['badstate'])
+        self.failUnlessRaises(Tkinter.TclError, self.widget.instate,
+            ['disabled', 'badstate'])
+
+
+def test_main():
+    support.run(WidgetTest)
+
+if __name__ == "__main__":
+    test_main()

Modified: sandbox/trunk/ttk-gsoc/src/2.x/test/test_treeview.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/2.x/test/test_treeview.py	(original)
+++ sandbox/trunk/ttk-gsoc/src/2.x/test/test_treeview.py	Sat Aug 30 15:19:17 2008
@@ -159,9 +159,9 @@
 
 
     def test_exists(self):
-        self.failUnless(self.tv.exists('something') is False)
-        self.failUnless(self.tv.exists('') is True)
-        self.failUnless(self.tv.exists({}) is False)
+        self.failUnlessEqual(self.tv.exists('something'), False)
+        self.failUnlessEqual(self.tv.exists(''), True)
+        self.failUnlessEqual(self.tv.exists({}), False)
 
         # the following will make a tk.call equivalent to
         # tk.call(treeview, "exists") which should result in an error

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	Sat Aug 30 15:19:17 2008
@@ -12,7 +12,7 @@
 of the widgets appearance lies at Themes.
 """
 
-__version__ = "0.2"
+__version__ = "0.2.1"
 
 __author__ = "Guilherme Polo <ggpolo at gmail.com>"
 
@@ -552,15 +552,15 @@
     def instate(self, statespec, callback=None, *args, **kw):
         """Test the widget's state.
 
-        If callback is not specified, returns 1 if the widget state
-        matches statespec and 0 otherwise. If callback is specified,
+        If callback is not specified, returns True if the widget state
+        matches statespec and False otherwise. If callback is specified,
         then it will be invoked with *args, **kw if the widget state
         matches statespec. statespec is expected to be a sequence."""
         ret = self.tk.call(self._w, "instate", ' '.join(statespec))
         if ret and callback:
             return callback(*args, **kw)
 
-        return ret
+        return bool(ret)
 
 
     def state(self, statespec=None):

Added: sandbox/trunk/ttk-gsoc/src/3.x/test/test_base_widget.py
==============================================================================
--- (empty file)
+++ sandbox/trunk/ttk-gsoc/src/3.x/test/test_base_widget.py	Sat Aug 30 15:19:17 2008
@@ -0,0 +1,53 @@
+import sys
+import unittest
+import tkinter
+import ttk
+
+import support
+
+class WidgetTest(unittest.TestCase):
+    """Tests methods available in every ttk widget."""
+
+    def setUp(self):
+        self.widget = ttk.Button()
+        self.widget.pack()
+        self.widget.wait_visibility()
+
+    def tearDown(self):
+        self.widget.destroy()
+
+
+    def test_widget_state(self):
+        # XXX not sure about the portability of all these tests
+        self.failUnlessEqual(self.widget.state(), ())
+        self.failUnlessEqual(self.widget.instate(['!disabled']), True)
+
+        # changing from !disabled to disabled
+        self.failUnlessEqual(self.widget.state(['disabled']), ('!disabled', ))
+        # no state change
+        self.failUnlessEqual(self.widget.state(['disabled']), ())
+        # change back to !disable but also active
+        self.failUnlessEqual(self.widget.state(['!disabled', 'active']),
+            ('!active', 'disabled'))
+        # no state changes, again
+        self.failUnlessEqual(self.widget.state(['!disabled', 'active']), ())
+        self.failUnlessEqual(self.widget.state(['active', '!disabled']), ())
+
+        def test_cb(arg1, **kw):
+            return arg1, kw
+        self.failUnlessEqual(self.widget.instate(['!disabled'],
+            test_cb, "hi", **{"msg": "there"}),
+            ('hi', {'msg': 'there'}))
+
+        # attempt to set invalid statespec
+        self.failUnlessRaises(tkinter.TclError, self.widget.instate,
+            ['badstate'])
+        self.failUnlessRaises(tkinter.TclError, self.widget.instate,
+            ['disabled', 'badstate'])
+
+
+def test_main():
+    support.run(WidgetTest)
+
+if __name__ == "__main__":
+    test_main()

Modified: sandbox/trunk/ttk-gsoc/src/3.x/test/test_treeview.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/3.x/test/test_treeview.py	(original)
+++ sandbox/trunk/ttk-gsoc/src/3.x/test/test_treeview.py	Sat Aug 30 15:19:17 2008
@@ -159,9 +159,9 @@
 
 
     def test_exists(self):
-        self.failUnless(self.tv.exists('something') is False)
-        self.failUnless(self.tv.exists('') is True)
-        self.failUnless(self.tv.exists({}) is False)
+        self.failUnlessEqual(self.tv.exists('something'), False)
+        self.failUnlessEqual(self.tv.exists(''), True)
+        self.failUnlessEqual(self.tv.exists({}), False)
 
         # the following will make a tk.call equivalent to
         # tk.call(treeview, "exists") which should result in an error

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	Sat Aug 30 15:19:17 2008
@@ -12,7 +12,7 @@
 of the widgets appearance lies at Themes.
 """
 
-__version__ = "0.2"
+__version__ = "0.2.1"
 
 __author__ = "Guilherme Polo <ggpolo at gmail.com>"
 
@@ -552,15 +552,15 @@
     def instate(self, statespec, callback=None, *args, **kw):
         """Test the widget's state.
 
-        If callback is not specified, returns 1 if the widget state
-        matches statespec and 0 otherwise. If callback is specified,
+        If callback is not specified, returns True if the widget state
+        matches statespec and False otherwise. If callback is specified,
         then it will be invoked with *args, **kw if the widget state
         matches statespec. statespec is expected to be a sequence."""
         ret = self.tk.call(self._w, "instate", ' '.join(statespec))
         if ret and callback:
             return callback(*args, **kw)
 
-        return ret
+        return bool(ret)
 
 
     def state(self, statespec=None):


More information about the Python-checkins mailing list