Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions arcade/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from arcade.gui.events import UIOnChangeEvent
from arcade.gui.events import UIOnClickEvent
from arcade.gui.events import UIOnUpdateEvent
from arcade.gui.events import UITextEvent
from arcade.gui.events import UITextInputEvent
from arcade.gui.events import UITextMotionEvent
from arcade.gui.events import UITextMotionSelectEvent
from arcade.gui.mixins import UIDraggableMixin
Expand Down Expand Up @@ -87,7 +87,7 @@
"UISpace",
"UISpriteWidget",
"UITextArea",
"UITextEvent",
"UITextInputEvent",
"UITextMotionEvent",
"UITextMotionSelectEvent",
"UITextureButton",
Expand Down
25 changes: 22 additions & 3 deletions arcade/gui/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,39 @@ class UIKeyReleaseEvent(UIKeyEvent):

@dataclass
class UITextEvent(UIEvent):
"""Covers all the text cursor event."""
"""Base class for text-related events.

It holds no data of its own.
"""

pass


@dataclass
class UITextInputEvent(UITextEvent):
"""Triggered whenever the user inputs any text.

Usually, this will be after :py:class:`UIKeyPressEvent` and before a
:py:class:`UIKeyReleaseEvent`. It may also occur when:

* the user holds down a key to repeat letters or spaces
* a platform-specific input method, such as pen input on a tablet PC

To learn more, see pyglet's `relevant documentation <https://pyglet.readthedocs.io/en/development/modules/window.html#pyglet.window.Window.on_text>`_.
"""

text: str


@dataclass
class UITextMotionEvent(UIEvent):
class UITextMotionEvent(UITextEvent):
"""Triggered when text cursor moves."""

motion: Any


@dataclass
class UITextMotionSelectEvent(UIEvent):
class UITextMotionSelectEvent(UITextEvent):
"""Triggered when the text cursor moves selecting the text with it."""

selection: Any
Expand Down
4 changes: 2 additions & 2 deletions arcade/gui/experimental/password_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

from typing import Optional

from arcade.gui import Surface, UIEvent, UIInputText, UITextEvent
from arcade.gui import Surface, UIEvent, UIInputText, UITextInputEvent


class UIPasswordInput(UIInputText):
"""A password input field. The text is hidden with asterisks."""

def on_event(self, event: UIEvent) -> Optional[bool]:
if isinstance(event, UITextEvent):
if isinstance(event, UITextInputEvent):
event.text = event.text.replace("\n", "").replace("\r", "") # remove new lines!
return super().on_event(event)

Expand Down
4 changes: 2 additions & 2 deletions arcade/gui/experimental/typed_text_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import arcade
from arcade.color import BLACK, RED, WHITE
from arcade.gui import UIEvent, UIInputText, UILabel, UITextEvent
from arcade.gui import UIEvent, UIInputText, UILabel, UITextInputEvent
from arcade.types import Color, RGBOrA255
from arcade.utils import type_name

Expand Down Expand Up @@ -150,7 +150,7 @@ def _checked_parse(self, text: str):

def on_event(self, event: UIEvent) -> Optional[bool]:
# print(f"In {type_name(event)}")
if isinstance(event, UITextEvent) and self._active:
if isinstance(event, UITextInputEvent) and self._active:
text = event.text.replace("\r", "").replace("\r", "")
event.text = text

Expand Down
4 changes: 2 additions & 2 deletions arcade/gui/ui_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
UIMouseReleaseEvent,
UIMouseScrollEvent,
UIOnUpdateEvent,
UITextEvent,
UITextInputEvent,
UITextMotionEvent,
UITextMotionSelectEvent,
)
Expand Down Expand Up @@ -402,7 +402,7 @@ def on_key_release(self, symbol: int, modifiers: int):
return self.dispatch_ui_event(UIKeyReleaseEvent(self, symbol, modifiers)) # type: ignore

def on_text(self, text):
return self.dispatch_ui_event(UITextEvent(self, text))
return self.dispatch_ui_event(UITextInputEvent(self, text))

def on_text_motion(self, motion):
return self.dispatch_ui_event(UITextMotionEvent(self, motion))
Expand Down
4 changes: 2 additions & 2 deletions arcade/gui/widgets/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
UIMouseEvent,
UIMousePressEvent,
UIMouseScrollEvent,
UITextEvent,
UITextInputEvent,
UITextMotionEvent,
UITextMotionSelectEvent,
)
Expand Down Expand Up @@ -449,7 +449,7 @@ def on_event(self, event: UIEvent) -> Optional[bool]:
# If active pass all non press events to caret
if self._active:
# Act on events if active
if isinstance(event, UITextEvent):
if isinstance(event, UITextInputEvent):
self.caret.on_text(event.text)
self.trigger_full_render()
elif isinstance(event, UITextMotionEvent):
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/gui/test_uimanager_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
UIMouseScrollEvent,
UIMouseMovementEvent,
UIKeyPressEvent,
UITextEvent,
UITextInputEvent,
UITextMotionEvent,
UITextMotionSelectEvent,
)
Expand Down Expand Up @@ -100,7 +100,7 @@ def test_on_text_passes_an_event(uimanager):
uimanager.on_text("a")

event = records[-1]
assert isinstance(event, UITextEvent)
assert isinstance(event, UITextInputEvent)
assert event.text == "a"


Expand Down