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


Python QDeclarativeView.setValue方法代码示例

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


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

示例1: SleepTimer

# 需要导入模块: from PyQt4.QtDeclarative import QDeclarativeView [as 别名]
# 或者: from PyQt4.QtDeclarative.QDeclarativeView import setValue [as 别名]

#.........这里部分代码省略.........
        self.blockValueSignal = False  # if this is true, valueChanged signal is not evaluated
        if self.forceSpinBoxWidget:
            self.sb_hours.valueChanged.connect(self.onValueChanged)
            self.sb_minutes.valueChanged.connect(self.onValueChanged)
        else:
            self.sb_hours_obj.currentIndexChanged.connect(self.onValueChanged)
            self.sb_minutes_obj.currentIndexChanged.connect(self.onValueChanged)


        # setup Timer which is started as soon as a value is changed in any of the spinboxes
        self.timer = QTimer()
        self.timer.setSingleShot(True)
        self.timer.setInterval(2000)  # 2 seconds until timer starts automatically
        self.connect(self.timer, SIGNAL("timeout()"), self.activate)

        #setup Timer which is a second-timer. It is startet with the self.timer (see self.active)
        self.countDown = QTimer()
        self.countDown.setInterval(1000) #sec
        self.connect(self.countDown, SIGNAL("timeout()"), self.check)

    def onValueChanged(self):

        if self.forceSpinBoxWidget:
            value_sb_hours = self.sb_hours.value()
            value_sb_minutes = self.sb_minutes.value()
        else:
            value_sb_hours = self.sb_hours_value.read().toInt()[0]
            value_sb_minutes = self.sb_minutes_value.read().toInt()[0]

        if self.blockValueSignal:
            return

        if value_sb_hours == 0 and value_sb_minutes == 0:
            print("Stop Timer")
            self.bomb_text.write("Abbruch")
            self.timer.stop()
            self.countDown.stop()
            self.isActive = False
            return

        if self.countDown.isActive():
            self.countDown.stop()

        if self.timer.isActive():
            self.timer.stop()
            self.timer.start()
        else:
            self.timer.start()

    def activate(self):
        #print("Activated")
        self.isActive = True
        self.countDown.start()
        if self.forceSpinBoxWidget:
            self.value = self.sb_hours.value() * 60 * 60 + self.sb_minutes.value() * 60
        else:
            self.value = self.sb_hours_value.read().toInt()[0] * 60 * 60 + self.sb_minutes_value.read().toInt()[0] * 60

    def check(self):
        #print("check")
        self.value -= 1
        if self.value == 0:
            #print("Der Timer ist abgelaufen")
            self.bomb_text.write(" Boom!")
            self.sleepTimerelapsed.emit()
            self.countDown.stop()
            self.isActive = False
        elif self.value == 10:
            self.sleepTimertenseconds.emit()
        else:
            m, s = divmod(self.value, 60)
            h, m = divmod(m, 60)
            text = "%02d:%02d:%02d" % (h, m, s)
            #self.lbl_countdown.setText(text)
            self.bomb_text.write(text)
            self.blockValueSignal = True
            if self.forceSpinBoxWidget:
                self.sb_hours.setValue(h)
                self.sb_minutes.setValue(m)
            else:
                self.sb_minutes_value.write(m)
                self.sb_hours_value.write(h)# = h
            self.blockValueSignal = False

    def stop(self, silent=True):
        if not silent:
            self.bomb_text.write("Abbruch")
        else:
            self.bomb_text.write("00:00:00")
        self.timer.stop()
        self.countDown.stop()
        self.blockValueSignal = True
        if self.forceSpinBoxWidget:
            self.sb_hours.setValue(0)
            self.sb_minutes.setValue(0)
        else:
            self.sb_minutes_value.write(0)
            self.sb_hours_value.write(0)
        self.blockValueSignal = False
        self.isActive = False
开发者ID:Acer54,项目名称:Webradio_v2,代码行数:104,代码来源:sleeptimer.py


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