Skip to content

Commit 47ab2d8

Browse files
committed
fix
1 parent 90e4a58 commit 47ab2d8

5 files changed

Lines changed: 39 additions & 34 deletions

File tree

pygame_menu/examples/other/calculator.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def __init__(self) -> None:
168168
w_deco.disable(on_layer)
169169
widget.set_attribute("on_layer", on_layer)
170170

171-
def widget_select(sel: bool, wid: pygame_menu.widgets.Widget, _):
171+
def widget_select(sel: bool, wid: pygame_menu.widgets.Widget, _) -> None:
172172
"""
173173
Function triggered if widget is selected
174174
"""
@@ -237,9 +237,9 @@ def _operate(self) -> int | float:
237237
238238
:return: Operation result
239239
"""
240-
a = 0 if self.curr == "" else float(self.curr)
241-
b = 0 if self.prev == "" else float(self.prev)
242-
c = 0
240+
a = 0.0 if self.curr == "" else float(self.curr)
241+
b = 0.0 if self.prev == "" else float(self.prev)
242+
c = 0.0
243243
if self.op == "+":
244244
c = a + b
245245
elif self.op == "-":
@@ -259,19 +259,24 @@ def _press(self, digit: int | str) -> None:
259259
260260
:param digit: Number or symbol
261261
"""
262-
if digit in ("+", "-", "x", "/"):
262+
if isinstance(digit, int):
263+
digit_str = str(digit)
264+
else:
265+
digit_str = digit
266+
267+
if digit_str in ("+", "-", "x", "/"):
263268
if self.curr != "":
264269
if self.op != "":
265270
self.prev = str(self._operate())
266271
else:
267272
self.prev = self.curr
268273
self.curr = ""
269-
self.op = digit
274+
self.op = digit_str
270275
if len(self.prev) <= 8:
271276
self.screen.set_title(self.prev + self.op)
272277
else:
273278
self.screen.set_title("Ans" + self.op)
274-
elif digit == "=":
279+
elif digit_str == "=":
275280
if self.prev == "":
276281
self.curr = ""
277282
self.screen.set_title("0")
@@ -287,12 +292,12 @@ def _press(self, digit: int | str) -> None:
287292
else:
288293
if self.op == "":
289294
if len(self.prev) <= 7:
290-
self.prev += str(digit)
295+
self.prev += digit_str
291296
self.prev = self._format(self.prev)
292297
self.screen.set_title(self.prev)
293298
else:
294299
if len(self.curr) <= 7:
295-
self.curr += str(digit)
300+
self.curr += digit_str
296301
self.curr = self._format(self.curr)
297302
self.screen.set_title(self.curr)
298303

pygame_menu/examples/other/maze.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ class AStarQueue:
4747
A* Queue.
4848
"""
4949

50-
def __init__(self):
50+
def __init__(self) -> None:
5151
self.myheap = []
5252

5353
def show(self):
5454
return self.myheap
5555

56-
def push(self, priority, distance, node):
56+
def push(self, priority, distance, node) -> None:
5757
heapq.heappush(self.myheap, (priority, distance, node))
5858

5959
def pop(self):
@@ -67,13 +67,13 @@ class PriorityQueue:
6767
Priority Queue.
6868
"""
6969

70-
def __init__(self):
70+
def __init__(self) -> None:
7171
self.myheap = []
7272

7373
def show(self):
7474
return self.myheap
7575

76-
def push(self, priority, node):
76+
def push(self, priority, node) -> None:
7777
heapq.heappush(self.myheap, (priority, node))
7878

