Skip to content

Commit

Permalink
rename to on_self_event
Browse files Browse the repository at this point in the history
short is good
  • Loading branch information
LondonClass committed Feb 13, 2024
1 parent 01641fe commit e728e60
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
14 changes: 7 additions & 7 deletions pygame_gui/elements/ui_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class UIButton(UIElement):
unique event.
:param visible: Whether the element is visible by default. Warning - container visibility may
override this.
:param command: Functions to be called when an element event occurs.
:param command: Functions to be called when an event triggered by this element.
:param text_kwargs: a dictionary of variable arguments to pass to the translated string
useful when you have multiple translations that need variables inserted
in the middle.
Expand Down Expand Up @@ -329,9 +329,9 @@ def process_event(self, event: pygame.event.Event) -> bool:
if self.is_enabled:
if (self.allow_double_clicks and self.last_click_button == event.button and
self.double_click_timer <= self.ui_manager.get_double_click_time()):
self.on_element_event(UI_BUTTON_DOUBLE_CLICKED, {'mouse_button':event.button})
self.on_self_event(UI_BUTTON_DOUBLE_CLICKED, {'mouse_button':event.button})
else:
self.on_element_event(UI_BUTTON_START_PRESS, {'mouse_button':event.button})
self.on_self_event(UI_BUTTON_START_PRESS, {'mouse_button':event.button})
self.double_click_timer = 0.0
self.last_click_button = event.button
self.held = True
Expand All @@ -349,7 +349,7 @@ def process_event(self, event: pygame.event.Event) -> bool:
self._set_inactive()
consumed_event = True
self.pressed_event = True
self.on_element_event(UI_BUTTON_PRESSED, {'mouse_button':event.button})
self.on_self_event(UI_BUTTON_PRESSED, {'mouse_button':event.button})

if self.is_enabled and self.held:
self.held = False
Expand Down Expand Up @@ -384,12 +384,12 @@ def bind(self, event:int, function:Callable = None):
else:
raise TypeError("Command function must be callable")

def on_element_event(self, event:int, data:Dict[str, Any]=None):
def on_self_event(self, event:int, data:Dict[str, Any]=None):
"""
Called when an element event occurs. Handles these events either by posting the event back
Called when a event triggered by this element. Handles these events either by posting the event back
to the event queue, or by running a function supplied by the user.
:param event: The event occurs.
:param event: The event triggered.
:param data: event data
Expand Down
12 changes: 6 additions & 6 deletions tests/test_elements/test_ui_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ def function_with_3_params(x, y, z):
with pytest.raises(ValueError):
button.bind(pygame_gui.UI_BUTTON_PRESSED, function_with_3_params)

def test_on_element_event(self, _init_pygame: None, default_ui_manager: UIManager,
def test_on_self_event(self, _init_pygame: None, default_ui_manager: UIManager,
_display_surface_return_none):
button_start_press = False

Expand All @@ -546,14 +546,14 @@ def test_function2(data):
assert pygame_gui.UI_BUTTON_DOUBLE_CLICKED not in button._handler

assert not button_start_press
button.on_element_event(pygame_gui.UI_BUTTON_START_PRESS, {'mouse_button':1})
button.on_self_event(pygame_gui.UI_BUTTON_START_PRESS, {'mouse_button':1})
assert button_start_press

assert pressed_button == 0
button.on_element_event(pygame_gui.UI_BUTTON_PRESSED, {'mouse_button':3})
button.on_self_event(pygame_gui.UI_BUTTON_PRESSED, {'mouse_button':3})
assert pressed_button == 3

button.on_element_event(pygame_gui.UI_BUTTON_DOUBLE_CLICKED, {'mouse_button':1})
button.on_self_event(pygame_gui.UI_BUTTON_DOUBLE_CLICKED, {'mouse_button':1})

confirm_double_click_event_fired = False
for event in pygame.event.get():
Expand All @@ -562,7 +562,7 @@ def test_function2(data):
confirm_double_click_event_fired = True
assert confirm_double_click_event_fired

def test_on_element_event_no_params(self, _init_pygame: None, default_ui_manager: UIManager,
def test_on_self_event_no_params(self, _init_pygame: None, default_ui_manager: UIManager,
_display_surface_return_none):
button_start_press = False

Expand All @@ -579,7 +579,7 @@ def test_function():
command=command_dict)

assert not button_start_press
button.on_element_event(pygame_gui.UI_BUTTON_START_PRESS, {'mouse_button':1})
button.on_self_event(pygame_gui.UI_BUTTON_START_PRESS, {'mouse_button':1})
assert button_start_press


Expand Down

0 comments on commit e728e60

Please sign in to comment.