Skip to content

Commit

Permalink
Merge pull request #112 from ppizarror/add-types
Browse files Browse the repository at this point in the history
Improve type
  • Loading branch information
ppizarror committed Apr 3, 2020
2 parents 24020d6 + fdad266 commit cbd9863
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 62 deletions.
2 changes: 1 addition & 1 deletion pygameMenu/widgets/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def __init__(self,
args=args,
kwargs=kwargs
)
self._label = label
self._label = label # type: str

def _apply_font(self):
"""
Expand Down
15 changes: 7 additions & 8 deletions pygameMenu/widgets/colorinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def __init__(self,
'9'], 'input_separator cannot be a number'

_maxchar = 0
self._color_type = color_type.lower()
self._color_type = color_type.lower() # type: str
if self._color_type == _TYPE_RGB:
_maxchar = 11 # RRR,GGG,BBB
self._valid_chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', input_separator]
Expand Down Expand Up @@ -146,15 +146,14 @@ def __init__(self,
)

# Store inner variables
self._separator = input_separator
self._separator = input_separator # type: str

# Previsualization surface, if -1 previsualization does not show
self._last_r = -1
self._last_g = -1
self._last_b = -1
self._prev_surface = None
self._prev_render_width = None
self._prev_size = prev_size
self._last_r = -1 # type: int
self._last_g = -1 # type: int
self._last_b = -1 # type: int
self._prev_surface = None # type: _pygame.Surface
self._prev_size = prev_size # type: int

def clear(self):
"""
Expand Down
10 changes: 5 additions & 5 deletions pygameMenu/widgets/menubar.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ def __init__(self,
kwargs=kwargs
)

self._backbox = back_box
self._backbox = back_box # type: bool
self._backbox_pos = None # type: tuple
self._backbox_rect = None # type: _pygame.rect.RectType
self._label = label
self._offsetx = 0
self._offsety = 0
self._label = label # type: str
self._offsetx = 0 # type: int
self._offsety = 0 # type: int
self._polygon_pos = None # type: tuple
self._width = width
self._width = width # type: (int,float)

def _apply_font(self):
"""
Expand Down
41 changes: 20 additions & 21 deletions pygameMenu/widgets/scrollbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,35 +62,34 @@ def __init__(self,
onreturn=None,
*args,
**kwargs):

assert isinstance(length, (int, float))
assert isinstance(values_range, (tuple, list))
assert values_range[1] > values_range[0], "Minimum value first is expected"
assert values_range[1] > values_range[0], 'minimum value first is expected'
assert isinstance(slider_pad, (int, float))
assert isinstance(page_ctrl_thick, (int, float))
assert page_ctrl_thick - 2 * slider_pad >= 2, "slider shall be visible"
assert page_ctrl_thick - 2 * slider_pad >= 2, 'slider shall be visible'

super(ScrollBar, self).__init__(widget_id=scrollbar_id,
onchange=onchange,
onreturn=onreturn,
args=args,
kwargs=kwargs)
self._values_range = list(values_range)
self._scrolling = False
self._orientation = 0
self._opp_orientation = int(not self._orientation)
self._values_range = list(values_range) # type: list
self._scrolling = False # type: bool
self._orientation = 0 # type: int
self._opp_orientation = int(not self._orientation) # type: int

self._page_ctrl_length = length
self._page_ctrl_thick = page_ctrl_thick
self._page_ctrl_color = page_ctrl_color
self._page_ctrl_length = length # type: int
self._page_ctrl_thick = page_ctrl_thick # type: (int,float)
self._page_ctrl_color = page_ctrl_color # type: tuple

self._slider_rect = None # type: _pygame.rect.RectType
self._slider_pad = slider_pad
self._slider_color = slider_color
self._slider_position = 0
self._slider_pad = slider_pad # type: (int,float)
self._slider_color = slider_color # type: tuple
self._slider_position = 0 # type: int
self._slider_length = None # type: int

self._single_step = 20
self._single_step = 20 # type: int
self._page_step = None # type: int

if values_range[1] - values_range[0] > length:
Expand Down Expand Up @@ -154,7 +153,7 @@ def get_page_step(self):
page control surface.
"""
return self._page_step * (self._values_range[1] - self._values_range[0]) / \
(self._page_ctrl_length - self._slider_length)
(self._page_ctrl_length - self._slider_length)

def get_value(self):
"""
Expand All @@ -164,7 +163,7 @@ def get_value(self):
:rtype: int
"""
value = self._values_range[0] + self._slider_position * \
(self._values_range[1] - self._values_range[0]) / (self._page_ctrl_length - self._slider_length)
(self._values_range[1] - self._values_range[0]) / (self._page_ctrl_length - self._slider_length)

# Correction due to value scaling
value = max(self._values_range[0], value)
Expand Down Expand Up @@ -206,10 +205,10 @@ def _scroll(self, pixels):

