def METHOD_NAME(self, obj, event):
    if not self._popup_is_shown:
        return
    current_index = self.view().currentIndex()
    model = self.model()
    if event.type() == QtCore.QEvent.MouseMove:
        if (
            self.view().isVisible()
            and self._initial_mouse_pos is not None
            and self._block_mouse_release_timer.isActive()
        ):
            diff = obj.mapToGlobal(event.pos()) - self._initial_mouse_pos
            if diff.manhattanLength() > 9:
                self._block_mouse_release_timer.stop()
        return
    index_flags = current_index.flags()
    state = checkstate_int_to_enum(
        current_index.data(QtCore.Qt.CheckStateRole)
    )
    new_state = None
    if event.type() == QtCore.QEvent.MouseButtonRelease:
        if (
            self._block_mouse_release_timer.isActive()
            or not current_index.isValid()
            or not self.view().isVisible()
            or not self.view().rect().contains(event.pos())
            or not index_flags & QtCore.Qt.ItemIsSelectable
            or not index_flags & QtCore.Qt.ItemIsEnabled
            or not index_flags & QtCore.Qt.ItemIsUserCheckable
        ):
            return
        if state == QtCore.Qt.Unchecked:
            new_state = CHECKED_INT
        else:
            new_state = UNCHECKED_INT
    elif event.type() == QtCore.QEvent.KeyPress:
        # TODO: handle QtCore.Qt.Key_Enter, Key_Return?
        if event.key() == QtCore.Qt.Key_Space:
            # toggle the current items check state
            if (
                index_flags & QtCore.Qt.ItemIsUserCheckable
                and index_flags & ITEM_IS_USER_TRISTATE
            ):
                new_state = (checkstate_enum_to_int(state) + 1) % 3
            elif index_flags & QtCore.Qt.ItemIsUserCheckable:
                if state != QtCore.Qt.Checked:
                    new_state = CHECKED_INT
                else:
                    new_state = UNCHECKED_INT
    if new_state is not None:
        model.setData(current_index, new_state, QtCore.Qt.CheckStateRole)
        self.view().update(current_index)
        self.value_changed.emit()
        return True