Skip to content

Commit 43ae2ea

Browse files
authored
Merge pull request #299 from ppizarror/fix-docs-typos-widget-id
Fix docs typos widget
2 parents 5e1915b + 4f0a2b4 commit 43ae2ea

23 files changed

+155
-128
lines changed

docs/_source/gallery.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,4 @@ Other - Image background
115115
:alt: Image background
116116
:width: 590
117117

118-
Source: `examples/other/image_background.py <https://github.com/ppizarror/pygame-menu/blob/master/pygame_menu/examples/other/image_background.py>`_
118+
Source: `examples/other/image_background.py <https://github.com/ppizarror/pygame-menu/blob/master/pygame_menu/examples/other/image_background.py>`_

docs/_source/migration_guide.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ Migration Guide - v2 to v3
4343
- Renamed Menu method parameters
4444
- ``element_name`` and ``element`` from ``add_button()`` to ``title`` and ``action``
4545
- ``values`` from ``add_selector()`` to ``items``
46-
- ``widget_id`` from ``add_button()`` to ``button_id``
46+
- ``widget_id`` from ``add_button()`` to ``button_id``

docs/_source/themes.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Background Color/Images
7070

7171
Theme background can be both a color or an image. All colors can be defined
7272
using a tuple or an list of 3 or 4 numbers between 0 and 255. The format of
73-
numers are:
73+
the numbers are:
7474

7575
.. code-block:: python
7676

pygame_menu/baseimage.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ def checkpoint(self):
287287
def apply_image_function(self, image_function):
288288
"""
289289
Apply a function to each pixel of the image. The function will receive the red, green, blue and alpha
290-
colors and must return the same values. The color pixel will be overriden by the function output.
290+
colors and must return the same values. The color pixel will be overridden by the function output.
291291
292292
.. note::
293293

pygame_menu/events.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
class MenuAction(object):
4040
"""
41-
Pymenu events.
41+
Pygame-menu events.
4242
4343
:param action: Action identifier
4444
:type action: int

pygame_menu/examples/scroll_menu.py

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ def make_long_menu():
130130
_menu_sub.add_button(txt, on_button_click, 100 * i)
131131
_menu_sub.add_button('Back', pygame_menu.events.BACK)
132132

