2009/11/9 Jérôme Laheurte <[email protected]>:
> It seems the reminders don't work anymore. After some digging, I found
> out that the clock.time event is fired a few milliseconds too early;
> so when rounding it to get the event type, it falls one second short.
> The obvious but not so clean way to "fix" this would be to change
> domain/date/clock.py and put
>
> super(OnceTimer, self).Start(timeDelta.milliseconds() + 100)
>
> instead of
>
> super(OnceTimer, self).Start(timeDelta.milliseconds())
>
> but it seems like a hack :( Seems to work though. What do you think ?
How about having OnceTimer remember at which time it should fire and
then pass that time to the callback so the callback can use the
requested time instead of the actual time?
class OnceTimer(LargeIntervalTimer):
''' OnceTimer allows for scheduling a callback at a specific date and
time. '''
def __init__(self, callback, dateTime=None, now=None):
self.__callback = callback
super(OnceTimer, self).__init__(self._notify)
if dateTime:
self.Start(dateTime, now)
def Start(self, dateTime, now=None): # pylint: disable-msg=W0221
self.__requestedDateTime = dateTime
now = now or dateandtime.DateTime.now()
timeDelta = dateTime - now
super(OnceTimer, self).Start(timeDelta.milliseconds())
def _notify(self, now=None):
now = now or self.__requestedDateTime
self.__callback(now)
Cheers, Frank