implement scheduler functions

This commit is contained in:
Romain Bignon 2010-04-17 11:33:59 +02:00
commit e88247e495

View file

@ -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_()