133+
# noinspection SpellCheckingInspection
133134
_menu_text.add_label(
134135
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod '
135136
'tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, '

pygame_menu/menu.py

+30-26
Original file line numberDiff line numberDiff line change
@@ -1208,10 +1208,12 @@ def select_widget(self, widget):
12081208
"""
12091209
Select a widget from the Menu.
12101210
1211-
:param widget: Widget to be selected
1212-
:type widget: :py:class:`pygame_menu.widgets.core.widget.Widget`
1211+
:param widget: Widget to be selected or Widget ID
1212+
:type widget: :py:class:`pygame_menu.widgets.core.widget.Widget`, str
12131213
:return: None
12141214
"""
1215+
if isinstance(widget, str):
1216+
widget = self.get_widget(widget_id=widget)
12151217
assert isinstance(widget, _widgets.core.Widget)
12161218
if not widget.is_selectable:
12171219
raise ValueError('widget is not selectable')
@@ -1228,10 +1230,12 @@ def remove_widget(self, widget):
12281230
"""
12291231
Remove a widget from the Menu.
12301232
1231-
:param widget: Widget object
1232-
:type widget: :py:class:`pygame_menu.widgets.core.widget.Widget`
1233+
:param widget: Widget object or ID
1234+
:type widget: :py:class:`pygame_menu.widgets.core.widget.Widget`, str
12331235
:return: None
12341236
"""
1237+
if isinstance(widget, str):
1238+
widget = self.get_widget(widget_id=widget)
12351239
assert isinstance(widget, _widgets.core.Widget)
12361240
try:
12371241
index = self._widgets.index(widget) # If not exists this raises ValueError
@@ -1253,19 +1257,19 @@ def _update_after_remove_or_hidden(self, index, update_surface=True):
12531257
:return: None
12541258
"""
12551259
# Check if there's more selectable widgets
1256-
nselect = 0
1260+
n_select = 0
12571261
last_selectable = 0
12581262
for indx in range(len(self._widgets)):
12591263
wid = self._widgets[indx] # type: _widgets.core.Widget
12601264
if wid.is_selectable and wid.visible:
1261-
nselect += 1
1265+
n_select += 1
12621266
last_selectable = indx
12631267

1264-
if nselect == 0:
1268+
if n_select == 0:
12651269
self._index = -1 # Any widget is selected
1266-
elif nselect == 1:
1270+
elif n_select == 1:
12671271
self._select(last_selectable) # Select the unique selectable option
1268-
elif nselect > 1:
1272+
elif n_select > 1:
12691273
if index == -1: # Index was hidden
12701274
self._select(self._index + 1)
12711275
elif self._index > index: # If the selected widget was after this
@@ -1400,27 +1404,27 @@ def _update_widget_position(self):
14001404
x_coord += self._widget_offset[0]
14011405

14021406
# Calculate Y position
1403-
ysum = 1 # Compute the total height from the current row position to the top of the column
1407+
y_sum = 1 # Compute the total height from the current row position to the top of the column
14041408
for r in range(row):
1405-
rwidget = self._widgets[int(self._rows * col + r)] # type: _widgets.core.Widget
1406-
if rwidget.visible:
1407-
ysum += widget_rects[rwidget.get_id()].height # Height
1408-
ysum += rwidget.get_margin()[1] # Vertical margin (bottom)
1409+
r_widget = self._widgets[int(self._rows * col + r)] # type: _widgets.core.Widget
1410+
if r_widget.visible:
1411+
y_sum += widget_rects[r_widget.get_id()].height # Height
1412+
y_sum += r_widget.get_margin()[1] # Vertical margin (bottom)
14091413

14101414
# If no widget is before add the selection effect
1411-
yselh = rwidget.get_selection_effect().get_margin()[0]
1412-
if r == 0 and self._widget_offset[1] <= yselh:
1413-
if rwidget.is_selectable:
1414-
ysum += yselh - self._widget_offset[1]
1415+
y_sel_h = r_widget.get_selection_effect().get_margin()[0]
1416+
if r == 0 and self._widget_offset[1] <= y_sel_h:
1417+
if r_widget.is_selectable:
1418+
y_sum += y_sel_h - self._widget_offset[1]
14151419

14161420
# If the widget offset is zero, then add the selection effect to the height
14171421
# of the widget to avoid visual glitches
1418-
yselh = widget.get_selection_effect().get_margin()[0]
1419-
if ysum == 1 and self._widget_offset[1] <= yselh: # No widget is before
1422+
y_sel_h = widget.get_selection_effect().get_margin()[0]
1423+
if y_sum == 1 and self._widget_offset[1] <= y_sel_h: # No widget is before
14201424
if widget.is_selectable: # Add top margin
1421-
ysum += yselh - self._widget_offset[1]
1425+
y_sum += y_sel_h - self._widget_offset[1]
14221426

1423-
y_coord = max(0, self._widget_offset[1]) + ysum + widget.get_padding()[0]
1427+
y_coord = max(0, self._widget_offset[1]) + y_sum + widget.get_padding()[0]
14241428

14251429
# Update the position of the widget
14261430
widget.set_position(int(x_coord), int(y_coord))
@@ -1971,8 +1975,8 @@ def update(self, events):
19711975

19721976
# If mouse motion enabled, add the current mouse position to event list
19731977
if self._current._mouse and self._current._mouse_motion_selection:
1974-
mousex, mousey = pygame.mouse.get_pos()
1975-
events.append(pygame.event.Event(pygame.MOUSEMOTION, {'pos': (mousex, mousey)}))
1978+
mouse_x, mouse_y = pygame.mouse.get_pos()
1979+
events.append(pygame.event.Event(pygame.MOUSEMOTION, {'pos': (mouse_x, mouse_y)}))
19761980

19771981
for event in events: # type: pygame.event.Event
19781982

@@ -2245,8 +2249,8 @@ def _get_input_data(self, recursive, depth):
22452249

22462250
# Check if there is a collision between keys
22472251
data_keys = data.keys()
2248-
subdata_keys = data_submenu.keys()
2249-
for key in subdata_keys: # type: str
2252+
sub_data_keys = data_submenu.keys()
2253+
for key in sub_data_keys: # type: str
22502254
if key in data_keys:
22512255
msg = 'collision between widget data ID="{0}" at depth={1}'.format(key, depth)
22522256
raise ValueError(msg)

pygame_menu/sound.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -307,11 +307,11 @@ def _play_sound(self, sound):
307307
return False
308308

309309
# Play the sound
310-
soundtime = time.time()
310+
sound_time = time.time()
311311

312312
# If the previous sound is the same and has not ended (max 20% overlap)
313313
if sound['type'] != self._last_play or \
314-
soundtime - self._last_time >= 0.2 * sound['length'] or self._uniquechannel:
314+
sound_time - self._last_time >= 0.2 * sound['length'] or self._uniquechannel:
315315
try:
316316
if self._uniquechannel: # Stop the current channel if it's unique
317317
channel.stop()
@@ -325,7 +325,7 @@ def _play_sound(self, sound):
325325

326326
# Store last execution
327327
self._last_play = sound['type']
328-
self._last_time = soundtime
328+
self._last_time = sound_time
329329
return True
330330

331331
def play_click_mouse(self):

pygame_menu/themes.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ class Theme(object):
9797
:type title_background_color: tuple, list
9898
:param title_bar_style: Style of the title, use menubar widget styles
9999
:type title_bar_style: int
100-
:param title_font: Title font color. If ``None`` use the widget font color
101-
:type title_font: str, None
100+
:param title_font: Title font path or name
101+
:type title_font: str
102102
:param title_font_antialias: Title font renders with antialiasing
103103
:type title_font_antialias: bool
104104
:param title_font_color: Title font color, if None use the widget font color
@@ -417,28 +417,28 @@ def _get(params, key, allowed_types=None, default=None):
417417
if allowed_types:
418418
if not isinstance(allowed_types, (tuple, list)):
419419
allowed_types = (allowed_types,)
420-
for valtype in allowed_types:
421-
if valtype == 'color':
420+
for val_type in allowed_types:
421+
if val_type == 'color':
422422
_utils.assert_color(value)
423-
elif valtype == 'color_none':
423+
elif val_type == 'color_none':
424424
if value is None:
425425
return value
426426
_utils.assert_color(value)
427-
elif valtype == 'color_image':
427+
elif val_type == 'color_image':
428428
if isinstance(value, BaseImage):
429429
return value
430430
_utils.assert_color(value)
431-
elif valtype == 'color_image_none':
431+
elif val_type == 'color_image_none':
432432
if value is None:
433433
return value
434434
elif isinstance(value, BaseImage):
435435
return value
436436
_utils.assert_color(value)
437-
elif valtype == 'position':
437+
elif val_type == 'position':
438438
_utils.assert_position(value)
439-
elif valtype == 'alignment':
439+
elif val_type == 'alignment':
440440
_utils.assert_alignment(value)
441-
elif valtype == 'tuple2':
441+
elif val_type == 'tuple2':
442442
_utils.assert_vector2(value)
443443

444444
all_types = ('color', 'color_none', 'color_image', 'color_image_none',

pygame_menu/utils.py

+1
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ def is_callable(func):
204204
return isinstance(func, (types.FunctionType, types.BuiltinFunctionType, types.MethodType, functools.partial))
205205

206206

207+
# noinspection SpellCheckingInspection
207208
def to_string(s, strict=False):
208209
"""
209210
Check if string, if not convert. See issue #215.

pygame_menu/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ def __str__(self):
5757
patch = property(lambda self: self[2])
5858

5959

60-
vernum = Version(3, 5, 6)
60+
vernum = Version(3, 5, 7)
6161
ver = str(vernum)
6262
rev = ''

pygame_menu/widgets/core/widget.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ def expand_background_inflate_to_selection_effect(self):
298298
Expand background inflate to match the selection effect
299299
(the widget don't require to be selected).
300300
301-
This is a permanent change; for dynamic purpuoses, depending if the widget
301+
This is a permanent change; for dynamic purposes, depending if the widget
302302
is selected or not, setting ``widget.selection_expand_background`` to ``True`` may help.
303303
304304
.. note::

pygame_menu/widgets/examples/scrollbar.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ def make_world(width, height):
5959
world.fill((200, 200, 200))
6060

6161
color = [70, 20, 20]
62-
maxx = len(list(range(100, width, 200)))
63-
maxy = len(list(range(100, height, 200)))
64-
numberx = 0
62+
max_x = len(list(range(100, width, 200)))
63+
max_y = len(list(range(100, height, 200)))
64+
number_x = 0
6565
for x in range(100, width, 200):
66-
numbery = 0
66+
number_y = 0
6767
for y in range(100, height, 200):
68-
if numberx in (0, maxx - 1) or numbery in (0, maxy - 1):
68+
if number_x in (0, max_x - 1) or number_y in (0, max_y - 1):
6969
# White circles to delimit world boundaries
7070
# noinspection PyArgumentList
7171
pygame.draw.circle(world, (255, 255, 255), (x, y), 100, 10)
@@ -78,8 +78,8 @@ def make_world(width, height):
7878
color[1] += 15
7979
else:
8080
color[2] += 15
81-
numbery += 1
82-
numberx += 1
81+
number_y += 1
82+
number_x += 1
8383

8484
return world
8585

pygame_menu/widgets/widget/colorinput.py

+19-19
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def _render(self):
304304
# noinspection PyMissingOrEmptyDocstring
305305
def update(self, events):
306306
_input = self._input_string
307-
_curpos = self._cursor_position
307+
_cur_pos = self._cursor_position
308308
_disable_remove_separator = True
309309

310310
key = '' # Pressed key
@@ -316,19 +316,19 @@ def update(self, events):
316316
if not check_key_pressed_valid(event):
317317
return True
318318

319-
if _disable_remove_separator and len(_input) > 0 and len(_input) > _curpos and (
319+
if _disable_remove_separator and len(_input) > 0 and len(_input) > _cur_pos and (
320320
'{0}{0}'.format(self._separator) not in _input or
321-
_input[_curpos] == self._separator and len(_input) == _curpos + 1
321+
_input[_cur_pos] == self._separator and len(_input) == _cur_pos + 1
322322
):
323323

324324
# Backspace button, delete text from right
325325
if event.key == pygame.K_BACKSPACE:
326-
if len(_input) >= 1 and _input[_curpos - 1] == self._separator:
326+
if len(_input) >= 1 and _input[_cur_pos - 1] == self._separator:
327327
return True
328328

329329
# Delete button, delete text from left
330330
elif event.key == pygame.K_DELETE:
331-
if _input[_curpos] == self._separator:
331+
if _input[_cur_pos] == self._separator:
332332
return True
333333

334334
# Verify only on user key input, the rest of events are checked by TextInput on super call
@@ -362,13 +362,13 @@ def update(self, events):
362362
if key != self._separator:
363363
_pos_before = 0
364364
_pos_after = 0
365-
for _i in range(_curpos):
366-
if _new_string[_curpos - _i - 1] == self._separator:
367-
_pos_before = _curpos - _i
365+
for _i in range(_cur_pos):
366+
if _new_string[_cur_pos - _i - 1] == self._separator:
367+
_pos_before = _cur_pos - _i
368368
break
369-
for _i in range(len(_new_string) - _curpos):
370-
if _new_string[_curpos + _i] == self._separator:
371-
_pos_after = _curpos + _i
369+
for _i in range(len(_new_string) - _cur_pos):
370+
if _new_string[_cur_pos + _i] == self._separator:
371+
_pos_after = _cur_pos + _i
372372
break
373373
if _pos_after == 0:
374374
_pos_after = len(_new_string)
@@ -393,20 +393,20 @@ def update(self, events):
393393

394394
# Backspace button, delete text from right
395395
if event.key == pygame.K_BACKSPACE:
396-
if _curpos == 1:
396+
if _cur_pos == 1:
397397
return True
398398

399399
# Delete button, delete text from left
400400
elif event.key == pygame.K_DELETE:
401-
if _curpos == 0:
401+
if _cur_pos == 0:
402402
return True
403403

404404
# Verify only on user key input, the rest of events are checked by TextInput on super call
405405
key = str(event.unicode)
406406
if key in self._valid_chars:
407407
if key == '#':
408408
return True
409-
if _curpos == 0:
409+
if _cur_pos == 0:
410410
return True
411411

412412
# Update
@@ -433,7 +433,7 @@ def update(self, events):
433433
for c in colors:
434434
if len(c) > 0 and (int(c) > 255 or int(c) < 0):
435435
self._input_string = _input
436-
self._cursor_position = _curpos
436+
self._cursor_position = _cur_pos
437437
break
438438

439439
if len(colors) == 3:
@@ -442,12 +442,12 @@ def update(self, events):
442442
# Add an auto separator if the number can't continue growing and the cursor
443443
# is at the end of the line
444444
if _total_separator < 2 and len(self._input_string) == self._cursor_position:
445-
autopos = len(colors) - 1
446-
last_num = colors[autopos]
445+
auto_pos = len(colors) - 1
446+
last_num = colors[auto_pos]
447447
if (len(last_num) == 2 and int(last_num) > 25 or len(last_num) == 3 and int(last_num) <= 255) and \
448-
autopos not in self._auto_separator_pos:
448+
auto_pos not in self._auto_separator_pos:
449449
self._push_key_input(self._separator, sounds=False) # This calls .onchange()
450-
self._auto_separator_pos.append(autopos)
450+
self._auto_separator_pos.append(auto_pos)
451451

452452
# If the user cleared all the string, reset auto separator
453453
if _total_separator == 0 and \

0 commit comments

Comments
 (0)