Пример #1
0
    def eventFilter(self, obj: QObject, event: QEvent) -> bool:
        """Filter event from CodeEdit and QListView
        
        Args:
            obj (QObject): Description
            event (QEvent): Description
        
        Returns:
            bool
        """

        #  Intercept CodeEdit event
        if obj == self._target:
            if event.type() == QEvent.FocusOut:
                # Ignore lost focus!
                return True
            else:
                obj.event(event)
                return True

        # Intercept QListView event
        if obj == self.view:
            #  Redirect event to QTextExit

            if event.type() == QEvent.KeyPress and self._target:

                current = self.view.selectionModel().currentIndex()

                # emit signal when user press return
                if event.key() == Qt.Key_Return:
                    word = current.data()
                    self.activated.emit(word)
                    self.hide()
                    event.ignore()
                    return True

                # use tab to move down/up in the list
                if event.key() == Qt.Key_Tab:
                    if current.row() < self.proxy_model.rowCount() - 1:
                        self.view.setCurrentIndex(
                            self.proxy_model.index(current.row() + 1, 0))
                if event.key() == Qt.Key_Backtab:
                    if current.row() > 0:
                        self.view.setCurrentIndex(
                            self.proxy_model.index(current.row() - 1, 0))

                # Route other key event to the target ! This make possible to write text when completer is visible
                self._target.event(event)

        return super().eventFilter(obj, event)
Пример #2
0
    def eventFilter(self, obj, event):
        if event.type() == QEvent.MouseButtonPress:
            row, col = map(int, obj.objectName().split('_'))
            covering_ship: Ship = self.field.covering_ship(row, col)

            if event.button() == Qt.LeftButton:
                if covering_ship:
                    self.rotate_ship(covering_ship)
                else:
                    self.place_ship(row, col)

            elif event.button() == Qt.RightButton and covering_ship:
                self.delete_ship(covering_ship)

        return QObject.event(obj, event)
Пример #3
0
    def eventFilter(self, obj, event):
        if event.type() == QEvent.MouseButtonPress and not self.lock:
            self.lock = True
            row, col = map(int, obj.objectName().split('_'))

            user_shot = self.shot(obj, row, col, user_turn=True)
            obj.removeEventFilter(self)

            if user_shot == ShotResult.hit:
                self.help_text.setText('Nice hit. Shot again')
            elif user_shot == ShotResult.kill:
                self.help_text.setText('You kill it. Shot again')
                if self.ai_field.empty:
                    self.endgame(user_won=True)
            else:
                self.help_text.setText('You miss. AI turn')
                self.ai_turns()

            self.lock = False
        return QObject.event(obj, event)