当前位置: 首页>>代码示例>>Python>>正文


Python QBasicTimer.timerId方法代码示例

本文整理汇总了Python中PyQt5.QtCore.QBasicTimer.timerId方法的典型用法代码示例。如果您正苦于以下问题:Python QBasicTimer.timerId方法的具体用法?Python QBasicTimer.timerId怎么用?Python QBasicTimer.timerId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt5.QtCore.QBasicTimer的用法示例。


在下文中一共展示了QBasicTimer.timerId方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: AutoSaver

# 需要导入模块: from PyQt5.QtCore import QBasicTimer [as 别名]
# 或者: from PyQt5.QtCore.QBasicTimer import timerId [as 别名]
class AutoSaver(QObject):
    """
    Class implementing the auto saver.
    """
    AUTOSAVE_IN = 1000 * 3
    MAXWAIT = 1000 * 15
    
    def __init__(self, parent, save):
        """
        Constructor
        
        @param parent reference to the parent object (QObject)
        @param save slot to be called to perform the save operation
        @exception RuntimeError raised, if no parent is given
        """
        super(AutoSaver, self).__init__(parent)
        
        if parent is None:
            raise RuntimeError("AutoSaver: parent must not be None.")
        
        self.__save = save
        
        self.__timer = QBasicTimer()
        self.__firstChange = QTime()
    
    def changeOccurred(self):
        """
        Public slot handling a change.
        """
        if self.__firstChange.isNull():
            self.__firstChange.start()
        
        if self.__firstChange.elapsed() > self.MAXWAIT:
            self.saveIfNeccessary()
        else:
            self.__timer.start(self.AUTOSAVE_IN, self)
    
    def timerEvent(self, evt):
        """
        Protected method handling timer events.
        
        @param evt reference to the timer event (QTimerEvent)
        """
        if evt.timerId() == self.__timer.timerId():
            self.saveIfNeccessary()
        else:
            super(AutoSaver, self).timerEvent(evt)
    
    def saveIfNeccessary(self):
        """
        Public method to activate the save operation.
        """
        if not self.__timer.isActive():
            return
        
        self.__timer.stop()
        self.__firstChange = QTime()
        self.__save()
开发者ID:pycom,项目名称:EricShort,代码行数:60,代码来源:AutoSaver.py

示例2: WigglyLabel

# 需要导入模块: from PyQt5.QtCore import QBasicTimer [as 别名]
# 或者: from PyQt5.QtCore.QBasicTimer import timerId [as 别名]
class WigglyLabel(object):

    def __init__(self, clazz):
        self.clazz = clazz
        # clazz.setBackgroundRole(QPalette.Midlight)
        # clazz.setAutoFillBackground(True)

        setattr(clazz, "paintEvent", self.paintEvent)
        setattr(clazz, "timerEvent", self.timerEvent)

#         newFont = self.clazz.font()
#         newFont.setPointSize(newFont.pointSize() + 20)
#         self.clazz.setFont(newFont)

        self.timer = QBasicTimer()

        self.step = 0;
        self.timer.start(60, self.clazz)

    def __del__(self):
        self.timer.stop()

    def getText(self):
        return self.clazz.text()

    def paintEvent(self, event):
        # 上下跳动
        # sineTable = (0, 38, 71, 92, 100, 92, 71, 38, 0, -38, -71, -92, -100, -92, -71, -38)

        metrics = QFontMetrics(self.clazz.font())
        x = (self.clazz.width() - metrics.width(self.getText())) / 2
        y = (self.clazz.height() + metrics.ascent() - metrics.descent()) / 2
        color = QColor()

        painter = QPainter(self.clazz)

        for i, ch in enumerate(self.getText()):
            index = (self.step + i) % 16
            color.setHsv((15 - index) * 16, 255, 191)
            painter.setPen(color)
            # 上下跳动
            # painter.drawText(x, y - ((sineTable[index] * metrics.height()) / 400), ch)
            painter.drawText(x, y , ch)
            x += metrics.width(ch)

    def timerEvent(self, event):
        if event.timerId() == self.timer.timerId():
            self.step += 1
            self.clazz.update()
        else:
            super(WigglyLabel, self).timerEvent(event)
