From 41317e5029950d42416773b2e541804d34a5a53a Mon Sep 17 00:00:00 2001 From: Romain Bignon Date: Tue, 13 Jul 2010 23:44:22 +0200 Subject: [PATCH] fix QtScheduler and use it instead of QTimer --- weboob/applications/qhavesex/status.py | 11 +++------ weboob/tools/application/qt/qt.py | 32 ++++++++++++++++++-------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/weboob/applications/qhavesex/status.py b/weboob/applications/qhavesex/status.py index 6af4ed42..fc2c1f07 100644 --- a/weboob/applications/qhavesex/status.py +++ b/weboob/applications/qhavesex/status.py @@ -18,7 +18,7 @@ from __future__ import with_statement from PyQt4.QtGui import QWidget, QHBoxLayout, QVBoxLayout, QFrame, QLabel, QImage, QPixmap -from PyQt4.QtCore import SIGNAL, QTimer +from PyQt4.QtCore import SIGNAL from weboob.capabilities.dating import StatusField from weboob.tools.application.qt import QtDo @@ -49,17 +49,12 @@ class Account(QFrame): head.addWidget(self.title) head.addStretch() - self.body = QLabel() + self.body = QLabel(u'Waiting...') self.layout().addWidget(headw) self.layout().addWidget(self.body) - self.timer = QTimer() - self.timer.setSingleShot(False) - self.timer.setInterval(60) - self.connect(self.timer, SIGNAL('timeout()'), self.updateStats) - - self.updateStats() + self.weboob.repeat(60, self.updateStats) def updateStats(self): self.process = QtDo(self.weboob, self.updateStats_cb) diff --git a/weboob/tools/application/qt/qt.py b/weboob/tools/application/qt/qt.py index 71316bad..1b4d224c 100644 --- a/weboob/tools/application/qt/qt.py +++ b/weboob/tools/application/qt/qt.py @@ -31,26 +31,38 @@ __all__ = ['QtApplication', 'QtMainWindow', 'QtDo', 'HTMLDelegate'] class QtScheduler(IScheduler): def __init__(self, app): self.app = app + self.count = 0 self.timers = {} def schedule(self, interval, function, *args): timer = QTimer() - timer.setInterval(interval) - timer.setSingleShot(False) - self.app.connect(timer, SIGNAL("timeout()"), lambda: self.timeout(timer.timerId(), False, function, *args)) - self.timers[timer.timerId()] = timer + timer.setInterval(interval * 1000) + timer.setSingleShot(True) + + count = self.count + self.count += 1 + + timer.start() + self.app.connect(timer, SIGNAL("timeout()"), lambda: self.timeout(count, None, function, *args)) + self.timers[count] = timer def repeat(self, interval, function, *args): timer = QTimer() - timer.setInterval(interval) - timer.setSingleShot(True) - self.app.connect(timer, SIGNAL("timeout()"), lambda: self.timeout(timer.timerId(), True, function, *args)) - self.timers[timer.timerId()] = timer + timer.setSingleShot(False) - def timeout(self, _id, single, function, *args): + count = self.count + self.count += 1 + + timer.start(0) + self.app.connect(timer, SIGNAL("timeout()"), lambda: self.timeout(count, interval, function, *args)) + self.timers[count] = timer + + def timeout(self, _id, interval, function, *args): function(*args) - if single: + if interval is None: self.timers.pop(_id) + else: + self.timers[_id].setInterval(interval * 1000) def want_stop(self): self.app.quit()