ability to back out of music menus

This commit is contained in:
Rudis Muiznieks 2022-12-28 11:26:30 -06:00
parent 24c769218a
commit c0be9136a5
Signed by: rudism
GPG Key ID: CABF2F86EF7884F9
3 changed files with 12 additions and 4 deletions

View File

@ -8,6 +8,7 @@ class MenuType(Enum):
CMD = auto() CMD = auto()
EXIT_CMD = auto() EXIT_CMD = auto()
PLUGIN = auto() PLUGIN = auto()
BACK = auto()
@dataclass @dataclass
class MenuItem: class MenuItem:
@ -16,6 +17,8 @@ class MenuItem:
data: dict data: dict
class Menu: class Menu:
STR_BACK = "BACK"
def __init__( def __init__(
self, config: list[MenuItem], cinput: ControlInput, graphics: Graphics): self, config: list[MenuItem], cinput: ControlInput, graphics: Graphics):
self._top_index = 0 self._top_index = 0
@ -65,6 +68,9 @@ class Menu:
elif pressed == Button.BTN_A or pressed == Button.DIR_L: elif pressed == Button.BTN_A or pressed == Button.DIR_L:
if len(self._menu_path) > 0: if len(self._menu_path) > 0:
self._selected_index = self._menu_path.pop() self._selected_index = self._menu_path.pop()
else:
return MenuItem(self.STR_BACK, MenuType.BACK, {})
self._cur_menu = self._menu self._cur_menu = self._menu
for i in range(0, len(self._menu_path)): for i in range(0, len(self._menu_path)):

View File

@ -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}) return MenuItem(dirname, MenuType.SUB_MENU, {"sub_menu": dir_menu})
else: else:
if is_resume: if is_resume:
return MenuItem(dirname, MenuType.CMD, { return MenuItem(dirname.lstrip("_"), MenuType.CMD, {
"dir": directory, "dir": directory,
"mode": "resume"}) "mode": "resume"})
else: else:
return MenuItem(dirname, MenuType.SUB_MENU, { return MenuItem(dirname.lstrip("_"), MenuType.SUB_MENU, {
"sub_menu": [ "sub_menu": [
MenuItem("Play", MenuType.CMD, { MenuItem("Play", MenuType.CMD, {
"dir": directory, "dir": directory,

View File

@ -1,4 +1,4 @@
from menu import Menu from menu import Menu, MenuType
from cinput import ControlInput from cinput import ControlInput
from graphics import Graphics from graphics import Graphics
@ -10,4 +10,6 @@ class MusicPlayer:
def run(self): def run(self):
while True: while True:
self._menu.get_selection() item = self._menu.get_selection()
if item.menu_type == MenuType.BACK:
return