Type DelayedEvent, also in Core.
This commit is contained in:
parent
edbbf759ce
commit
a6c5ac486b
2 changed files with 9 additions and 7 deletions
|
@ -41,6 +41,7 @@ from poezio.roster import roster
|
|||
from poezio.size_manager import SizeManager
|
||||
from poezio.user import User
|
||||
from poezio.text_buffer import TextBuffer
|
||||
from poezio.timed_events import DelayedEvent
|
||||
from poezio.theming import get_theme
|
||||
from poezio import keyboard, xdg
|
||||
|
||||
|
@ -776,11 +777,11 @@ class Core:
|
|||
|
||||
########################## TImed Events #######################################
|
||||
|
||||
def remove_timed_event(self, event):
|
||||
def remove_timed_event(self, event: DelayedEvent) -> None:
|
||||
"""Remove an existing timed event"""
|
||||
event.handler.cancel()
|
||||
|
||||
def add_timed_event(self, event):
|
||||
def add_timed_event(self, event: DelayedEvent) -> None:
|
||||
"""Add a new timed event"""
|
||||
event.handler = asyncio.get_event_loop().call_later(
|
||||
event.delay, event.callback, *event.args)
|
||||
|
|
|
@ -13,7 +13,8 @@ Once created, they must be added to the list of checked events with
|
|||
"""
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Callable, Union
|
||||
from asyncio import Handle
|
||||
from typing import Callable, Union, Optional, Tuple, Any
|
||||
|
||||
|
||||
class DelayedEvent:
|
||||
|
@ -31,11 +32,11 @@ class DelayedEvent:
|
|||
:param function callback: The handler that will be executed.
|
||||
:param args: Optional arguments passed to the handler.
|
||||
"""
|
||||
self.callback = callback
|
||||
self.args = args
|
||||
self.delay = delay
|
||||
self.callback = callback # type: Callable
|
||||
self.args = args # type: Tuple[Any, ...]
|
||||
self.delay = delay # type: Union[int, float]
|
||||
# An asyncio handler, as returned by call_later() or call_at()
|
||||
self.handler = None
|
||||
self.handler = None # type: Optional[Handle]
|
||||
|
||||
|
||||
class TimedEvent(DelayedEvent):
|
||||
|
|
Loading…
Reference in a new issue