This commit is contained in:
Will McGugan
2021-06-06 12:56:14 +01:00
parent d54aaa3fec
commit b89d81e382
2 changed files with 21 additions and 5 deletions

View File

@@ -92,6 +92,7 @@ class Idle(Event, type=EventType.IDLE):
class Resize(Event, type=EventType.RESIZE):
__slots__ = ["width", "height"]
width: int
height: int
@@ -119,7 +120,7 @@ class Shutdown(Event, type=EventType.SHUTDOWN):
@rich_repr
class Key(Event, type=EventType.KEY, bubble=True):
code: int = 0
__slots__ = ["code"]
def __init__(self, sender: MessageTarget, code: int) -> None:
super().__init__(sender)
@@ -136,6 +137,8 @@ class Key(Event, type=EventType.KEY, bubble=True):
@rich_repr
class Move(Event, type=EventType.MOVE):
__slots__ = ["x", "y"]
def __init__(self, sender: MessageTarget, x: int, y: int) -> None:
super().__init__(sender)
self.x = x
@@ -148,6 +151,8 @@ class Move(Event, type=EventType.MOVE):
@rich_repr
class _MouseBase(Event, type=EventType.PRESS):
__slots__ = ["x", "y", "button", "alt", "ctrl", "shift"]
def __init__(
self,
sender: MessageTarget,
@@ -193,6 +198,8 @@ class DoubleClick(_MouseBase, type=EventType.DOUBLE_CLICK):
@rich_repr
class Timer(Event, type=EventType.TIMER, priority=10):
__slots__ = ["time", "count", "callback"]
def __init__(
self,
sender: MessageTarget,
@@ -211,6 +218,8 @@ class Timer(Event, type=EventType.TIMER, priority=10):
@rich_repr
class Enter(Event, type=EventType.ENTER):
__slots__ = ["x", "y"]
def __init__(self, sender: MessageTarget, x: int, y: int) -> None:
super().__init__(sender)
self.x = x
@@ -234,5 +243,5 @@ class Blur(Event, type=EventType.BLUR):
class Update(Event, type=EventType.UPDATE):
def can_batch(self, event: Event) -> bool:
def can_batch(self, event: Message) -> bool:
return isinstance(event, Update) and event.sender == self.sender

View File

@@ -9,17 +9,24 @@ from ._types import MessageTarget
class Message:
"""Base class for a message."""
__slots__ = [
"sender",
"name",
"time",
"_no_default_action",
"_stop_propagation",
]
sender: MessageTarget
bubble: ClassVar[bool] = False
default_priority: ClassVar[int] = 0
_no_default_action: bool = False
_stop_propagaton: bool = False
def __init__(self, sender: MessageTarget) -> None:
self.sender = sender
self.name = camel_to_snake(self.__class__.__name__)
self.time = monotonic()
self._no_default_action = False
self._stop_propagaton = False
super().__init__()
def __init_subclass__(cls, bubble: bool = False, priority: int = 0) -> None: