Add cancel_timeout method

This method is useful when the keymap needs to use
state.set_timeout() and this timeout needs to be
cancellable.

Also, the set_timeout() now returns a timer handle.
This commit is contained in:
Elvis Pfützenreuter 2019-04-26 18:54:08 -03:00
parent 9c4a136989
commit f9b56d82f7

View File

@ -67,8 +67,15 @@ class InternalState:
else:
timeout_key = ticks_ms() + after_ticks
while timeout_key in self.timeouts:
timeout_key += 1
self.timeouts[timeout_key] = callback
return self
return timeout_key
def cancel_timeout(self, timeout_key):
if timeout_key in self.timeouts:
del self.timeouts[timeout_key]
def process_timeouts(self):
if not self.timeouts: