diff options
-rw-r--r-- | gi/overrides/Gtk.py | 15 | ||||
-rw-r--r-- | tests/test_overrides_gtk.py | 26 |
2 files changed, 41 insertions, 0 deletions
diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py index 23d06adf..612c07da 100644 --- a/gi/overrides/Gtk.py +++ b/gi/overrides/Gtk.py @@ -118,10 +118,25 @@ def _builder_connect_callback(builder, gobj, signal_name, handler_name, connect_ gobj.connect(signal_name, handler, *args) +class _FreezeNotifyManager(object): + def __init__(self, obj): + self.obj = obj + + def __enter__(self): + pass + + def __exit__(self, exc_type, exc_value, traceback): + self.obj.thaw_child_notify() + + class Widget(Gtk.Widget): translate_coordinates = strip_boolean_result(Gtk.Widget.translate_coordinates) + def freeze_child_notify(self): + super(Widget, self).freeze_child_notify() + return _FreezeNotifyManager(self) + def drag_dest_set_target_list(self, target_list): if (target_list is not None) and (not isinstance(target_list, Gtk.TargetList)): target_list = Gtk.TargetList.new(_construct_target_list(target_list)) diff --git a/tests/test_overrides_gtk.py b/tests/test_overrides_gtk.py index 7ffb5068..1e365525 100644 --- a/tests/test_overrides_gtk.py +++ b/tests/test_overrides_gtk.py @@ -70,6 +70,32 @@ def realized(widget): @unittest.skipUnless(Gtk, 'Gtk not available') +def test_freeze_child_notif(): + + events = [] + + def on_notify(widget, spec): + events.append(spec.name) + + b = Gtk.Box() + c = Gtk.Button() + c.connect("child-notify", on_notify) + c.freeze_child_notify() + b.pack_start(c, True, True, 0) + b.child_set_property(c, "expand", False) + b.child_set_property(c, "expand", True) + c.thaw_child_notify() + assert events.count("expand") == 1 + del events[:] + + with c.freeze_child_notify(): + b.child_set_property(c, "expand", True) + b.child_set_property(c, "expand", False) + + assert events.count("expand") == 1 + + +@unittest.skipUnless(Gtk, 'Gtk not available') def test_wrapper_toggle_refs(): class MyButton(Gtk.Button): def __init__(self, height): |