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


Python QBasicTimer.start方法代码示例

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


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

示例1: T_window

# 需要导入模块: from PyQt5.QtCore import QBasicTimer [as 别名]
# 或者: from PyQt5.QtCore.QBasicTimer import start [as 别名]
class T_window(QWidget):
    def __init__(self):
        super().__init__()
        self.tabs = QTabWidget()
        self.com = T_communication()
        self.pbar = QProgressBar()
        self.pbar.setFormat("Battery : %p%")
        self.grid = QGridLayout()

        self.setLayout(self.grid)
        self.grid.addWidget(self.pbar)
        self.grid.addWidget(self.tabs)

        self.dpi = T_dpi()
        self.com.getDpi(self.dpi)
        self.dpi.dataHasBeenSent()
        self.t = []
        for i in range(0, 4):
            self.t.append(T_tab(i, self.dpi, self.com))
            self.tabs.addTab(self.t[i], "Mode " + str(i + 1))

        self.data = T_data(self.pbar, self.tabs, self.dpi, self.com)
        for i in range(0, 4):
            self.t[i].sendButton.clicked.connect(self.data.sendDpi)
            self.t[i].resetButton.clicked.connect(self.com.resetDpi)
        self.timer = QBasicTimer()
        self.timer.start(100, self.data)
        self.tabs.currentChanged.connect(self.com.sendMode)
开发者ID:np,项目名称:MadCatz,代码行数:30,代码来源:configurator.py

示例2: Example

