Last active
May 24, 2022 07:22
-
-
Save durden/5060373 to your computer and use it in GitHub Desktop.
Context manager to temporarily disconnect a pyqt signal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from contextlib import contextmanager | |
@contextmanager | |
def slot_disconnected(signal, slot): | |
""" | |
Create context to perform operations with given slot disconnected from | |
given signal and automatically connected afterwards. | |
usage: | |
with slot_disconnected(chkbox.stateChanged, self._stateChanged): | |
foo() | |
bar() | |
""" | |
signal.disconnect(slot) | |
yield | |
signal.connect(slot) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment