From 47ab2d8a9bac582b35ec92c64946ef5d9e15a405 Mon Sep 17 00:00:00 2001 From: JaskRendix Date: Fri, 13 Mar 2026 15:11:24 +0100 Subject: [PATCH 1/2] fix --- pygame_menu/examples/other/calculator.py | 23 ++++++++++------- pygame_menu/examples/other/maze.py | 25 +++++++++++-------- pygame_menu/widgets/widget/colorinput.py | 15 +++++------ .../widgets/widget/dropselect_multiple.py | 2 +- pygame_menu/widgets/widget/textinput.py | 8 +++--- 5 files changed, 39 insertions(+), 34 deletions(-) diff --git a/pygame_menu/examples/other/calculator.py b/pygame_menu/examples/other/calculator.py index 56641f89..646e9042 100644 --- a/pygame_menu/examples/other/calculator.py +++ b/pygame_menu/examples/other/calculator.py @@ -168,7 +168,7 @@ def __init__(self) -> None: w_deco.disable(on_layer) widget.set_attribute("on_layer", on_layer) - def widget_select(sel: bool, wid: pygame_menu.widgets.Widget, _): + def widget_select(sel: bool, wid: pygame_menu.widgets.Widget, _) -> None: """ Function triggered if widget is selected """ @@ -237,9 +237,9 @@ def _operate(self) -> int | float: :return: Operation result """ - a = 0 if self.curr == "" else float(self.curr) - b = 0 if self.prev == "" else float(self.prev) - c = 0 + a = 0.0 if self.curr == "" else float(self.curr) + b = 0.0 if self.prev == "" else float(self.prev) + c = 0.0 if self.op == "+": c = a + b elif self.op == "-": @@ -259,19 +259,24 @@ def _press(self, digit: int | str) -> None: :param digit: Number or symbol """ - if digit in ("+", "-", "x", "/"): + if isinstance(digit, int): + digit_str = str(digit) + else: + digit_str = digit + + if digit_str in ("+", "-", "x", "/"): if self.curr != "": if self.op != "": self.prev = str(self._operate()) else: self.prev = self.curr self.curr = "" - self.op = digit + self.op = digit_str if len(self.prev) <= 8: self.screen.set_title(self.prev + self.op) else: self.screen.set_title("Ans" + self.op) - elif digit == "=": + elif digit_str == "=": if self.prev == "": self.curr = "" self.screen.set_title("0") @@ -287,12 +292,12 @@ def _press(self, digit: int | str) -> None: else: if self.op == "": if len(self.prev) <= 7: - self.prev += str(digit) + self.prev += digit_str self.prev = self._format(self.prev) self.screen.set_title(self.prev) else: if len(self.curr) <= 7: - self.curr += str(digit) + self.curr += digit_str self.curr = self._format(self.curr) self.screen.set_title(self.curr) diff --git a/pygame_menu/examples/other/maze.py b/pygame_menu/examples/other/maze.py index 33c7ee2a..8a119eec 100644 --- a/pygame_menu/examples/other/maze.py +++ b/pygame_menu/examples/other/maze.py @@ -47,13 +47,13 @@ class AStarQueue: A* Queue. """ - def __init__(self): + def __init__(self) -> None: self.myheap = [] def show(self): return self.myheap - def push(self, priority, distance, node): + def push(self, priority, distance, node) -> None: heapq.heappush(self.myheap, (priority, distance, node)) def pop(self): @@ -67,13 +67,13 @@ class PriorityQueue: Priority Queue. """ - def __init__(self): + def __init__(self) -> None: self.myheap = [] def show(self): return self.myheap - def push(self, priority, node): + def push(self, priority, node) -> None: heapq.heappush(self.myheap, (priority, node)) def pop(self): @@ -87,14 +87,14 @@ class PrioritySet: Create a priority queue that doesn't add duplicate nodes. """ - def __init__(self): + def __init__(self) -> None: self.myheap = [] self.myset = set() def show(self): return self.myheap - def push(self, priority, node): + def push(self, priority, node) -> None: if node not in self.myset: heapq.heappush(self.myheap, (priority, node)) self.myset.add(node) @@ -1074,7 +1074,7 @@ def _clear_visited(self) -> None: self._grid[row][column].update(is_visited=False, is_path=False) self._update_gui() - def _update_path(self) -> bool | _MazeType: + def _update_path(self) -> bool: """ Updates the path. """ @@ -1403,11 +1403,14 @@ def _xfs( # Trace back to start using path_dict path_node = goal_node while True: - path_node = path_dict[path_node] - mazearray[path_node[0]][path_node[1]].update(is_path=True) # type: ignore - self._draw_square(mazearray, path_node[0], path_node[1]) # type: ignore + parent = path_dict[path_node] + if parent is None: + break + path_node = parent + mazearray[path_node[0]][path_node[1]].update(is_path=True) + self._draw_square(mazearray, path_node[0], path_node[1]) if self._visualize: - self._update_square(path_node[0], path_node[1]) # type: ignore + self._update_square(path_node[0], path_node[1]) if path_node == start_point: return True diff --git a/pygame_menu/widgets/widget/colorinput.py b/pygame_menu/widgets/widget/colorinput.py index e5ad8d39..1d891c19 100644 --- a/pygame_menu/widgets/widget/colorinput.py +++ b/pygame_menu/widgets/widget/colorinput.py @@ -172,10 +172,11 @@ def __init__( ), 'invalid hex format mode, it must be "none", "lower" or "upper"' maxchar: int = 0 + valid_chars: list[str] | None = None self._color_type = color_type.lower() if self._color_type == COLORINPUT_TYPE_RGB: maxchar = 11 # RRR,GGG,BBB - self._valid_chars = [ + valid_chars = [ "0", "1", "2", @@ -190,7 +191,7 @@ def __init__( ] elif self._color_type == COLORINPUT_TYPE_HEX: maxchar = 7 # #XXYYZZ - self._valid_chars = [ + valid_chars = [ "a", "A", "b", @@ -218,6 +219,8 @@ def __init__( # noinspection PyArgumentEqualDefault super().__init__( + alt_x_enabled=False, + apply_widget_update_callback=False, copy_paste_enable=False, cursor_color=cursor_color, cursor_switch_ms=cursor_switch_ms, @@ -238,7 +241,7 @@ def __init__( text_ellipsis="", textinput_id=colorinput_id, title=title, - valid_chars=self._valid_chars, + valid_chars=valid_chars, *args, **kwargs, ) @@ -257,12 +260,6 @@ def __init__( self._prev_width_factor = prev_width_factor self._previsualization_surface = None - # Disable parent callbacks - self._apply_widget_update_callback = False - - # Disable alt+x - self._alt_x_enabled = False - def _apply_font(self) -> None: super()._apply_font() diff --git a/pygame_menu/widgets/widget/dropselect_multiple.py b/pygame_menu/widgets/widget/dropselect_multiple.py index 23c8ee1e..9e1d6f22 100644 --- a/pygame_menu/widgets/widget/dropselect_multiple.py +++ b/pygame_menu/widgets/widget/dropselect_multiple.py @@ -243,6 +243,7 @@ def __init__( selection_option_selected_bgcolor=selection_option_selected_bgcolor, selection_option_selected_font_color=selection_option_selected_font_color, title=title, + args=args, **kwargs, ) @@ -261,7 +262,6 @@ def __init__( assert isinstance(max_selected, int) and max_selected >= 0 # Configure parent - self._args = args or [] self._max_selected = max_selected self._selection_option_left_space_margin = selection_option_selected_box_margin diff --git a/pygame_menu/widgets/widget/textinput.py b/pygame_menu/widgets/widget/textinput.py index 71ac6166..6bb6b577 100644 --- a/pygame_menu/widgets/widget/textinput.py +++ b/pygame_menu/widgets/widget/textinput.py @@ -163,8 +163,6 @@ class TextInput(Widget): """ _absolute_origin: Tuple2IntType - _alt_x_enabled: bool - _apply_widget_update_callback: bool # Used in ColorInput _block_copy_paste: bool _clock: pygame.time.Clock _copy_paste_enabled: bool @@ -227,6 +225,8 @@ def __init__( self, title: Any, textinput_id: str = "", + apply_widget_update_callback: bool = True, + alt_x_enabled: bool = True, copy_paste_enable: bool = True, cursor_color: ColorInputType = (0, 0, 0), cursor_selection_color: ColorInputType = (30, 30, 30, 100), @@ -405,10 +405,10 @@ def __init__( self._valid_chars = valid_chars # Callbacks - self._apply_widget_update_callback = True + self._apply_widget_update_callback = apply_widget_update_callback # Other - self._alt_x_enabled = True + self._alt_x_enabled = alt_x_enabled self._copy_paste_enabled = copy_paste_enable self._current_underline_string = "" self._input_type = input_type From d863a59c9d94610350010d1b66dd227e5a35f240 Mon Sep 17 00:00:00 2001 From: JaskRendix Date: Mon, 16 Mar 2026 08:52:23 +0100 Subject: [PATCH 2/2] fix code ql --- test/test_decorator.py | 21 ++++++++++++--------- test/test_sound.py | 2 -- test/test_utils.py | 4 ++-- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/test/test_decorator.py b/test/test_decorator.py index 73dc27ea..9e647d6a 100644 --- a/test/test_decorator.py +++ b/test/test_decorator.py @@ -12,7 +12,10 @@ import pygame import pytest -import pygame_menu +from pygame_menu.baseimage import IMAGE_EXAMPLE_PYGAME_MENU, BaseImage +from pygame_menu.font import FONT_8BIT +from pygame_menu.widgets.widget.button import Button +from pygame_menu.widgets.widget.none import NoneWidget from test._utils import TEST_THEME, MenuUtils, surface TEST_TIME_DRAW = False @@ -20,7 +23,7 @@ @pytest.mark.skipif(not TEST_TIME_DRAW, reason="Timing test disabled") def test_time_draw(): - widg = pygame_menu.widgets.NoneWidget() + widg = NoneWidget() deco = widg.get_decorator() deco.cache = True @@ -37,7 +40,7 @@ def test_time_draw(): def test_cache(): - widg = pygame_menu.widgets.NoneWidget() + widg = NoneWidget() deco = widg.get_decorator() deco.cache = True @@ -87,7 +90,7 @@ def test_cache(): def test_copy(): - widg = pygame_menu.widgets.NoneWidget() + widg = NoneWidget() deco = widg.get_decorator() with pytest.raises(Exception): @@ -97,7 +100,7 @@ def test_copy(): def test_add_remove(): - widg = pygame_menu.widgets.NoneWidget() + widg = NoneWidget() deco = widg.get_decorator() d = deco._add_none() @@ -133,7 +136,7 @@ def test_enable_disable(): def fun(surf, obj): test[0] = True assert isinstance(surf, pygame.Surface) - assert isinstance(obj, pygame_menu.widgets.Button) + assert isinstance(obj, Button) call_id = deco.add_callable(fun) assert not test[0] @@ -197,7 +200,7 @@ def test_general(): deco.add_circle(1, 1, 100, color, False, 5) deco.add_circle(50, 50, 100, color, True) - img = pygame_menu.BaseImage(pygame_menu.baseimage.IMAGE_EXAMPLE_PYGAME_MENU) + img = BaseImage(IMAGE_EXAMPLE_PYGAME_MENU) img.scale(0.15, 0.15) deco.add_surface(60, 60, img.get_surface(), prev=False) @@ -244,9 +247,9 @@ def test_general(): assert deco._coord_cache[img_dec] == (300, 173, ((300, 173),)) with pytest.raises(ValueError): - deco.add_text(100, 200, "nice", pygame_menu.font.FONT_8BIT, 0, color) + deco.add_text(100, 200, "nice", FONT_8BIT, 0, color) - deco.add_text(-150, 0, "nice", pygame_menu.font.FONT_8BIT, 20, color, centered=True) + deco.add_text(-150, 0, "nice", FONT_8BIT, 20, color, centered=True) menu.draw(surface) with pytest.raises(AssertionError): diff --git a/test/test_sound.py b/test/test_sound.py index b5ff085d..29ed57bc 100644 --- a/test/test_sound.py +++ b/test/test_sound.py @@ -8,12 +8,10 @@ import copy import time -from pathlib import Path import pygame import pytest -import pygame_menu from pygame_menu.sound import ( SOUND_EXAMPLES, SOUND_INITIALIZED, diff --git a/test/test_utils.py b/test/test_utils.py index d4e3c2d8..fbf1e648 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -8,9 +8,9 @@ import pytest -import pygame_menu import pygame_menu.utils as ut from pygame_menu.locals import POSITION_NORTHWEST +from pygame_menu.widgets.widget.button import Button def test_alpha(): @@ -46,7 +46,7 @@ def test_padding(value, expected): def test_terminal_widget_title(): - w = pygame_menu.widgets.Button("epic") + w = Button("epic") w.hide() s = ut.widget_terminal_title(w) assert "╳" in s