def get_handler_id_for_signal(widget, signal): signal_id, detail = GObject.signal_parse_name(signal, widget, True) handler_id = GObject.signal_handler_find(widget, GObject.SignalMatchType.ID, signal_id, detail, None, None, None) return handler_id
def test_signal_handler_find(self): def foo(obj): obj.status += 1 obj = self.Object() handler_id = GObject.signal_connect_closure(obj, 'my-signal', foo, after=False) signal_id, detail = GObject.signal_parse_name('my-signal', obj, True) found_id = GObject.signal_handler_find(obj, GObject.SignalMatchType.ID, signal_id=signal_id, detail=detail, closure=None, func=0, data=0) self.assertEqual(handler_id, found_id)
def gobject_signal_blocked(gobject, signal_name): """ This is a context manager that can be used with the 'with' statement to execute a block of code while *signal_name* is blocked. :param gobject: The object to block the signal on. :type gobject: :py:class:`GObject.Object` :param str signal_name: The name of the signal to block. """ signal_id = GObject.signal_lookup(signal_name, gobject.__class__) handler_id = GObject.signal_handler_find(gobject, GObject.SignalMatchType.ID, signal_id, 0, None, 0, 0) GObject.signal_handler_block(gobject, handler_id) yield GObject.signal_handler_unblock(gobject, handler_id)
def gobject_signal_blocked(gobject, signal_name): """ This is a context manager that can be used with the 'with' statement to execute a block of code while *signal_name* is blocked. :param gobject: The object to block the signal on. :type gobject: :py:class:`GObject.Object` :param str signal_name: The name of the signal to block. """ signal_id = GObject.signal_lookup(signal_name, gobject.__class__) handler_id = GObject.signal_handler_find(gobject, GObject.SignalMatchType.ID, signal_id, 0, None, 0, 0) GObject.signal_handler_block(gobject, handler_id) yield GObject.signal_handler_unblock(gobject, handler_id)
def onFocusIn( self, *args ): def dummy( *args ): pass signalId = GObject.signal_lookup( "focus-out-event", self.window ) while True: result = GObject.signal_handler_find( self.window, GObject.SignalMatchType.ID | GObject.SignalMatchType.UNBLOCKED, signalId, 0, None, dummy, dummy ) if result == 0: self.window.handler_unblock( self.loseFocusId ) else: break return False
def onInsertText(self, oWidget, strText, nLength, nPosition): strText = ''.join([s for s in strText if s not in '/\\']) nId, nDetail = GObject.signal_parse_name('insert-text', oWidget, True) if strText: nHandler = GObject.signal_handler_find(oWidget, GObject.SignalMatchType.ID, nId, nDetail, None, 0, 0) nPosition = oWidget.get_position() GObject.signal_handler_block(oWidget, nHandler) oWidget.insert_text(strText, nPosition) GObject.signal_handler_unblock(oWidget, nHandler) GObject.idle_add(oWidget.set_position, nPosition + len(strText)) GObject.signal_stop_emission(oWidget, nId, nDetail)
def test_signal_handler_find(self): def foo(obj): obj.status += 1 obj = self.Object() handler_id = GObject.signal_connect_closure(obj, 'my-signal', foo, after=False) signal_id, detail = GObject.signal_parse_name('my-signal', obj, True) found_id = GObject.signal_handler_find(obj, GObject.SignalMatchType.ID, signal_id=signal_id, detail=detail, closure=None, func=0, data=0) self.assertEqual(handler_id, found_id)
def resize_paned(paned, rect, relpos): """ Resize `~paned` to have its handle at `~relpos`, then disconnect this signal handler. Called from the :func:`Gtk.Widget.signals.size_allocate` signal. Args: paned (:class:`~Gtk.Paned`): Panel whose size has just been allocated, and whose handle needs initial placement. rect (:class:`~Gdk.Rectangle`): The rectangle specifying the size that has just been allocated to `~paned` relpos (`float`): A number between `0.` and `1.` that specifies the handle position Returns: `True` """ size = rect.width if paned.get_orientation( ) == Gtk.Orientation.HORIZONTAL else rect.height handle_pos = int(round(relpos * size)) GLib.idle_add(paned.set_position, handle_pos) sig = GObject.signal_lookup('size-allocate', Gtk.Paned) hnd = GObject.signal_handler_find(paned, GObject.SignalMatchType.ID, sig, 0, None, None, None) GObject.signal_handler_disconnect(paned, hnd) return True
def gobject_signal_blocked(gobject, signal_name): signal_id = GObject.signal_lookup(signal_name, gobject.__class__) handler_id = GObject.signal_handler_find(gobject, GObject.SignalMatchType.ID, signal_id, 0, None, 0, 0) GObject.signal_handler_block(gobject, handler_id) yield GObject.signal_handler_unblock(gobject, handler_id)
def disconnect_signal(source, signal): signal_id = GObject.signal_lookup(signal, source.__class__) handler_id = GObject.signal_handler_find(source, GObject.SignalMatchType.ID, signal_id, 0, None, 0, 0) source.disconnect(handler_id)