diff options
author | Florent Le Coz <louiz@louiz.org> | 2014-08-01 01:22:59 +0200 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2014-08-01 01:22:59 +0200 |
commit | 87cf38995a283e4a476fd124fcc55e0f80edf1ad (patch) | |
tree | 54e434be6a56ae5d501d4c2e769dd7ca1cbb4009 /src/tabs | |
parent | 55daf9d49df4a0e0774b27acd33735abf80f80dd (diff) | |
download | poezio-87cf38995a283e4a476fd124fcc55e0f80edf1ad.tar.gz poezio-87cf38995a283e4a476fd124fcc55e0f80edf1ad.tar.bz2 poezio-87cf38995a283e4a476fd124fcc55e0f80edf1ad.tar.xz poezio-87cf38995a283e4a476fd124fcc55e0f80edf1ad.zip |
Make the TimedEvents work with asyncio
Improvements: events now occur precisely at the specified date. You don’t
need to stop touching your keyboard to execute them.
Diffstat (limited to 'src/tabs')
-rw-r--r-- | src/tabs/basetabs.py | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/src/tabs/basetabs.py b/src/tabs/basetabs.py index c2efc9bc..95e47e4e 100644 --- a/src/tabs/basetabs.py +++ b/src/tabs/basetabs.py @@ -624,17 +624,12 @@ class ChatTab(Tab): """ if not config.get_by_tabname('send_chat_states', True, self.general_jid, True): return - if self.timed_event_paused: - # check the weakref - event = self.timed_event_paused() - if event: - # the event already exists: we just update - # its date - event.change_date(datetime.now() + timedelta(seconds=4)) - return + # First, cancel the delay if it already exists, before rescheduling + # it at a new date + self.cancel_paused_delay() new_event = timed_events.DelayedEvent(4, self.send_chat_state, 'paused') self.core.add_timed_event(new_event) - self.timed_event_paused = weakref.ref(new_event) + self.timed_event_paused = new_event def cancel_paused_delay(self): """ @@ -642,12 +637,9 @@ class ChatTab(Tab): Called for example when the input is emptied, or when the message is sent """ - if self.timed_event_paused: - event = self.timed_event_paused() - if event: - self.core.remove_timed_event(event) - del event - self.timed_event_paused = None + if self.timed_event_paused is not None: + self.core.remove_timed_event(self.timed_event_paused) + self.timed_event_paused = None def command_correct(self, line): """ |