implement scheduler functions
This commit is contained in:
parent
eb3b8a7165
commit
e88247e495
1 changed files with 24 additions and 0 deletions
|
|
@ -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_()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue