Skip to content

Commit 9fafaff

Browse files
committed
Rename 'handler' to '_handler'
1 parent 42a9985 commit 9fafaff

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

pygame_gui/elements/ui_button.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,15 @@ def __init__(self, relative_rect: Union[pygame.Rect, Tuple[float, float], pygame
135135

136136
self.state_transitions = {}
137137

138-
self.handler = {}
138+
self._handler = {}
139139
if command is not None:
140140
if callable(command):
141141
self.bind(UI_BUTTON_PRESSED, command)
142142
else:
143143
for key, value in command.items():
144144
self.bind(key, value)
145145

146-
if UI_BUTTON_DOUBLE_CLICKED in self.handler:
146+
if UI_BUTTON_DOUBLE_CLICKED in self._handler:
147147
self.allow_double_clicks = True
148148

149149
self.rebuild_from_changed_theme_data()
@@ -368,15 +368,15 @@ def bind(self, event:int, function:Callable = None):
368368
369369
"""
370370
if function is None:
371-
self.handler.pop(event, None)
371+
self._handler.pop(event, None)
372372
return
373373

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

400-
if event in self.handler:
401-
self.handler[event](data)
400+
if event in self._handler:
401+
self._handler[event](data)
402402
else:
403403
# old event to remove in 0.8.0
404404
event_data = {'user_type': OldType(event),

tests/test_elements/test_ui_button.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ def test_function(data):
465465
manager=default_ui_manager,
466466
command=test_function)
467467

468-
assert button.handler[pygame_gui.UI_BUTTON_PRESSED] == test_function
468+
assert button._handler[pygame_gui.UI_BUTTON_PRESSED] == test_function
469469

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

501-
assert pygame_gui.UI_BUTTON_PRESSED not in button.handler
501+
assert pygame_gui.UI_BUTTON_PRESSED not in button._handler
502502

503503
button.bind(pygame_gui.UI_BUTTON_PRESSED, test_function)
504-
assert button.handler[pygame_gui.UI_BUTTON_PRESSED] == test_function
504+
assert button._handler[pygame_gui.UI_BUTTON_PRESSED] == test_function
505505

506506
button.bind(pygame_gui.UI_BUTTON_PRESSED, None)
507-
assert pygame_gui.UI_BUTTON_PRESSED not in button.handler
507+
assert pygame_gui.UI_BUTTON_PRESSED not in button._handler
508508

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

540-
assert button.handler[pygame_gui.UI_BUTTON_START_PRESS] == test_function # not
541-
assert button.handler[pygame_gui.UI_BUTTON_PRESSED] == test_function2
542-
assert pygame_gui.UI_BUTTON_DOUBLE_CLICKED not in button.handler
540+
assert button._handler[pygame_gui.UI_BUTTON_START_PRESS] == test_function # not
541+
assert button._handler[pygame_gui.UI_BUTTON_PRESSED] == test_function2
542+
assert pygame_gui.UI_BUTTON_DOUBLE_CLICKED not in button._handler
543543

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

0 commit comments

Comments
 (0)