开发者ID:892768447,项目名称:BlogClient,代码行数:53,代码来源:wiggly.py

示例3: WigglyWidget

# 需要导入模块: from PyQt5.QtCore import QBasicTimer [as 别名]
# 或者: from PyQt5.QtCore.QBasicTimer import timerId [as 别名]
class WigglyWidget(QWidget):
    def __init__(self, parent=None):
        super(WigglyWidget, self).__init__(parent)

        self.setBackgroundRole(QPalette.Midlight)
        self.setAutoFillBackground(True)

        newFont = self.font()
        newFont.setPointSize(newFont.pointSize() + 20)
        self.setFont(newFont)

        self.timer = QBasicTimer()
        self.text = ''

        self.step = 0;
        self.timer.start(60, self)   

    def paintEvent(self, event):
        sineTable = (0, 38, 71, 92, 100, 92, 71, 38, 0, -38, -71, -92, -100, -92, -71, -38)

        metrics = QFontMetrics(self.font())
        x = (self.width() - metrics.width(self.text)) / 2
        y = (self.height() + metrics.ascent() - metrics.descent()) / 2
        color = QColor()

        painter = QPainter(self)

        for i, ch in enumerate(self.text):
            index = (self.step + i) % 16
            color.setHsv((15 - index) * 16, 255, 191)
            painter.setPen(color)
            painter.drawText(x, y - ((sineTable[index] * metrics.height()) / 400), ch)
            x += metrics.width(ch)

    def setText(self, newText):
        self.text = newText

    def timerEvent(self, event):
        if event.timerId() == self.timer.timerId():
            self.step += 1
            self.update()
        else:
            super(WigglyWidget, self).timerEvent(event)
开发者ID:death-finger,项目名称:Scripts,代码行数:45,代码来源:wiggly.py

示例4: LiquidBox

# 需要导入模块: from PyQt5.QtCore import QBasicTimer [as 别名]
# 或者: from PyQt5.QtCore.QBasicTimer import timerId [as 别名]
class LiquidBox(QWidget):
    # 模拟流体力学程序,盛着液体的盒子
    def __init__(self):
        super().__init__()
        self.speed = 100  #重绘速度1s
        self.WindowSize = 50
        self.timer = QBasicTimer()
        self.sim = sm.Stimulator(self.WindowSize)
        self.initUI()

    def initUI(self):
        self.setGeometry(200, 200, 600, 600)
        self.setFixedSize(400, 400)
        self.setWindowTitle("流体力学模拟程序")
        self.timer.start(self.speed, self)
        self.show()

    #处理计时器消息
    def timerEvent(self, event):
        if event.timerId() == self.timer.timerId():
            self.update()
        else:
            super().timerEvent(event)

    #处理重绘消息
    def paintEvent(self, event):
        qp = QPainter()
        qp.begin(self)
        self.Draw(qp)
        qp.end()

    #具体绘图函数
    def Draw(self, qp):
        qp.setPen(Qt.blue)
        points = self.sim.step()
        for i in range(len(points)):
            qp.drawPoint(int(points[i][0]), int(points[i][1]))
开发者ID:zwdnet,项目名称:liquid,代码行数:39,代码来源:MainWindow.py

示例5: Board

# 需要导入模块: from PyQt5.QtCore import QBasicTimer [as 别名]
# 或者: from PyQt5.QtCore.QBasicTimer import timerId [as 别名]