# 需要导入模块: from PyQt5.QtCore import QBasicTimer [as 别名]
# 或者: from PyQt5.QtCore.QBasicTimer import start [as 别名]
class Example(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()
 
    def initUI(self):
        self.progress_bar = QProgressBar(self)
        self.progress_bar.setGeometry(30, 40, 200, 25)
 
        self.btn = QPushButton('Start', self)
        self.btn.move(30, 80)
        self.btn.clicked.connect(self.doAction)
 
        self.timer = QBasicTimer()
        self.step = 0
 
        self.setGeometry(300, 300, 280, 170)
        self.setWindowTitle('QProgressBar')
        self.show()
 
    def timerEvent(self, QTimerEvent):
        if self.step >= 100:
            self.timer.stop()
            self.btn.setText('Finished')
            return
        self.step += 1
        self.progress_bar.setValue(self.step)
 
    def doAction(self):
        if self.timer.isActive():
            self.timer.stop()
            self.btn.setText('Start')
        else:
            self.timer.start(100, self)
            self.btn.setText('Stop')
开发者ID:blackPantherOS,项目名称:playground,代码行数:37,代码来源:progress.py

示例3: Marquee

# 需要导入模块: from PyQt5.QtCore import QBasicTimer [as 别名]
# 或者: from PyQt5.QtCore.QBasicTimer import start [as 别名]
class Marquee(QLabel):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.right_to_left_direction = True
        self.initUI()
        self.timer = QBasicTimer()
        self.timer.start(80, self)

    def initUI(self):
        self.setWindowFlags(Qt.FramelessWindowHint)
        self.setAttribute(Qt.WA_TranslucentBackground)
        self.setText("Hello World! ")
        self.setFont(QFont(None, 50, QFont.Bold))
        # make more irritating for the authenticity with <marquee> element
        self.setStyleSheet("QLabel {color: cyan; }")

    def timerEvent(self, event):
        i = 1 if self.right_to_left_direction else -1
        self.setText(self.text()[i:] + self.text()[:i])  # rotate

    def mouseReleaseEvent(self, event):  # change direction on mouse release
        self.right_to_left_direction = not self.right_to_left_direction

    def keyPressEvent(self, event):  # exit on Esc
        if event.key() == Qt.Key_Escape:
            self.close()
开发者ID:acmeism,项目名称:RosettaCodeData,代码行数:28,代码来源:animation-1.py

示例4: AutoSaver

# 需要导入模块: from PyQt5.QtCore import QBasicTimer [as 别名]
# 或者: from PyQt5.QtCore.QBasicTimer import start [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

示例5: Example

# 需要导入模块: from PyQt5.QtCore import QBasicTimer [as 别名]
# 或者: from PyQt5.QtCore.QBasicTimer import start [as 别名]
class Example(QWidget):
    
    def __init__(self):
        super().__init__()
        
        self.initUI()
        
        
    def initUI(self):      

        self.pbar = QProgressBar(self)
        self.pbar.setGeometry(30, 40, 200, 25)

        self.btn = QPushButton('Start', self)
        self.btn.move(40, 80)
        self.btn.clicked.connect(self.doAction)

        # タイマー
        self.timer = QBasicTimer()
        self.step = 0
        
        self.setGeometry(300, 300, 280, 170)
        self.setWindowTitle('QProgressBar')
        self.show()
        
        
    def timerEvent(self, e):
        # カウントが100に達すると終了
        if self.step >= 100:
            self.timer.stop()
            self.btn.setText('Finished')
            return
    
        # 呼ばれるたび1ずつ増やす
        self.step = self.step + 1
        self.pbar.setValue(self.step)
        

    def doAction(self):
        """ボタンが押されると呼ばれる"""

        # タイマーが実行中ならタイマーを停止する
        if self.timer.isActive():
            self.timer.stop()
            self.btn.setText('Start')
        # タイマーが停止中ならタイマーを実行する
        else:
            # (timeout[ms], イベントの受取先)
            # timeoutで指定した時間間隔でシグナルが飛ぶ模様
            self.timer.start(1000, self)
            self.btn.setText('Stop')
开发者ID:minus9d,项目名称:python_exercise,代码行数:53,代码来源:ch06-04-QProgressBar.py

示例6: WigglyLabel

# 需要导入模块: from PyQt5.QtCore import QBasicTimer [as 别名]
# 或者: from PyQt5.QtCore.QBasicTimer import start [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

示例7: setupWidget

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

	def __init__(self,parent_):
		super(setupWidget,self).__init__(parent_)
		self.parent_=parent_
		self.initUI()

	def initUI(self):
		self.pbar = QProgressBar(self)
		self.pbar.setObjectName('pbar')
		self.pbar.setTextVisible(True)
		self.pbar.setFormat('Configuring...')

		self.timer = QBasicTimer()
		self.step = 0

		pixmap=QPixmap(':/Assets/moodly.gif')
		lbl=QLabel(self)
		lbl.setPixmap(pixmap)

		hbox1=QHBoxLayout()
		hbox1.addStretch(1)
		hbox1.addWidget(lbl)
		hbox1.addStretch(1)

		hbox2=QHBoxLayout()
		hbox2.addStretch(1)
		hbox2.addWidget(self.pbar)
		hbox2.addStretch(1)

		vbox=QVBoxLayout()
		vbox.addStretch(8)
		vbox.addLayout(hbox1)
		vbox.addStretch(1)
		vbox.addLayout(hbox2)
		vbox.addStretch(8)

		self.setLayout(vbox)
		self.callTimer()

	def timerEvent(self,e):
		if self.step>=100:
			self.step=0
		self.step=self.step+1
		self.pbar.setValue(self.step)

	def callTimer(self):
		 self.timer.start(100, self)
开发者ID:AkshayAgarwal007,项目名称:Moodly,代码行数:50,代码来源:view.py

示例8: MyQt

# 需要导入模块: from PyQt5.QtCore import QBasicTimer [as 别名]
# 或者: from PyQt5.QtCore.QBasicTimer import start [as 别名]
class MyQt(QWidget):
    def __init__(self):
        super(MyQt, self).__init__()
        self.initUI()

    def initUI(self):
        # 构建一个进度条
        self.pbar = QProgressBar(self)
        # 从左上角30-50的界面,显示一个200*25的界面
        self.pbar.setGeometry(30, 50, 200, 25)  # 设置进度条的位置
        # 设置开始按钮
        self.btn = QPushButton('开始', self)
        self.btn.move(50, 90)  # 按钮移动的位置
        # 点击按钮
        # 信号函数不能加括号
        self.btn.clicked.connect(self.doAction)


        # 构建一个计时器
        self.timer = QBasicTimer()
        # 计数
        self.step = 0
        self.setGeometry(300,300,280,170)
        self.setWindowTitle('我是进度条')
        self.setWindowIcon(QIcon('1.jpg'))

        self.show()

    def doAction(self):
        # 判断是否处于激活状态
        if self.timer.isActive():
            self.timer.stop()
            self.btn.setText('开始')
        else:
            self.timer.start(100,self)
            self.btn.setText('停止')
    def timerEvent(self, *args, **kwargs):
        if self.step>=100:
            # 停止进度条
            self.timer.stop()
            self.btn.setText('完成')
            return
        self.step+=1
        # 把进度条每次充值的值赋给进图条
        self.pbar.setValue(self.step)
开发者ID:fiso0,项目名称:MxPython,代码行数:47,代码来源:progressBarTest.py

示例9: WigglyWidget

# 需要导入模块: from PyQt5.QtCore import QBasicTimer [as 别名]
# 或者: from PyQt5.QtCore.QBasicTimer import start [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

示例10: LiquidBox

# 需要导入模块: from PyQt5.QtCore import QBasicTimer [as 别名]
# 或者: from PyQt5.QtCore.QBasicTimer import start [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

示例11: CheckCreds

# 需要导入模块: from PyQt5.QtCore import QBasicTimer [as 别名]
# 或者: from PyQt5.QtCore.QBasicTimer import start [as 别名]
class CheckCreds(QDialog):
    """
        This class manages the authentication process for oVirt. If credentials are saved, they're
        tried automatically. If they are wrong, the username/password dialog is shown.
    """

    def __init__(self, parent, username, password, remember):
        QDialog.__init__(self, parent)
        self.uname = username
        self.pw = password
        self.remember = False if conf.CONFIG['allow_remember'] == '0' else remember
        self.setModal(True)

        self.initUI()

    def initUI(self):
        """
            Description: A progress bar, a status message will be shown and a timer() method will
                         be invoked as part of the authentication process.
            Arguments: None
            Returns: Nothing
        """

        self.pbar = QProgressBar(self)
        self.pbar.setGeometry(30, 40, 200, 25)
        
        self.status = QLabel(self)
        self.status.setGeometry(30, 75, 200, 20)

        self.timer = QBasicTimer()
        self.step = 0
        
        self.setGeometry(300, 300, 255, 100)
        self.center()
        self.setWindowTitle(_('loading'))
        self.show()

        self.timer.start(100, self)
    
    def timerEvent(self, e):
        """
            Description: Called periodically as part of the QBasicTimer() object.
                         Authentication will be handled within this method.
            Arguments: The event. Won't be used, though.
            Returns: Nothing, just exits when progress bar reaches 100%
        """

        global conf

        err = QMessageBox()
        self.status.setText(_('authenticating'))

        if not conf.USERNAME:
            try:
                kvm = API(url=conf.CONFIG['ovirturl'], username=self.uname + '@' + conf.CONFIG['ovirtdomain'], password=self.pw, insecure=True, timeout=int(conf.CONFIG['conntimeout']), filter=True)
                conf.OVIRTCONN = kvm
                conf.USERNAME = self.uname
                conf.PASSWORD = self.pw
                self.status.setText(_('authenticated_and_storing'))
                self.step = 49
            except ConnectionError as e:
                err.critical(self, _('apptitle') + ': ' + _('error'), _('ovirt_connection_error') + ': ' + sub('<[^<]+?>', '', str(e)))
                self.status.setText(_('error_while_authenticating'))
                self.step = 100
            except RequestError as e:
                err.critical(self, _('apptitle') + ': ' + _('error'), _('ovirt_request_error') + ': ' + sub('<[^<]+?>', '', str(e)))
                self.status.setText(_('error_while_authenticating'))
                self.step = 100
        
        if self.step >= 100:
            # Authenticacion process has concluded
            self.timer.stop()
            self.close()
            return
        elif self.step == 50:
            # Credentials were ok, we check whether we should store them for further uses
            if self.remember:
                self.status.setText(_('storing_credentials'))
                with os.fdopen(os.open(conf.USERCREDSFILE, os.O_WRONLY | os.O_CREAT, 0600), 'w') as handle:
                    handle.write('[credentials]\nusername=%s\npassword=%s' % (self.uname, encode(self.pw, 'rot_13')))
                    handle.close()
                self.step = 99
            else:
                self.status.setText(_('successfully_authenticated'))
                self.step = 99
            
        self.step = self.step + 1
        self.pbar.setValue(self.step)
开发者ID:h0lyday,项目名称:ovirt-desktop-client,代码行数:90,代码来源:credentials.py

示例12: ScrollArea

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

#.........这里部分代码省略.........
        viewport = self.viewport().rect()
        dx = pos.x() - viewport.left() - 12
        if dx >= 0:
            dx = max(0, pos.x() - viewport.right() + 12)
        dy = pos.y() - viewport.top() - 12
        if dy >= 0:
            dy = max(0, pos.y() - viewport.bottom() + 12)
        self.steadyScroll(QPoint(dx*10, dy*10))

    def scrollTo(self, pos):
        """Scroll the View to get pos (QPoint) in the top left corner (if possible).

        Returns the actual distance moved.

        """
        return self.scrollBy(pos - self.scrollOffset())

    def scrollBy(self, diff):
        """Scroll the View diff pixels (QPoint) in x and y direction.

        Returns the actual distance moved.

        """
        hbar = self.horizontalScrollBar()
        vbar = self.verticalScrollBar()
        x = hbar.value()
        hbar.setValue(hbar.value() + diff.x())
        x = hbar.value() - x
        y = vbar.value()
        vbar.setValue(vbar.value() + diff.y())
        y = vbar.value() - y
        return QPoint(x, y)

    def kineticScrollTo(self, pos):
        """Scroll the View to get pos (QPoint) in the top left corner (if possible).

        Returns the actual distance the scroll area will move.

        """
        return self.kineticScrollBy(pos - self.scrollOffset())

    def kineticScrollBy(self, diff):
        """Scroll the View diff pixels (QPoint) in x and y direction.

        Returns the actual distance the scroll area will move.

        """
        ret = self.canScrollBy(diff)
        if diff:
            scroller = KineticScroller()
            scroller.scrollBy(diff)
            self.startScrolling(scroller)
        return ret

    def kineticAddDelta(self, diff):
        """Add diff (QPoint) to an existing kinetic scroll.

        If no scroll is active, a new one is started (like kineticScrollBy).

        """
        if isinstance(self._scroller, KineticScroller):
            self._scroller.scrollBy(self._scroller.remainingDistance() + diff)
        else:
            self.kineticScrollBy(diff)

    def steadyScroll(self, diff):
        """Start steadily scrolling diff (QPoint) pixels per second.

        Stops automatically when the end is reached.

        """
        if diff:
            self.startScrolling(SteadyScroller(diff, self.scrollupdatespersec))
        else:
            self.stopScrolling()

    def startScrolling(self, scroller):
        """Begin a scrolling operation using the specified scroller."""
        self._scroller = scroller
        if not self._scrollTimer.isActive():
            self._scrollTimer.start(1000 / self.scrollupdatespersec, self)

    def stopScrolling(self):
        """Stop scrolling."""
        if self._scroller:
            self._scrollTimer.stop()
            self._scroller = None

    def isScrolling(self):
        """Return True if a scrolling movement is active."""
        return bool(self._scroller)

    def timerEvent(self, ev):
        """Called by the _scrollTimer."""
        diff = self._scroller.step()
        # when scrolling slowly, it might be that no redraw is needed
        if diff:
            # change the scrollbars, but check how far they really moved.
            if not self.scrollBy(diff) or self._scroller.finished():
                self.stopScrolling()
开发者ID:19joho66,项目名称:frescobaldi,代码行数:104,代码来源:scrollarea.py

示例13: ReversiWindow

# 需要导入模块: from PyQt5.QtCore import QBasicTimer [as 别名]
# 或者: from PyQt5.QtCore.QBasicTimer import start [as 别名]
class ReversiWindow(QMainWindow):
    def __init__(self, board_size, game_mode, game_difficulty_level,
                 game_time_for_move):
        super().__init__()
        self.images = {}
        self.init_ui(board_size, game_mode, game_difficulty_level,
                     game_time_for_move)

    def init_ui(self, board_size, game_mode, game_difficulty_level,
                game_time_for_move):
        self.game = Game(board_size, mode=game_mode,
                         difficulty_level=game_difficulty_level,
                         is_console_game=False,
                         time_for_move=game_time_for_move)
        self.game_was_saved = False
        self.time_for_move = game_time_for_move
        self.count = self.time_for_move
        self.timer = QBasicTimer()
        self.move_timer = QTimer()
        self.ai_thread = AIThread(self)
        self.ai_thread.finished.connect(self.ai_finish)
        self.ai_finished = True
        self.load_images()
        self.add_toolbar()
        self.font_size = 10
        self.resize(board_size * s.IMG_SIZE,
                    (board_size * s.IMG_SIZE + self.toolbar.height() + 10 +
                     self.font_size))
        self.center()
        self.setWindowTitle('Reversi')
        self.show()
        self.timer.start(1, self)
        self.move_timer.timeout.connect(self.count_down)
        self.move_timer.start(1000)

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

    def add_toolbar(self):
        self.toolbar = self.addToolBar('')
        self.add_toolbar_action(self.toolbar, 'Save', 'save.png', self.save,
                                'Ctrl+S')
        self.add_toolbar_action(self.toolbar, 'Undo', 'undo.png', self.undo,
                                'Ctrl+Z')
        self.add_toolbar_action(self.toolbar, 'Redo', 'redo.png', self.redo)
        self.toolbar.setMovable(False)

    def add_toolbar_action(self, toolbar, name, image, function,
                           shortcut=None):
        action = QAction(QIcon(QPixmap(self.images[image])), name, self)
        if shortcut is not None:
            action.setShortcut(shortcut)
        action.triggered.connect(function)
        toolbar.addAction(action)

    def save(self):
        if self.game.game_state == Game.States.human:
            with open('saved_game.pickle', 'wb') as f:
                pickle.dump(self.game, f, protocol=pickle.HIGHEST_PROTOCOL)
            self.game_was_saved = True

    def undo(self):
        if self.game.game_state == Game.States.human:
            self.reset_count()
            self.game.undo()

    def redo(self):
        if self.game.game_state == Game.States.human:
            self.reset_count()
            self.game.redo()

    def draw_cell(self, painter, cell):
        if cell.state == s.BLACK:
            image = self.images['black.png']
        elif cell.state == s.WHITE:
            image = self.images['white.png']
        elif (cell.get_coordinates() in self.game.mover.next_possible_moves and
              self.game.game_state != Game.States.ai):
            image = self.images['possible_move.png']
        else:
            image = self.images['empty.png']
        painter.drawImage(
            cell.y*s.IMG_SIZE,
            cell.x*s.IMG_SIZE + self.toolbar.height() + self.font_size,
            image)

    def draw_text(self, painter, font_size):
        painter.setPen(QColor(Qt.black))
        painter.setFont(QFont('Decorative', font_size))
        painter.drawText(QPoint(10, self.toolbar.height() + font_size),
                         'Time left for move: {}'.format(self.count))

    def reset_count(self):
            if not self.ai_thread.isRunning():
                self.count = self.time_for_move

    def count_down(self):
#.........这里部分代码省略.........
开发者ID:ElenaArslanova,项目名称:rev,代码行数:103,代码来源:reversi.py

示例14: Example

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

#.........这里部分代码省略.........

        grnb = QPushButton('Green', self)
        grnb.setCheckable(True)
        grnb.move(10, 60)
        grnb.clicked[bool].connect(self.setColor)

        blueb = QPushButton('Blue', self)
        blueb.setCheckable(True)
        blueb.move(10, 90)
        blueb.clicked[bool].connect(self.setColor)

        self.square = QFrame(self)
        self.square.setGeometry(150, 20, 50, 50)
        self.square.setStyleSheet("QWidget { background-color: %s}" %
                                  self.col.name())

        # slider 滚动条
        sld = QSlider(Qt.Horizontal, self)
        sld.setFocusPolicy(Qt.NoFocus)
        sld.setGeometry(10, 120, 100, 10)
        sld.valueChanged[int].connect(self.changeValue)

        self.label = QLabel(self)
        self.label.setPixmap(QPixmap('1.png'))
        self.label.setGeometry(150, 90, 80, 80)

        # 进度条ProgressBar
        self.pbar = QProgressBar(self)
        self.pbar.setGeometry(10, 170, 200, 20)
        self.btn = QPushButton('Start', self)
        self.btn.move(10, 200)
        self.btn.clicked.connect(self.doAction)

        self.timer = QBasicTimer()
        self.step = 0

        # Calendar 日历
        cal = QCalendarWidget(self)
        cal.setGridVisible(True)
        cal.move(10, 230)
        cal.clicked[QDate].connect(self.showDate)
        self.lbl = QLabel(self)
        date = cal.selectedDate()
        self.lbl.setText(date.toString())
        self.lbl.move(80, 440)

        self.setGeometry(300, 200, 300, 500)
        self.setWindowTitle('Toggle')
        self.show()

    def changeTitle(self, state):
        if state == Qt.Checked:
            self.setWindowTitle('Toogle')
        else:
            self.setWindowTitle(' ')

    def setColor(self, pressed):
        source = self.sender()
        if pressed:
            val = 255
        else:
            val = 0

        if source.text() == "Red":
            self.col.setRed(val)
        elif source.text() == "Green":
            self.col.setGreen(val)
        else:
            self.col.setBlue(val)

        self.square.setStyleSheet("QFrame {background-color: %s}" % self.col.name())

    def changeValue(self, value):
        if value == 0:
            self.label.setPixmap(QPixmap('1.png'))
        elif 0 < value <= 30:
            self.label.setPixmap(QPixmap('2.png'))
        elif 30 < value < 80:
            self.label.setPixmap(QPixmap('3.png'))
        else:
            self.label.setPixmap(QPixmap('4.png'))

    def timerEvent(self, *args, **kwargs):
        if self.step >= 100:
            self.timer.stop()
            self.btn.setText('Finished')
            return
        self.step += 1
        self.pbar.setValue(self.step)

    def doAction(self):
        if self.timer.isActive():
            self.timer.stop()
            self.btn.setText('Start')
        else:
            self.timer.start(100, self)
            self.btn.setText('Stop')

    def showDate(self, date):
        self.lbl.setText(date.toString())
开发者ID:HappyJamesL,项目名称:pyqtlearn,代码行数:104,代码来源:widget.py

示例15: LightMaps

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

#.........这里部分代码省略.........
                self.zoomPixmap.fill(Qt.lightGray)
    
            if True:
                p = QPainter(self.zoomPixmap)
                p.translate(-xy)
                self._largeMap.render(p, QRect(xy, box))
                p.end()

            clipPath = QPainterPath()
            clipPath.addEllipse(QPointF(center), ring, ring)
            p = QPainter(self)
            p.setRenderHint(QPainter.Antialiasing)
            p.setClipPath(clipPath)
            p.drawPixmap(corner, self.zoomPixmap)
            p.setClipping(False)
            p.drawPixmap(corner, self.maskPixmap)
            p.setPen(Qt.gray)
            p.drawPath(clipPath)

        if self.invert:
            p = QPainter(self)
            p.setCompositionMode(QPainter.CompositionMode_Difference)
            p.fillRect(event.rect(), Qt.white)
            p.end()

    def timerEvent(self, event):
        if not self.zoomed:
            self.activateZoom()

        self.update()
 
    def mousePressEvent(self, event):
        if event.buttons() != Qt.LeftButton:
            return

        self.pressed = self.snapped = True
        self.pressPos = self.dragPos = event.pos()
        self.tapTimer.stop()
        self.tapTimer.start(HOLD_TIME, self)

    def mouseMoveEvent(self, event):
        if not event.buttons():
            return

        if not self.zoomed:
            if not self.pressed or not self.snapped:
                delta = event.pos() - self.pressPos
                self.pressPos = event.pos()
                self._normalMap.pan(delta)
                return
            else:
                threshold = 10
                delta = event.pos() - self.pressPos
                if self.snapped:
                    self.snapped &= delta.x() < threshold
                    self.snapped &= delta.y() < threshold
                    self.snapped &= delta.x() > -threshold
                    self.snapped &= delta.y() > -threshold

                if not self.snapped:
                    self.tapTimer.stop()

        else:
            self.dragPos = event.pos()
            self.update()

    def mouseReleaseEvent(self, event):
        self.zoomed = False
        self.update()
 
    def keyPressEvent(self, event):
        if not self.zoomed:
            if event.key() == Qt.Key_Left:
                self._normalMap.pan(QPoint(20, 0))
            if event.key() == Qt.Key_Right:
                self._normalMap.pan(QPoint(-20, 0))
            if event.key() == Qt.Key_Up:
                self._normalMap.pan(QPoint(0, 20))
            if event.key() == Qt.Key_Down:
                self._normalMap.pan(QPoint(0, -20))
            if event.key() == Qt.Key_Z or event.key() == Qt.Key_Select:
                self.dragPos = QPoint(self.width() / 2, self.height() / 2)
                self.activateZoom()
        else:
            if event.key() == Qt.Key_Z or event.key() == Qt.Key_Select:
                self.zoomed = False
                self.update()

            delta = QPoint(0, 0)
            if event.key() == Qt.Key_Left:
                delta = QPoint(-15, 0)
            if event.key() == Qt.Key_Right:
                delta = QPoint(15, 0)
            if event.key() == Qt.Key_Up:
                delta = QPoint(0, -15)
            if event.key() == Qt.Key_Down:
                delta = QPoint(0, 15)
            if delta != QPoint(0, 0):
                self.dragPos += delta
                self.update()
开发者ID:Axel-Erfurt,项目名称:pyqt5,代码行数:104,代码来源:lightmaps.py


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