summaryrefslogtreecommitdiff
path: root/src/timed_events.py
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2011-04-10 03:52:46 +0200
committerFlorent Le Coz <louiz@louiz.org>2011-04-10 03:52:46 +0200
commita6c56682b74acb7ef568913bbc964b4f17cf3202 (patch)
treea69f53ea655b34831bbff0572dcc487429057f9e /src/timed_events.py
parent35b6e146cb6a0b313d6297f0d91654aa21f58c1b (diff)
downloadpoezio-a6c56682b74acb7ef568913bbc964b4f17cf3202.tar.gz
poezio-a6c56682b74acb7ef568913bbc964b4f17cf3202.tar.bz2
poezio-a6c56682b74acb7ef568913bbc964b4f17cf3202.tar.xz
poezio-a6c56682b74acb7ef568913bbc964b4f17cf3202.zip
Implement paused chate state. fixed #2124
Diffstat (limited to 'src/timed_events.py')
-rw-r--r--src/timed_events.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/timed_events.py b/src/timed_events.py
index 7cb92cde..66d3449e 100644
--- a/src/timed_events.py
+++ b/src/timed_events.py
@@ -31,6 +31,7 @@ class TimedEvent(object):
Note that these events can NOT be used for very small delay or a very
precise date, since the check for events is done once per second, as
a maximum.
+ The callback and its arguments should be passed as the lasts arguments.
"""
def __init__(self, date, callback, *args):
self._callback = callback
@@ -57,12 +58,24 @@ class TimedEvent(object):
else:
return False
+ def change_date(self, date):
+ """
+ Simply change the date of the event
+ """
+ self.next_call_date = date
+
+ def add_delay(self, delay):
+ """
+ Add a delay (in seconds) to the date
+ """
+ self.next_call_date += datetime.timedelta(seconds=delay)
+
class DelayedEvent(TimedEvent):
"""
The date is calculated from now + a delay in seconds
Use it if you want an event to happen in, e.g. 6 seconds
"""
def __init__(self, delay, callback, *args):
- date = datetime.datetime.now() + datetime.timedelta(0, delay)
+ date = datetime.datetime.now() + datetime.timedelta(seconds=delay)
TimedEvent.__init__(self, date, callback, args)