#.........这里部分代码省略.........
        key = event.key()

        if key == Qt.Key_P:
            self.pause()
            return

        if self.isPaused:
            return

        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()

        else:
            super(Board, self).keyPressEvent(event)


    def timerEvent(self, event):

        if event.timerId() == self.timer.timerId():

            if self.isWaitingAfterLine:
                self.isWaitingAfterLine = False
                self.newPiece()
            else:
                self.oneLineDown()

        else:
            super(Board, self).timerEvent(event)


    def clearBoard(self):

        for i in range(Board.BoardHeight * Board.BoardWidth):
            self.board.append(Tetrominoe.NoShape)


    def dropDown(self):

        newY = self.curY

        while newY > 0:

            if not self.tryMove(self.curPiece, self.curX, newY - 1):
                break

            newY -= 1

        self.pieceDropped()


    def oneLineDown(self):
开发者ID:HappyJamesL,项目名称:pyqtlearn,代码行数:70,代码来源:tetrisgame.py

示例6: TetrixBoard

# 需要导入模块: from PyQt5.QtCore import QBasicTimer [as 别名]
# 或者: from PyQt5.QtCore.QBasicTimer import timerId [as 别名]

#.........这里部分代码省略.........
                            rect.left() + j * self.squareWidth(),
                            boardTop + i * self.squareHeight(), shape)

        if self.curPiece.shape() != NoShape:
            for i in range(4):
                x = self.curX + self.curPiece.x(i)
                y = self.curY - self.curPiece.y(i)
                self.drawSquare(painter, rect.left() + x * self.squareWidth(),
                        boardTop + (TetrixBoard.BoardHeight - y - 1) * self.squareHeight(),
                        self.curPiece.shape())

    def keyPressEvent(self, event):
        if not self.isStarted or self.isPaused or self.curPiece.shape() == NoShape:
            super(TetrixBoard, self).keyPressEvent(event)
            return

        key = event.key()
        if 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.rotatedRight(), self.curX, self.curY)
        elif key == Qt.Key_Up:
            self.tryMove(self.curPiece.rotatedLeft(), self.curX, self.curY)
        elif key == Qt.Key_Space:
            self.dropDown()
        elif key == Qt.Key_D:
            self.oneLineDown()
        else:
            super(TetrixBoard, self).keyPressEvent(event)

    def timerEvent(self, event):
        if event.timerId() == self.timer.timerId():
            if self.isWaitingAfterLine:
                self.isWaitingAfterLine = False
                self.newPiece()
                self.timer.start(self.timeoutTime(), self)
            else:
                self.oneLineDown()
        else:
            super(TetrixBoard, self).timerEvent(event)

    def clearBoard(self):
        self.board = [NoShape for i in range(TetrixBoard.BoardHeight * TetrixBoard.BoardWidth)]

    def dropDown(self):
        dropHeight = 0
        newY = self.curY
        while newY > 0:
            if not self.tryMove(self.curPiece, self.curX, newY - 1):
                break
            newY -= 1
            dropHeight += 1

        self.pieceDropped(dropHeight)

    def oneLineDown(self):
        if not self.tryMove(self.curPiece, self.curX, self.curY - 1):
            self.pieceDropped(0)

    def pieceDropped(self, dropHeight):
        for i in range(4):
            x = self.curX + self.curPiece.x(i)
            y = self.curY - self.curPiece.y(i)
            self.setShapeAt(x, y, self.curPiece.shape())
开发者ID:Axel-Erfurt,项目名称:pyqt5,代码行数:70,代码来源:tetrix.py

示例7: Board

# 需要导入模块: from PyQt5.QtCore import QBasicTimer [as 别名]
# 或者: from PyQt5.QtCore.QBasicTimer import timerId [as 别名]

