ability to back out of music menus
This commit is contained in:
parent
24c769218a
commit
c0be9136a5
3 changed files with 12 additions and 4 deletions
6
menu.py
6
menu.py
|
@ -8,6 +8,7 @@ class MenuType(Enum):
|
|||
CMD = auto()
|
||||
EXIT_CMD = auto()
|
||||
PLUGIN = auto()
|
||||
BACK = auto()
|
||||
|
||||
@dataclass
|
||||
class MenuItem:
|
||||
|
@ -16,6 +17,8 @@ class MenuItem:
|
|||
data: dict
|
||||
|
||||
class Menu:
|
||||
STR_BACK = "BACK"
|
||||
|
||||
def __init__(
|
||||
self, config: list[MenuItem], cinput: ControlInput, graphics: Graphics):
|
||||
self._top_index = 0
|
||||
|
@ -65,6 +68,9 @@ class Menu:
|
|||
elif pressed == Button.BTN_A or pressed == Button.DIR_L:
|
||||
if len(self._menu_path) > 0:
|
||||
self._selected_index = self._menu_path.pop()
|
||||
else:
|
||||
return MenuItem(self.STR_BACK, MenuType.BACK, {})
|
||||
|
||||
|
||||
self._cur_menu = self._menu
|
||||
for i in range(0, len(self._menu_path)):
|
||||
|
|
|
@ -31,11 +31,11 @@ def create_directory_menu(directory: str, dirname: str, is_resume: bool):
|
|||
return MenuItem(dirname, MenuType.SUB_MENU, {"sub_menu": dir_menu})
|
||||
else:
|
||||
if is_resume:
|
||||
return MenuItem(dirname, MenuType.CMD, {
|
||||
return MenuItem(dirname.lstrip("_"), MenuType.CMD, {
|
||||
"dir": directory,
|
||||
"mode": "resume"})
|
||||
else:
|
||||
return MenuItem(dirname, MenuType.SUB_MENU, {
|
||||
return MenuItem(dirname.lstrip("_"), MenuType.SUB_MENU, {
|
||||
"sub_menu": [
|
||||
MenuItem("Play", MenuType.CMD, {
|
||||
"dir": directory,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from menu import Menu
|
||||
from menu import Menu, MenuType
|
||||
from cinput import ControlInput
|
||||
from graphics import Graphics
|
||||
|
||||
|
@ -10,4 +10,6 @@ class MusicPlayer:
|
|||
|
||||
def run(self):
|
||||
while True:
|
||||
self._menu.get_selection()
|
||||
item = self._menu.get_selection()
|
||||
if item.menu_type == MenuType.BACK:
|
||||
return
|
||||
|
|
Reference in a new issue