ability to back out of music menus
This commit is contained in:
parent
24c769218a
commit
c0be9136a5
6
menu.py
6
menu.py
|
@ -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)):
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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
|
||||||
|
|
Reference in New Issue