#.........这里部分代码省略.........
                print("Collision! There is: {0} or \
                      {1}".format(self.board[y1][x1], self.board[y2][x2]))
                return True
            elif direction == 'up' and y1 < 0:
                return True
            elif direction == 'right' and x1 > self.board_width:
                return True
            elif direction == 'down' and y1 > self.board_height:
                return True
            elif direction == 'left' and x1 < 0:
                return True
            else:
                return False
        except IndexError:
            return True

    def paintEvent(self, event):

        painter = QPainter(self)

        if self.debug_mode:
            self.drawRealBoard(painter)
        else:
            self.drawBoard(painter)
            self.drawPlayer(painter)

        self.update()

    def timerEvent(self, event):
        """
        Overwritten function of timer event
        """

        if event.timerId() == self.timer.timerId():
            takenBeds = self.getTakenBeds()

            if not self.is_operating and takenBeds:
                self.goToPatient(takenBeds)

        else:
            super(Board, self).timerEvent(event)

    def goToPatient(self, takenBeds):
        if takenBeds:
            index = randint(0, len(takenBeds) - 1)
            x, y = takenBeds[index].getPosition()
            sizeX, sizeY = takenBeds[index].getSize()

            pointX = int(x / 80)
            pointY = int(y / 80)

            if takenBeds[index].getName() == 'bed4':
                pointY = int(pointY + sizeY / 80)
            else:
                pointX = int(pointX + sizeX / 80)

            self.current_bed = takenBeds[index].getName()

            playerX = int(self.player_x / 80)
            playerY = int(self.player_y / 80)

            if self.pathFinding == "aStar":
                cameFrom, costSoFar = self.aStarSearch(self.graph,
                                                      (playerX, playerY),
                                                      (pointX, pointY))
            elif self.pathFinding == "dijkstra":
开发者ID:wieloranski,项目名称:experiNurse,代码行数:70,代码来源:board.py

示例8: Field

# 需要导入模块: from PyQt5.QtCore import QBasicTimer [as 别名]
# 或者: from PyQt5.QtCore.QBasicTimer import timerId [as 别名]

#.........这里部分代码省略.........
        self.clear()
        self.draw()
        if self.game.state is State.won:
            self.message(1)
        if self.game.state is State.lost:
            self.message(2)

    def move_current_right(self):
        """Moves the player right, draws the new field and checks for end of level."""
        self.game.move_current_right()
        self.clear()
        self.draw()
        if self.game.x == self.height - 1 and self.game.y == self.width - 1:
            if self.game.player.enough_stars():
                self.switch_levels()
            else:
                self.message(0)
        if self.game.state is State.won:
            self.message(1)
        if self.game.state is State.lost:
            self.message(2)

    def move_x(self, place, way):
        """Specifies the direction of moving of a X."""
        letter = way[0]
        if letter == 'u':
            self.game.move_x_up(place)
        if letter == 'd':
            self.game.move_x_down(place)
        if letter == 'l':
            self.game.move_x_left(place)
        if letter == 'r':
            self.game.move_x_right(place)
        way += letter
        way.pop(0)

    def keyPressEvent(self, event):
        if self.game.state is State.paused:
            key = event.key()
            if key == Qt.Key_P:
                self.unpause()
            else:
                super(Field, self).keyPressEvent(event)
            return
        if self.game.state is not State.running:
            super(Field, self).keyPressEvent(event)
            return
        key = event.key()
        if key == Qt.Key_Up:
            self.move_current_up()
        elif key == Qt.Key_Down:
            self.move_current_down()
        elif key == Qt.Key_Left:
            self.move_current_left()
        elif key == Qt.Key_Right:
            self.move_current_right()
        elif key == Qt.Key_P:
            self.pause()
        else:
            super(Field, self).keyPressEvent(event)

    def timerEvent(self, event):
        if self.game.state is not State.running:
            super(Field, self).timerEvent(event)
            return
        lev = self.game.level - 1
        if event.timerId() == self.timer.timerId() and self.ways.ways[lev] != []:
            for moving_x in self.ways.ways[lev]:
                self.move_x(moving_x['place'], moving_x['way'])
            self.clear()
            self.draw()
            if self.game.state is State.lost:
                self.message(2)
        else:
            super(Field, self).timerEvent(event)

    def switch_levels(self):
        self.game.new_level()
        self.mat = self.game.field
        self.clear()
        self.draw()

    def pause(self):
        self.game.pause()
        self.clear()
        self.draw()

    def unpause(self):
        self.game.unpause()
        self.clear()
        self.draw()

    def message(self, text_no):
        texts = [
            "You must collect all {} stars to continue!".format(self.game.player.STARS),
            "You win! Congratulations!",
            "Game over! Good luck next time!"]
        msgBox = QMessageBox()
        msgBox.setText(texts[text_no])
        msgBox.exec_()
