Hello World / plɹoM ollǝH

Programmers Live in Vain

pyside scoped signal blocking

IMPLEMENTS

class ScopedBlockSignals:
    def __init__(self, obj):
        self.obj = obj

    def __enter__(self):
        self._recursiveSet(self.obj, True)

    def __exit__(self, _exc_type, _exc_val, _exc_tb):
        self._recursiveSet(self.obj, False)

    def _recursiveSet(self, obj, flag):
        obj.blockSignals(flag)
        for c in obj.children():
            self._recursiveSet(c, flag)

HOW TO USE

widget = QLineEdit()
widget.textChanged.connect(lambda x: print(x))
with ScopedBlockSignals(widget):
    widget.setText('hoge')
widget.setText('fuga')

RESULT

fuga