from silx.gui import qt


class QSpinBoxWithEditionSignal(qt.QSpinBox):
    sigFocusOut = qt.Signal()
    sigFocusIn = qt.Signal()

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.installEventFilter(self)

    def eventFilter(self, obj, event):
        if event.type() == qt.QEvent.Type.FocusIn:
            self.sigFocusIn.emit()
        elif event.type() == qt.QEvent.Type.FocusOut:
            self.sigFocusOut.emit()

        return super().eventFilter(obj, event)