开发者ID:sulovm,项目名称:starsMaze,代码行数:104,代码来源:gui.py

示例9: FieldUI

# 需要导入模块: from PyQt5.QtCore import QBasicTimer [as 别名]
# 或者: from PyQt5.QtCore.QBasicTimer import timerId [as 别名]
class FieldUI(QFrame):
    def __init__(self, parent, game):
        super().__init__(parent)
        self.main_window = parent
        self.game = game
        self.rocks = self.game.rocks
        self.powerups = self.game.powerups
        self.bullets = self.game.bullets
        self.width, self.height = self.game.dimensions

        self.init_timers()
        self.start_timers()

        self.player_ui = PlayerUI(self, self.game)

        self.init_signals()
        self.setFocusPolicy(Qt.StrongFocus)

    def init_timers(self):
        """Initializes the timers in the game."""
        self.game_timer = QBasicTimer()
        self.rock_timer = QBasicTimer()
        self.level_timer = QBasicTimer()
        self.powerup_timer = QBasicTimer()
        self.ticker_timer = QBasicTimer()
        self.bullet_timer = QBasicTimer()

        self.player_invincibility_timer = QBasicTimer()
        self.big_bomb_timer = QBasicTimer()
        self.slow_down_rocks_timer = QBasicTimer()
        self.shoot_rocks_timer = QBasicTimer()

        self.powerup_duration_timer = QTimer()

    def start_timers(self):
        """Starts the timers in the game."""
        self.game_timer.start(self.game.game_speed, self)
        self.rock_timer.start(self.game.rock_speed, self)
        self.level_timer.start(self.game.level_speed, self)
        self.powerup_timer.start(self.game.rock_speed, self)
        self.player_invincibility_timer.start(int(PowerupTimeInterval.medium),
                                              self)
        self.big_bomb_timer.start(int(PowerupTimeInterval.big), self)
        self.slow_down_rocks_timer.start(int(PowerupTimeInterval.medium), self)
        self.shoot_rocks_timer.start(int(PowerupTimeInterval.very_big), self)
        self.bullet_timer.start(self.game.bullet_speed, self)

    def stop_timers(self):
        """Stops the timers in the game."""
        self.game_timer.stop()
        self.rock_timer.stop()
        self.level_timer.stop()
        self.powerup_timer.stop()
        self.ticker_timer.stop()
        self.bullet_timer.stop()

        self.player_invincibility_timer.stop()
        self.big_bomb_timer.stop()
        self.slow_down_rocks_timer.stop()
        self.shoot_rocks_timer.stop()

        self.powerup_duration_timer.stop()

    def init_signals(self):
        """Initializes the signals in the game that connect to a method and
        calls it after the singnals are emitted.
        """
        self.com = Communicate()
        self.com.move_left.connect(self.player_ui.move_left)
        self.com.move_right.connect(self.player_ui.move_right)
        self.com.restart.connect(self.main_window.restart_game)
        self.com.exit.connect(UserInterface.close_app)
        self.com.win.connect(self.win_the_game)

    def timerEvent(self, event):
        """Gets the emitted events from the timers and calls the appropriate
        methods for each of them.
        """
        self.powerups_timer_events(event)
        self.gameplay_timer_events(event)
        if event.timerId() == self.ticker_timer.timerId():
            self.ticker["value"] -= 1
            if self.ticker["type"] == "player_invincibility":
                self.show_player_invincibility_info(self.ticker["value"])
            if self.ticker["type"] == "slow_down_rocks":
                self.show_slow_down_rocks_info(self.ticker["value"])
            if self.ticker["type"] == "shoot_rocks":
                self.show_shoot_rocks_info(self.ticker["value"])
                self.bullet_ui = BulletUI(self, self.game, self.player_ui)
                self.bullets.append(self.bullet_ui)
        else:
            super(FieldUI, self).timerEvent(event)

    def gameplay_timer_events(self, event):
        """Gets the emitted events from the timers related to the gameplay and
        calls the appropriate methods and initializes the appropriate objects
        for each of them.
        """
        if event.timerId() == self.game_timer.timerId():
            self.rock_ui = RockUI(self, self.game)
