Example #1
0
 def viewportEvent(self, event: QEvent) -> bool:
     if event.type() == QEvent.Wheel:
         # delegate wheel events to parent StickyGraphicsView
         parent = self.parent().parent().parent()
         if isinstance(parent, StickyGraphicsView):
             QCoreApplication.sendEvent(parent.viewport(), event)
             if event.isAccepted():
                 return True
     return super().viewportEvent(event)
Example #2
0
    def keyPressEvent(self, event: QEvent):
        '''
        Process a key press. Any key press (not release) while the
        focus is in the board comes here. The key code is event.key()
        and the names of keys are defined in the Qt namespace, see
        http://doc.qt.io/qt-5/qt.html#Key-enum

        If we can handle the event we do; else pass it to our parent.

        Note that in left, right and rotate keys, we could look at the return
        from tryMove() and if it is False, we could maybe implement the "wall
        kick" feature.
        '''

        if self.isStarted and self.curPiece is not NO_T_mo:
            key = event.key()
            if key in self.validKeys:
                event.accept()  # Tell Qt, we got this one
                if key == Qt.Key_P:
                    self.togglePause()
                elif key == Qt.Key_Left:
                    self.tryMove(self.curPiece, self.curX - 1, self.curY)
                elif key == Qt.Key_Right:
                    self.tryMove(self.curPiece, self.curX + 1, self.curY)
                elif key == Qt.Key_Down:
                    self.tryMove(self.curPiece.rotateRight(), self.curX,
                                 self.curY)
                elif key == Qt.Key_Up:
                    self.tryMove(self.curPiece.rotateLeft(), self.curX,
                                 self.curY)
                elif key == Qt.Key_Space:
                    self.dropDown()
                elif key == Qt.Key_D:
                    self.oneLineDown()
        if not event.isAccepted():
            '''either we are paused or not one of our keys'''
            super().keyPressEvent(event)
Example #3
0
 def updateTarget(self):
     event = QEvent(QEvent.Type(StyleAnimationUpdate))
     event.setAccepted(False)
     QCoreApplication.sendEvent(self.target(), event)
     if not event.isAccepted():
         self.stop()