pcdsutils.qt.callbacks.WeakPartialMethodSlot
- class pcdsutils.qt.callbacks.WeakPartialMethodSlot(signal_owner: QObject, signal: pyqtSignal, method: MethodType, *args, **kwargs)[source]
A PyQt-compatible slot for a partial method.
This utility handles deleting the connection when the method class instance gets garbage collected. This avoids cycles in the garbage collector that would prevent the instance from being garbage collected prior to the program exiting.
To use, create an instance of this class, and store a hard reference to that instance. The class will connect the slot to the signal:
class MyWidget(QtWidgets.QWidget): button: QtWidgets.QPushButton def __init__(self, *args, **kwargs): self._partial_slots: List[WeakPartialMethodSlot] = [] slot = WeakPartialMethodSlot( self.button, self.button.clicked, self.foo_method, 'partial_foo' ) self._partial_slots.append(slot) # hold hard reference super().__init__(*args, **kwargs) def foo_method(self, my_arg): print(my_arg)
- Parameters:
- signal_ownerQtCore.QObject
The owner of the signal.
- signalQtCore.Signal
The signal instance itself. Should be a signal on
signal_owner- methodinstance method
The method slot to call when the signal fires. Should be a method on the containing class.
- *args
Arguments to pass to the method.
- **kwargs
Keyword arguments to pass to the method.
Methods
__init__(signal_owner, signal, method, ...)