@@ -127,23 +127,23 @@ def __init__(self,
127
127
):
128
128
assert isinstance (height , (int , float ))
129
129
assert isinstance (width , (int , float ))
130
- # assert isinstance (title, str )
130
+ assert _utils . isinstance_str (title )
131
131
132
132
assert isinstance (center_content , bool )
133
133
assert isinstance (column_force_fit_text , bool )
134
134
assert isinstance (column_max_width , (tuple , type (None ), (int , float ), list ))
135
135
assert isinstance (columns , int )
136
136
assert isinstance (enabled , bool )
137
137
assert isinstance (joystick_enabled , bool )
138
- assert isinstance (menu_id , str )
138
+ assert _utils . isinstance_str (menu_id )
139
139
assert isinstance (menu_position , (tuple , list ))
140
140
assert isinstance (mouse_enabled , bool )
141
141
assert isinstance (mouse_motion_selection , bool )
142
142
assert isinstance (mouse_visible , bool )
143
143
assert isinstance (overflow , (tuple , list , bool ))
144
144
assert isinstance (rows , (int , type (None )))
145
145
assert isinstance (screen_dimension , (tuple , list , type (None )))
146
- assert isinstance (theme , _themes .Theme ), 'theme bust be an pygame_menu.themes.Theme object instance'
146
+ assert isinstance (theme , _themes .Theme ), 'theme bust be a pygame_menu.themes.Theme object instance'
147
147
assert isinstance (touchscreen_enabled , bool )
148
148
assert isinstance (touchscreen_motion_selection , bool )
149
149
@@ -468,7 +468,7 @@ def add_button(self,
468
468
469
469
# Get ID
470
470
button_id = kwargs .pop ('button_id' , '' )
471
- assert isinstance (button_id , str ), 'id must be a string'
471
+ assert _utils . isinstance_str (button_id ), 'id must be a string'
472
472
473
473
# Change action if certain events
474
474
if action == _events .PYGAME_QUIT or action == _events .PYGAME_WINDOWCLOSE :
@@ -708,7 +708,7 @@ def add_label(self,
708
708
:return: Widget object, or List of widgets if the text overflows
709
709
:rtype: :py:class:`pygame_menu.widgets.Label`, list[:py:class:`pygame_menu.widgets.Label`]
710
710
"""
711
- assert isinstance (label_id , str )
711
+ assert _utils . isinstance_str (label_id )
712
712
assert isinstance (max_char , int )
713
713
assert isinstance (selectable , bool )
714
714
assert max_char >= - 1
@@ -929,7 +929,9 @@ def add_text_input(self,
929
929
:return: Widget object
930
930
:rtype: :py:class:`pygame_menu.widgets.TextInput`
931
931
"""
932
- assert isinstance (default , (str , int , float ))
932
+ if not isinstance (default , (int , float )):
933
+ assert _utils .isinstance_str (default ), \
934
+ 'default value must be a string, an integer or a float value'
933
935
934
936
# Filter widget attributes to avoid passing them to the callbacks
935
937
attributes = self ._filter_widget_attributes (kwargs )
@@ -1042,7 +1044,7 @@ def _filter_widget_attributes(self, kwargs):
1042
1044
"""
1043
1045
attributes = {}
1044
1046
align = kwargs .pop ('align' , self ._theme .widget_alignment )
1045
- assert isinstance (align , str )
1047
+ assert _utils . isinstance_str (align )
1046
1048
attributes ['align' ] = align
1047
1049
1048
1050
background_is_color = False
@@ -1077,7 +1079,7 @@ def _filter_widget_attributes(self, kwargs):
1077
1079
attributes ['font_color' ] = font_color
1078
1080
1079
1081
font_name = kwargs .pop ('font_name' , self ._theme .widget_font )
1080
- assert isinstance (font_name , str )
1082
+ assert _utils . isinstance_str (font_name )
1081
1083
attributes ['font_name' ] = font_name
1082
1084
1083
1085
font_size = kwargs .pop ('font_size' , self ._theme .widget_font_size )
@@ -1111,7 +1113,7 @@ def _filter_widget_attributes(self, kwargs):
1111
1113
attributes ['shadow_color' ] = shadow_color
1112
1114
1113
1115
shadow_position = kwargs .pop ('shadow_position' , self ._theme .widget_shadow_position )
1114
- assert isinstance (shadow_position , str )
1116
+ assert _utils . isinstance_str (shadow_position )
1115
1117
attributes ['shadow_position' ] = shadow_position
1116
1118
1117
1119
shadow_offset = kwargs .pop ('shadow_offset' , self ._theme .widget_shadow_offset )
@@ -1212,7 +1214,7 @@ def select_widget(self, widget):
1212
1214
:type widget: :py:class:`pygame_menu.widgets.core.widget.Widget`, str
1213
1215
:return: None
1214
1216
"""
1215
- if isinstance (widget , str ):
1217
+ if _utils . isinstance_str (widget ):
1216
1218
widget = self .get_widget (widget_id = widget )
1217
1219
assert isinstance (widget , _widgets .core .Widget )
1218
1220
if not widget .is_selectable :
@@ -1234,7 +1236,7 @@ def remove_widget(self, widget):
1234
1236
:type widget: :py:class:`pygame_menu.widgets.core.widget.Widget`, str
1235
1237
:return: None
1236
1238
"""
1237
- if isinstance (widget , str ):
1239
+ if _utils . isinstance_str (widget ):
1238
1240
widget = self .get_widget (widget_id = widget )
1239
1241
assert isinstance (widget , _widgets .core .Widget )
1240
1242
try :
@@ -1475,7 +1477,7 @@ def _build_widget_surface(self):
1475
1477
sx = self ._scroll .get_scrollbar_thickness (_locals .ORIENTATION_HORIZONTAL , real = True )
1476
1478
sy = self ._scroll .get_scrollbar_thickness (_locals .ORIENTATION_VERTICAL , real = True )
1477
1479
1478
- # Remove the thick of the scrollbar to avoid displaying an horizontal one
1480
+ # Remove the thick of the scrollbar to avoid displaying a horizontal one
1479
1481
# If overflow in both axis
1480
1482
if max_x > self ._width and max_y > self ._height - menubar_height :
1481
1483
width , height = max_x + sy * 0.5 , max_y + sx * 0.25
@@ -1524,7 +1526,7 @@ def _check_id_duplicated(self, widget_id):
1524
1526
:type widget_id: str
1525
1527
:return: None
1526
1528
"""
1527
- assert isinstance (widget_id , str )
1529
+ assert _utils . isinstance_str (widget_id )
1528
1530
for widget in self ._widgets : # type: _widgets.core.Widget
1529
1531
if widget .get_id () == widget_id :
1530
1532
raise IndexError ('widget ID="{0}" already exists on the menu' .format (widget_id ))
@@ -2541,7 +2543,7 @@ def get_widget(self, widget_id, recursive=False):
2541
2543
:return: Widget object
2542
2544
:rtype: :py:class:`pygame_menu.widgets.core.widget.Widget`, None
2543
2545
"""
2544
- assert isinstance (widget_id , str )
2546
+ assert _utils . isinstance_str (widget_id )
2545
2547
assert isinstance (recursive , bool )
2546
2548
for widget in self ._widgets : # type: _widgets.core.Widget
2547
2549
if widget .get_id () == widget_id :
@@ -2651,7 +2653,7 @@ def set_attribute(self, key, value):
2651
2653
:type value: any
2652
2654
:return: None
2653
2655
"""
2654
- assert isinstance (key , str )
2656
+ assert _utils . isinstance_str (key )
2655
2657
self ._attributes [key ] = value
2656
2658
2657
2659
def get_attribute (self , key , default = None ):
@@ -2665,7 +2667,7 @@ def get_attribute(self, key, default=None):
2665
2667
:return: Attribute data
2666
2668
:rtype: any
2667
2669
"""
2668
- assert isinstance (key , str )
2670
+ assert _utils . isinstance_str (key )
2669
2671
if not self .has_attribute (key ):
2670
2672
return default
2671
2673
return self ._attributes [key ]
@@ -2679,7 +2681,7 @@ def has_attribute(self, key):
2679
2681
:return: True if exists
2680
2682
:rtype: bool
2681
2683
"""
2682
- assert isinstance (key , str )
2684
+ assert _utils . isinstance_str (key )
2683
2685
return key in self ._attributes .keys ()
2684
2686
2685
2687
def remove_attribute (self , key ):
0 commit comments