Skip to content

Commit b9ef5b4

Browse files
committed
attributes
1 parent 0db7b4a commit b9ef5b4

8 files changed

Lines changed: 18 additions & 20 deletions

File tree

pygame_menu/widgets/core/widget.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,6 @@ class Widget(Base):
280280
:param kwargs: Optional keyword arguments
281281
"""
282282

283-
_accept_events: bool
284283
_alignment: str
285284
_angle: NumberType
286285
_args: list[Any]
@@ -361,12 +360,9 @@ class Widget(Base):
361360
_update_callbacks: dict[
362361
str, Callable[[EventListType, Widget, pygame_menu.Menu], Any]
363362
]
364-
_visible: bool
365-
active: bool
366363
configured: bool
367364
force_menu_draw_focus: bool
368365
is_scrollable: bool
369-
is_selectable: bool
370366
last_surface: pygame.Surface | None
371367
lock_position: bool
372368
readonly: bool
@@ -383,6 +379,9 @@ def __init__(
383379
onselect: Callable[[bool, Widget, pygame_menu.Menu], Any] | None = None,
384380
args=None,
385381
kwargs=None,
382+
*,
383+
selectable: bool = True,
384+
visible: bool = True,
386385
) -> None:
387386
super().__init__(object_id=widget_id)
388387

@@ -413,7 +412,7 @@ def __init__(
413412
self._sound = Sound()
414413
self._tab_size = 0 # Tab spaces
415414
self._title = str(title)
416-
self._visible = True # Use show() or hide() to modify this status
415+
self._visible = visible # Use show() or hide() to modify this status
417416

418417
# If True, the widget don't contribute width/height to the Menu widget
419418
# positioning computation. Use .set_float() to modify this status
@@ -525,7 +524,7 @@ def __init__(
525524
self.configured = False # Widget has been configured
526525
self.force_menu_draw_focus = False # If True Menu draw focus if widget is selected, don't consider the previous requisites
527526
self.is_scrollable = False # Some widgets can be scrolled, such as the Frame
528-
self.is_selectable = True # Some widgets cannot be selected like labels
527+
self.is_selectable = selectable # Some widgets cannot be selected like labels
529528
self.last_surface = None # Stores the last surface the widget has been drawn
530529
self.lock_position = False # If True, the widget don't update the position if .set_position() is executed
531530
self.readonly = False # If True, widget ignores all input

pygame_menu/widgets/widget/dropselect.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ def __init__(
223223
selection_option_font: FontType | None = None,
224224
selection_option_font_color: ColorInputType = (0, 0, 0),
225225
selection_option_font_size: int | None = None,
226+
selection_option_left_space: bool = False,
226227
selection_option_left_space_height_factor: float = 1.0,
227228
selection_option_padding: PaddingType = 5,
228229
selection_option_selected_bgcolor: ColorInputType = (188, 227, 244),
@@ -328,7 +329,7 @@ def __init__(
328329

329330
# If True adds a space equals to the height of the option at left, used for
330331
# drawing some options (for example, ticks, boxes, etc.)
331-
self._selection_option_left_space = False
332+
self._selection_option_left_space = selection_option_left_space
332333
self._selection_option_left_space_height_factor = (
333334
selection_option_left_space_height_factor
334335
)

pygame_menu/widgets/widget/dropselect_multiple.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ def __init__(
236236
selection_option_font=selection_option_font,
237237
selection_option_font_color=selection_option_font_color,
238238
selection_option_font_size=selection_option_font_size,
239+
selection_option_left_space=True,
239240
selection_option_left_space_height_factor=selection_option_selected_box_height,
240241
selection_option_padding=selection_option_padding,
241242
selection_option_selected_bgcolor=selection_option_selected_bgcolor,
@@ -262,7 +263,6 @@ def __init__(
262263
self._args = args or []
263264
self._close_on_apply = False
264265
self._max_selected = max_selected
265-
self._selection_option_left_space = True
266266
self._selection_option_left_space_margin = selection_option_selected_box_margin
267267

268268
# Set style

pygame_menu/widgets/widget/frame.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def __init__(
161161
orientation: str,
162162
frame_id: str = "",
163163
) -> None:
164-
super().__init__(widget_id=frame_id)
164+
super().__init__(widget_id=frame_id, selectable=False)
165165
assert isinstance(width, NumberInstance)
166166
assert isinstance(height, NumberInstance)
167167
assert width > 0, f"width must be greater than zero ({width} received)"
@@ -201,7 +201,6 @@ def __init__(
201201
self.first_index = -1
202202
self.horizontal = orientation == ORIENTATION_HORIZONTAL
203203
self.is_scrollable = False
204-
self.is_selectable = False
205204
self.last_index = -1
206205

207206
def set_title(

pygame_menu/widgets/widget/menubar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ def __init__(
135135
onreturn=onreturn,
136136
title=title,
137137
widget_id=menubar_id,
138+
selectable=False,
138139
)
139140

140141
self._backbox = back_box
@@ -157,7 +158,6 @@ def __init__(
157158
self.set_title(title, offsetx, offsety)
158159

159160
# Public's
160-
self.is_selectable = False
161161
self.fixed = True
162162

163163
def _apply_font(self) -> None:

pygame_menu/widgets/widget/menulink.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,12 @@ class MenuLink(NoneWidget):
4141
def __init__(
4242
self, menu: pygame_menu.Menu, menu_opener_handler: Callable, link_id: str = ""
4343
) -> None:
44-
assert isinstance(menu, pygame_menu.Menu)
4544
assert callable(menu_opener_handler), (
4645
"menu opener handler must be callable (a function)"
4746
)
48-
super().__init__(widget_id=link_id)
47+
super().__init__(widget_id=link_id, visible=False)
4948
self.menu = menu
5049
self._onreturn = menu_opener_handler
51-
self._visible = False
52-
self.is_selectable = False
5350

5451
def hide(self) -> MenuLink:
5552
pass

pygame_menu/widgets/widget/none.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ class NoneWidget(Widget):
4141
:param widget_id: ID of the widget
4242
"""
4343

44-
def __init__(self, widget_id: str = "") -> None:
45-
super().__init__(widget_id=widget_id)
46-
self.is_selectable = False
44+
def __init__(self, widget_id: str = "", *, visible: bool = True) -> None:
45+
super().__init__(widget_id=widget_id, selectable=False, visible=visible)
4746
self._surface = make_surface(0, 0, alpha=True)
4847

4948
def _apply_font(self) -> None:

pygame_menu/widgets/widget/scrollbar.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,11 @@ def __init__(
121121
slider_hover_color = assert_color(slider_hover_color)
122122

123123
super().__init__(
124-
widget_id=scrollbar_id, onchange=onchange, args=args, kwargs=kwargs
124+
widget_id=scrollbar_id,
125+
onchange=onchange,
126+
args=args,
127+
kwargs=kwargs,
128+
selectable=False,
125129
)
126130

127131
self._check_mouseleave_call_render = True
@@ -167,7 +171,6 @@ def __init__(
167171

168172
# Configure public's
169173
self.is_scrollable = True
170-
self.is_selectable = False
171174
self.scrolling = False
172175

173176
def scroll_to_widget(self, *args, **kwargs) -> ScrollBar:

0 commit comments

Comments
 (0)