7979
def pop(self):
@@ -87,14 +87,14 @@ class PrioritySet:
8787
Create a priority queue that doesn't add duplicate nodes.
8888
"""
8989

90-
def __init__(self):
90+
def __init__(self) -> None:
9191
self.myheap = []
9292
self.myset = set()
9393

9494
def show(self):
9595
return self.myheap
9696

97-
def push(self, priority, node):
97+
def push(self, priority, node) -> None:
9898
if node not in self.myset:
9999
heapq.heappush(self.myheap, (priority, node))
100100
self.myset.add(node)
@@ -1074,7 +1074,7 @@ def _clear_visited(self) -> None:
10741074
self._grid[row][column].update(is_visited=False, is_path=False)
10751075
self._update_gui()
10761076

1077-
def _update_path(self) -> bool | _MazeType:
1077+
def _update_path(self) -> bool:
10781078
"""
10791079
Updates the path.
10801080
"""
@@ -1403,11 +1403,14 @@ def _xfs(
14031403
# Trace back to start using path_dict
14041404
path_node = goal_node
14051405
while True:
1406-
path_node = path_dict[path_node]
1407-
mazearray[path_node[0]][path_node[1]].update(is_path=True) # type: ignore
1408-
self._draw_square(mazearray, path_node[0], path_node[1]) # type: ignore
1406+
parent = path_dict[path_node]
1407+
if parent is None:
1408+
break
1409+
path_node = parent
1410+
mazearray[path_node[0]][path_node[1]].update(is_path=True)
1411+
self._draw_square(mazearray, path_node[0], path_node[1])
14091412
if self._visualize:
1410-
self._update_square(path_node[0], path_node[1]) # type: ignore
1413+
self._update_square(path_node[0], path_node[1])
14111414
if path_node == start_point:
14121415
return True
14131416

pygame_menu/widgets/widget/colorinput.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,11 @@ def __init__(
172172
), 'invalid hex format mode, it must be "none", "lower" or "upper"'
173173

174174
maxchar: int = 0
175+
valid_chars: list[str] | None = None
175176
self._color_type = color_type.lower()
176177
if self._color_type == COLORINPUT_TYPE_RGB:
177178
maxchar = 11 # RRR,GGG,BBB
178-
self._valid_chars = [
179+
valid_chars = [
179180
"0",
180181
"1",
181182
"2",
@@ -190,7 +191,7 @@ def __init__(
190191
]
191192
elif self._color_type == COLORINPUT_TYPE_HEX:
192193
maxchar = 7 # #XXYYZZ
193-
self._valid_chars = [
194+
valid_chars = [
194195
"a",
195196
"A",
196197
"b",
@@ -218,6 +219,8 @@ def __init__(
218219

219220
# noinspection PyArgumentEqualDefault
220221
super().__init__(
222+
alt_x_enabled=False,
223+
apply_widget_update_callback=False,
221224
copy_paste_enable=False,
222225
cursor_color=cursor_color,
223226
cursor_switch_ms=cursor_switch_ms,
@@ -238,7 +241,7 @@ def __init__(
238241
text_ellipsis="",
239242
textinput_id=colorinput_id,
240243
title=title,
241-
valid_chars=self._valid_chars,
244+
valid_chars=valid_chars,
242245
*args,
243246
**kwargs,
244247
)
@@ -257,12 +260,6 @@ def __init__(
257260
self._prev_width_factor = prev_width_factor
258261
self._previsualization_surface = None
259262

260-
# Disable parent callbacks
261-
self._apply_widget_update_callback = False
262-
263-
# Disable alt+x
264-
self._alt_x_enabled = False
265-
266263
def _apply_font(self) -> None:
267264
super()._apply_font()
268265

pygame_menu/widgets/widget/dropselect_multiple.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ def __init__(
243243
selection_option_selected_bgcolor=selection_option_selected_bgcolor,
244244
selection_option_selected_font_color=selection_option_selected_font_color,
245245
title=title,
246+
args=args,
246247
**kwargs,
247248
)
248249

@@ -261,7 +262,6 @@ def __init__(
261262
assert isinstance(max_selected, int) and max_selected >= 0
262263

263264
# Configure parent
264-
self._args = args or []
265265
self._max_selected = max_selected
266266
self._selection_option_left_space_margin = selection_option_selected_box_margin
267267

pygame_menu/widgets/widget/textinput.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,6 @@ class TextInput(Widget):
163163
"""
164164

165165
_absolute_origin: Tuple2IntType
166-
_alt_x_enabled: bool
167-
_apply_widget_update_callback: bool # Used in ColorInput
168166
_block_copy_paste: bool
169167
_clock: pygame.time.Clock
170168
_copy_paste_enabled: bool
@@ -227,6 +225,8 @@ def __init__(
227225
self,
228226
title: Any,
229227
textinput_id: str = "",
228+
apply_widget_update_callback: bool = True,
229+
alt_x_enabled: bool = True,
230230
copy_paste_enable: bool = True,
231231
cursor_color: ColorInputType = (0, 0, 0),
232232
cursor_selection_color: ColorInputType = (30, 30, 30, 100),
@@ -405,10 +405,10 @@ def __init__(
405405
self._valid_chars = valid_chars
406406

407407
# Callbacks
408-
self._apply_widget_update_callback = True
408+
self._apply_widget_update_callback = apply_widget_update_callback
409409

410410
# Other
411-
self._alt_x_enabled = True
411+
self._alt_x_enabled = alt_x_enabled
412412
self._copy_paste_enabled = copy_paste_enable
413413
self._current_underline_string = ""
414414
self._input_type = input_type

0 commit comments

Comments
 (0)