Commits

Ali Afshar committed 8306815

Found an ugly bug in proxy while writing docs, fixed, added test case.

Comments (0)

Files changed (5)

 pygtkhelpers API Documentation
 ==============================
 
-.. automodule:: pygtkhelpers.delegates
-    :members:
+.. toctree::
+    :maxdepth: 2
 
-.. automodule:: pygtkhelpers.gthreads
-    :members:
+    api_delegates
+    api_proxy
+    api_utils
+    api_gthreads
+    api_objectlist
+    api_widgets
+    api_dialogs
+    api_test
+    api_debut
 
-.. automodule:: pygtkhelpers.proxy
-    :members:
 
-.. automodule:: pygtkhelpers.ui
-    :members:
 
-.. automodule:: pygtkhelpers.ui.objectlist
-    :members:
-    :inherited-members:
 
-.. automodule:: pygtkhelpers.ui.dialogs
-    :members:
-
-.. automodule:: pygtkhelpers.ui.widgets
-    :members:
-
-.. automodule:: pygtkhelpers.utils
-    :members:
-
-.. automodule:: pygtkhelpers.test
-    :members:
-
-.. automodule:: pygtkhelpers.debug.dialogs
-    :members:
-
 
 # General information about the project.
 project = u'pygtkhelpers'
-copyright = u'2010, pygtkherlpers Authors'
+copyright = u'2009-2010, pygtkhelpers Authors'
 
 # The version info for the project you're documenting, acts as replacement for
 # |version| and |release|, also used in various other places throughout the
 # built documents.
 #
 # The short X.Y version.
-version = '0.3'
+version = '0.4'
 # The full version, including alpha/beta/rc tags.
-release = '0.3'
+release = '0.4'
 
 # The language for content autogenerated by Sphinx. Refer to documentation
 # for a list of supported languages.
 
 # The theme to use for HTML and HTML Help pages.  Major themes that come with
 # Sphinx are currently 'default' and 'sphinxdoc'.
-html_theme = 'sphinxdoc'
+#html_theme = 'sphinxdoc'
+html_theme = 'default'
 
 # Theme options are theme-specific and customize the look and feel of a theme
 # further.  For a list of options available for each theme, see the

pygtkhelpers/proxy.py

         gobject.GObject.__init__(self)
         self.widget = widget
         self.connections = []
+        self.connect_widget()
 
     # public API
 
         """
         if self.signal_name is not None:
             # None for read only widgets
-            self.widget.connect(self.signal_name, self.widget_changed)
+            sid = self.widget.connect(self.signal_name, self.widget_changed)
+            self.connections.append(sid)
+
 
 
 class SinglePropertyGObjectProxy(GObjectProxy):
         return self.widget.get_property(self.prop_name)
 
 
-class SingleDelegatedPropertyGObjectProxy(GObjectProxy):
+class SingleDelegatedPropertyGObjectProxy(SinglePropertyGObjectProxy):
     """Proxy which uses a delegated property on its widget.
     """
     prop_name = None
     dprop_name = None
-    signal_name = None
 
-    def set_widget_value(self, value):
-        return self.widget.get_property(self.dprop_name
-            ).set_property(self.prop_name, value)
-
-    def get_widget_value(self):
-        return self.widget.get_property(self.dprop_name
-            ).get_property(self.prop_name)
-
-    def connect_widget(self):
-        if self.signal_name is not None:
-            # None for read only widgets
-            self.widget.get_property(self.dprop_name
-                ).connect(self.signal_name, self.widget_changed)
+    def __init__(self, widget, *args, **kw):
+        self.owidget = widget
+        widget = widget.get_property(self.dprop_name)
+        GObjectProxy.__init__(self, widget, *args, **kw)
 
 
 class GtkEntryProxy(SinglePropertyGObjectProxy):
             if self.get_row_value(row) == value:
                 self.widget.set_active(i)
 
-    def connect_widget(self):
-        self.widget.connect('changed', self.widget_changed)
-
     @property
     def active_row(self):
         if self.widget.get_active() == -1:

pygtkhelpers/test.py

 
 class CheckCalled(object):
     """Utility to check whether a signal has been emitted
+
+    :param object: The Object that will fire the signal
+    :param signal: The signal name
+
+    This class should be used when testing whether a signal has been called.
+    It could be used in conjuntion with :func:`pygtkhelpers.utils.refresh_gui`
+    in order to block the UI adequately to check::
+
+        >>> import gtk
+        >>> from pygtkhelpers.utils import refresh_gui
+        >>> b = gtk.Button()
+        >>> check = CheckCalled(b, 'clicked')
+        >>> b.clicked()
+        >>> assert check.called
+        >>> assert check.called_count = 1
+        >>> b.click()
+        >>> assert check.called_count = 2
+
     """
     def __init__(self, object, signal):
         self.called = None
         object.connect(signal, self)
 
     def __call__(self, *k):
-        print 'call'
         self.called = k
         self.called_count += 1
 

tests/test_proxy.py

     print data
     assert len(data)==0
 
+def test_widget_externally_changed_emits():
+    data = []
+    w = gtk.Entry()
+    proxy = widget_proxies[gtk.Entry](w)
+    w.connect('changed', lambda p: data.append(p))
+    w.set_text('hello')
+    assert len(data)==1