Fixed issue with timer drift.

This commit is contained in:
Dain Nilsson 2015-10-12 10:19:55 +02:00
parent 17bcc80bd5
commit d5803b9fb6
2 changed files with 6 additions and 7 deletions

2
NEWS
View File

@ -1,4 +1,6 @@
* Version 2.2.2 (unreleased)
** Re-schedule timer each time period based on system time to prevent Qt timer
drift.
* Version 2.2.1 (released 2015-08-20)
** Bugfix release: Fix adding credentials via the UI.

View File

@ -152,17 +152,14 @@ class Timer(QtCore.QObject):
now = time()
rem = now % interval
QtCore.QTimer.singleShot((self._interval - rem) * 1000, self.start_timer)
self._time = int(now - rem)
QtCore.QTimer.singleShot((self._interval - rem) * 1000, self._tick)
def start_timer(self):
self.startTimer(self._interval * 1000)
self.timerEvent(QtCore.QEvent(QtCore.QEvent.None))
def timerEvent(self, event):
def _tick(self):
self._time += self._interval
self.time_changed.emit(self._time)
event.accept()
next_time = self._time + self._interval
QtCore.QTimer.singleShot((next_time - time()) * 1000, self._tick)
@property
def time(self):