Skip to content

Instantly share code, notes, and snippets.

@durden
Last active May 24, 2022 07:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save durden/5060373 to your computer and use it in GitHub Desktop.
Save durden/5060373 to your computer and use it in GitHub Desktop.
Context manager to temporarily disconnect a pyqt signal
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