python - Update QWidget every minutes -


is way possible update qwidget in pyqt4 every 15 minutes ? know qtimer possible make qwidget update @ specific time,for example 00h00 00h15 00h30 00h45 01h00,... . way make qtimer depend on time?

the qtimer class has setinterval method. can utilize change wait time on fly. short example, block of code show current second. however, if second multiple of 10 wait 5 seconds before starting again:

import sys pyqt4 import qtgui, qtcore time import strftime  class main(qtgui.qmainwindow):     def __init__(self):         qtgui.qmainwindow.__init__(self)         self.initui()      def initui(self):         self.timer = qtcore.qtimer(self)         self.timer.timeout.connect(self.time)         self.timer.start(1000)         self.lcd = qtgui.qlcdnumber(self)         self.lcd.display(strftime("%s"))         self.setcentralwidget(self.lcd)         self.setgeometry(300,300,250,100)      def time(self):         if int(strftime("%s")) % 10 == 0:             self.timer.setinterval(5000)         else:             self.timer.setinterval(1000)         self.lcd.display(strftime("%s"))  def main():     app = qtgui.qapplication(sys.argv)     main = main()     main.show()     sys.exit(app.exec_())  if __name__ == "__main__":     main() 

(this modified tutorial showing how build digital clock)

it looks 4 consecutive changes of display:

seconds


for particular problem, when start application, can find how long until next quarter hour via function presented in answer:

def next_quarter_hour(self):     dt = datetime.datetime.now()     nsecs = dt.minute*60+dt.second+dt.microsecond*1e-6       delta = (nsecs//900)*900+900-nsecs     return delta * 1000.0 

this change following:

def initui(self):     ...     self.timer.start(next_qt_hour)     ...  def time(self):     if int(strftime("%m")) % 15 == 0:         self.timer.setinterval(900000)     self.lcd.display(strftime("%m")) 

use set first interval. once timer has been exhausted, reset interval 15 minutes.


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -