Skip to content

Commit

Permalink
Rename 'handler' to '_handler'
Browse files Browse the repository at this point in the history
  • Loading branch information
LondonClass committed Feb 13, 2024
1 parent 42a9985 commit 9fafaff
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 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 @@ -135,15 +135,15 @@ def __init__(self, relative_rect: Union[pygame.Rect, Tuple[float, float], pygame

self.state_transitions = {}

self.handler = {}
self._handler = {}
if command is not None:
if callable(command):
self.bind(UI_BUTTON_PRESSED, command)
else:
for key, value in command.items():
self.bind(key, value)

if UI_BUTTON_DOUBLE_CLICKED in self.handler:
if UI_BUTTON_DOUBLE_CLICKED in self._handler:
self.allow_double_clicks = True

Check warning on line 147 in pygame_gui/elements/ui_button.py

View check run for this annotation

Codecov / codecov/patch

pygame_gui/elements/ui_button.py#L147

Added line #L147 was not covered by tests

self.rebuild_from_changed_theme_data()
Expand Down Expand Up @@ -368,15 +368,15 @@ def bind(self, event:int, function:Callable = None):
"""
if function is None:
self.handler.pop(event, None)
self._handler.pop(event, None)
return

if callable(function):
num_params = len(signature(function).parameters)
if num_params == 1:
self.handler[event] = function
self._handler[event] = function
elif num_params == 0:
self.handler[event] = lambda _:function()
self._handler[event] = lambda _:function()
else:
raise ValueError("Button command function signatures can have 0 or 1 parameter. "
"If one parameter is set it will contain data for the id of the mouse button used "
Expand All @@ -397,8 +397,8 @@ def on_button_event(self, event:int, data:Dict[str, Any]=None):
if data is None:
data = {}

Check warning on line 398 in pygame_gui/elements/ui_button.py

View check run for this annotation

Codecov / codecov/patch

pygame_gui/elements/ui_button.py#L398

Added line #L398 was not covered by tests

if event in self.handler:
self.handler[event](data)
if event in self._handler:
self._handler[event](data)
else:
# old event to remove in 0.8.0
event_data = {'user_type': OldType(event),
Expand Down
14 changes: 7 additions & 7 deletions tests/test_elements/test_ui_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ def test_function(data):
manager=default_ui_manager,
command=test_function)

assert button.handler[pygame_gui.UI_BUTTON_PRESSED] == test_function
assert button._handler[pygame_gui.UI_BUTTON_PRESSED] == test_function

assert not button_clicked
# process a mouse button down event
Expand Down Expand Up @@ -498,13 +498,13 @@ def test_function(data):
tool_tip_text="This is a test of the button's tool tip functionality.",
manager=default_ui_manager)

assert pygame_gui.UI_BUTTON_PRESSED not in button.handler
assert pygame_gui.UI_BUTTON_PRESSED not in button._handler

button.bind(pygame_gui.UI_BUTTON_PRESSED, test_function)
assert button.handler[pygame_gui.UI_BUTTON_PRESSED] == test_function
assert button._handler[pygame_gui.UI_BUTTON_PRESSED] == test_function

button.bind(pygame_gui.UI_BUTTON_PRESSED, None)
assert pygame_gui.UI_BUTTON_PRESSED not in button.handler
assert pygame_gui.UI_BUTTON_PRESSED not in button._handler

with pytest.raises(TypeError, match="Button command function must be callable"):
button.bind(pygame_gui.UI_BUTTON_PRESSED, "non-callable")
Expand Down Expand Up @@ -537,9 +537,9 @@ def test_function2(data):
manager=default_ui_manager,
command=command_dict)

assert button.handler[pygame_gui.UI_BUTTON_START_PRESS] == test_function # not
assert button.handler[pygame_gui.UI_BUTTON_PRESSED] == test_function2
assert pygame_gui.UI_BUTTON_DOUBLE_CLICKED not in button.handler
assert button._handler[pygame_gui.UI_BUTTON_START_PRESS] == test_function # not
assert button._handler[pygame_gui.UI_BUTTON_PRESSED] == test_function2
assert pygame_gui.UI_BUTTON_DOUBLE_CLICKED not in button._handler

assert not button_start_press
button.on_button_event(pygame_gui.UI_BUTTON_START_PRESS, {'mouse_button':1})
Expand Down

0 comments on commit 9fafaff

Please sign in to comment.