Ejemplo n.º 1
0
def disconnect(signal: pyqtSignal, callback: Callable):
    """
    After using ``connect()`` to link a signal, use this function to disconnect from the given signal.

    This function will also work if the ``callback`` was connected directly with ``signal.connect()``.

    :param signal: the signal to ``disconnect()`` from.
    :param callback: the callback to connect (will be called after ``signal.emit(...)``.
    """
    if hasattr(callback, 'tb_wrapper'):
        disconnectable = callback.tb_wrapper
    elif hasattr(callback, "__self__") and hasattr(callback, "__func__"):
        disconnectable = callback.__self__.tb_mapping[callback.__func__.__name__]
    else:
        disconnectable = callback
    signal.disconnect(disconnectable)
Ejemplo n.º 2
0
def is_connected(signal: pyqtSignal, slot: pyqtSlot) -> bool:
    """
    Determine if a (bound) signal is connected to a slot.
    :param signal: signal (a return value from a call to pyqtSignal(...))
    :param slot: slot (a method on a QObject, decorated with pyqtSlot)
    :return: True if connected, False otherwise
    """
    try:
        signal.connect(slot, Qt.UniqueConnection)

    except TypeError as exc:
        assert str(exc) in (
            'connection is not unique',
            'connect() failed between MyObj.sig_test[] and meth()')
        return True

    else:
        signal.disconnect(slot)
        return False
Ejemplo n.º 3
0
def disconnect_lambda_slots(*, signal: pyqtSignal) -> None:
    # ignore first run - when no slots connected
    with contextlib.suppress(TypeError):
        signal.disconnect()