#.........这里部分代码省略.........
开发者ID:hristy93,项目名称:FallingRocks,代码行数:103,代码来源:user_interface.py

示例10: Tetris

# 需要导入模块: from PyQt5.QtCore import QBasicTimer [as 别名]
# 或者: from PyQt5.QtCore.QBasicTimer import timerId [as 别名]
class Tetris(QMainWindow):
    def __init__(self):
        super().__init__()
        self.isStarted = False
        self.isPaused = False
        self.nextMove = None
        self.lastShape = Shape.shapeNone

        self.initUI()

    def initUI(self):
        self.gridSize = 22
        self.speed = 10

        self.timer = QBasicTimer()
        self.setFocusPolicy(Qt.StrongFocus)

        hLayout = QHBoxLayout()
        self.tboard = Board(self, self.gridSize)
        hLayout.addWidget(self.tboard)

        self.sidePanel = SidePanel(self, self.gridSize)
        hLayout.addWidget(self.sidePanel)

        self.statusbar = self.statusBar()
        self.tboard.msg2Statusbar[str].connect(self.statusbar.showMessage)

        self.start()

        self.center()
        self.setWindowTitle('Tetris')
        self.show()

        self.setFixedSize(self.tboard.width() + self.sidePanel.width(),
                          self.sidePanel.height() + self.statusbar.height())

    def center(self):
        screen = QDesktopWidget().screenGeometry()
        size = self.geometry()
        self.move((screen.width() - size.width()) // 2, (screen.height() - size.height()) // 2)

    def start(self):
        if self.isPaused:
            return

        self.isStarted = True
        self.tboard.score = 0
        BOARD_DATA.clear()

        self.tboard.msg2Statusbar.emit(str(self.tboard.score))

        BOARD_DATA.createNewPiece()
        self.timer.start(self.speed, self)

    def pause(self):
        if not self.isStarted:
            return

        self.isPaused = not self.isPaused

        if self.isPaused:
            self.timer.stop()
            self.tboard.msg2Statusbar.emit("paused")
        else:
            self.timer.start(self.speed, self)

        self.updateWindow()

    def updateWindow(self):
        self.tboard.updateData()
        self.sidePanel.updateData()
        self.update()

    def timerEvent(self, event):
        if event.timerId() == self.timer.timerId():
            if TETRIS_AI and not self.nextMove:
                self.nextMove = TETRIS_AI.nextMove()
            if self.nextMove:
                k = 0
                while BOARD_DATA.currentDirection != self.nextMove[0] and k < 4:
                    BOARD_DATA.rotateRight()
                    k += 1
                k = 0
                while BOARD_DATA.currentX != self.nextMove[1] and k < 5:
                    if BOARD_DATA.currentX > self.nextMove[1]:
                        BOARD_DATA.moveLeft()
                    elif BOARD_DATA.currentX < self.nextMove[1]:
                        BOARD_DATA.moveRight()
                    k += 1
            # lines = BOARD_DATA.dropDown()
            lines = BOARD_DATA.moveDown()
            self.tboard.score += lines
            if self.lastShape != BOARD_DATA.currentShape:
                self.nextMove = None
                self.lastShape = BOARD_DATA.currentShape
            self.updateWindow()
        else:
            super(Tetris, self).timerEvent(event)

    def keyPressEvent(self, event):
#.........这里部分代码省略.........
开发者ID:EleVenPerfect,项目名称:OTHERS,代码行数:103,代码来源:tetris_game.py


注:本文中的PyQt5.QtCore.QBasicTimer.timerId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。