Skip to content

Commit

Permalink
Added format_selection method
Browse files Browse the repository at this point in the history
  • Loading branch information
ppizarror committed Jan 30, 2019
1 parent 551934d commit 5a87318
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
17 changes: 15 additions & 2 deletions pygameMenu/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Selector class, manage elements and adds entries to menu.
The MIT License (MIT)
Copyright 2017-2018 Pablo Pizarro R. @ppizarror
Copyright 2017-2019 Pablo Pizarro R. @ppizarror
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -54,6 +54,9 @@ def __init__(self, title, elements, onchange=None, onreturn=None, default=0, **k
self._title = title
self._total_elements = len(elements)

# Selection format
self._sformat = '{0} < {1} >'

# Apply default item
default %= self._total_elements
for k in range(0, default):
Expand Down Expand Up @@ -109,14 +112,24 @@ def change(self):
else:
self._on_change(*paraml)

def format_selection(self, s):
"""
Change the selection text.
:param s: Selection text
:type s: basestring
:return:
"""
self._sformat = s

def get(self):
"""
Return element text.
:return: Element text
:rtype: str
"""
return '{0} < {1} >'.format(self._title, self._elements[self._index][0])
return self._sformat.format(self._title, self._elements[self._index][0])

def left(self):
"""
Expand Down
5 changes: 2 additions & 3 deletions pygameMenu/textmenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Menu with text and buttons.
The MIT License (MIT)
Copyright 2017-2018 Pablo Pizarro R. @ppizarror
Copyright 2017-2019 Pablo Pizarro R. @ppizarror
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -50,8 +50,7 @@ def __init__(self,
text_color=_cfg.TEXT_FONT_COLOR,
text_fontsize=_cfg.MENU_FONT_TEXT_SIZE,
text_margin=_cfg.TEXT_MARGIN,
**kwargs
):
**kwargs):
"""
TextMenu constructor.
Expand Down

0 comments on commit 5a87318

Please sign in to comment.