diff --git a/weboob/tools/application/qt.py b/weboob/tools/application/qt.py index b007d25b..2d4cc93a 100644 --- a/weboob/tools/application/qt.py +++ b/weboob/tools/application/qt.py @@ -19,6 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. """ import sys +from PyQt4.QtCore import QTimer, SIGNAL from PyQt4.QtGui import QMainWindow, QApplication from weboob import Weboob @@ -31,6 +32,29 @@ __all__ = ['QtApplication'] class QtScheduler(Scheduler): def __init__(self, app): self.app = app + 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 + + 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 + + def timeout(self, _id, single, function, *args): + function(*args) + if single: + self.timers.pop(_id) + + def want_stop(self): + self.app.quit() def run(self): self.app.exec_()