axis = self._orientation
space_before = self._rect.topleft[axis] - \
self._slider_rect.move(self._rect.topleft).topleft[axis] + self._slider_pad
self._slider_rect.move(*self._rect.topleft).topleft[axis] + self._slider_pad
move = max(round(pixels), space_before)
space_after = self._rect.bottomright[axis] - \
self._slider_rect.move(self._rect.topleft).bottomright[axis] - self._slider_pad
self._slider_rect.move(*self._rect.topleft).bottomright[axis] - self._slider_pad
move = min(move, space_after)
if not move:
return False
Expand Down Expand Up @@ -293,7 +292,7 @@ def set_value(self, value):
assert self._values_range[0] <= value <= self._values_range[1]

pixels = 1.0 * (value - self._values_range[0]) * (self._page_ctrl_length - self._slider_length) / \
(self._values_range[1] - self._values_range[0])
(self._values_range[1] - self._values_range[0])

# Correction due to value scaling
pixels = max(0, pixels)
Expand Down Expand Up @@ -321,11 +320,11 @@ def update(self, events):
updated = True
else:
# The _slider_rect origin is related to the widget surface
if self._slider_rect.move(self._rect.topleft).collidepoint(event.pos):
if self._slider_rect.move(*self._rect.topleft).collidepoint(event.pos):
# Initialize scrolling
self._scrolling = True

elif self._rect.collidepoint(event.pos):
elif self._rect.collidepoint(*event.pos):
# Moves towards the click by one "page" (= slider length without pad)
pos = (self._slider_rect.x, self._slider_rect.y)
direction = 1 if event.pos[self._orientation] > pos[self._orientation] else -1
Expand Down
10 changes: 5 additions & 5 deletions pygameMenu/widgets/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ def __init__(self,
onreturn=onreturn,
kwargs=kwargs)

self._elements = elements
self._index = 0
self._label = label
self._labelsize = 0
self._sformat = '{0} < {1} >'
self._elements = elements # type: list
self._index = 0 # type: int
self._label = label # type: str
self._labelsize = 0 # type: int
self._sformat = '{0} < {1} >' # type: str

# Apply default item
default %= len(self._elements)
Expand Down
44 changes: 22 additions & 22 deletions pygameMenu/widgets/textinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,17 +219,17 @@ def __init__(self,
self._cursor_offset = -1
self._cursor_position = 0 # Inside text
self._cursor_render = True # If true cursor must be rendered
self._cursor_surface = None
self._cursor_surface = None # type: _pygame.Surface
self._cursor_surface_pos = [0, 0] # Position (x,y) of surface
self._cursor_switch_ms = 500
self._cursor_switch_ms = 500 # type: int
self._cursor_visible = False # Switches every self._cursor_switch_ms ms

# History of editions
self._history = []
self._history_cursor = []
self._history_renderbox = []
self._history = [] # type: list
self._history_cursor = [] # type: list
self._history_renderbox = [] # type: list
self._history_index = 0 # Index at which the new editions are added
self._max_history = history
self._max_history = history # type: int

# Text selection
self._last_selection_render = [0, 0]
Expand All @@ -240,7 +240,7 @@ def __init__(self,
self._selection_mouse_first_position = -1
self._selection_position = [0, 0] # (x,y)
self._selection_render = False
self._selection_surface = None # type: _pygame.SurfaceType
self._selection_surface = None # type: _pygame.Surface

# List of valid chars
if valid_chars is not None:
Expand All @@ -253,25 +253,25 @@ def __init__(self,
self._valid_chars = valid_chars

# Other
self._copy_paste_enabled = enable_copy_paste
self._first_render = True
self._input_type = input_type
self._input_underline = input_underline
self._input_underline_size = 0
self._keychar_size = {'': 0}
self._label = label
self._label_size = 0
self._last_char = ''
self._last_rendered_string = '__pygameMenu__last_render_string__'
self._last_rendered_surface = None
self._copy_paste_enabled = enable_copy_paste # type: bool
self._first_render = True # type: bool
self._input_type = input_type # type: str
self._input_underline = input_underline # type: bool
self._input_underline_size = 0 # type: int
self._keychar_size = {'': 0} # type: dict
self._label = label # type: str
self._label_size = 0 # type: int
self._last_char = '' # type: str
self._last_rendered_string = '__pygameMenu__last_render_string__' # type: str
self._last_rendered_surface = None # type: _pygame.Surface
self._last_rendered_surface_underline_width = 0
self._maxchar = maxchar
self._maxchar = maxchar # type: int
self._maxwidth = maxwidth # This value will be changed depending on how many chars are printed
self._maxwidth_base = maxwidth
self._maxwidth_update = maxwidth_dynamically_update
self._maxwidth_base = maxwidth # type: int
self._maxwidth_update = maxwidth_dynamically_update # type: bool
self._maxwidthsize = 0 # Updated in font
self._password = password # True/False
self._password_char = password_char
self._password_char = password_char # type: str

def _apply_font(self):
"""
Expand Down

0 comments on commit cbd9863

Please sign in to comment.