This repository has been archived on 2022-12-29. You can view files and clone it, but cannot push or open issues or pull requests.
zeropod/__main__.py

79 lines
2.3 KiB
Python
Raw Normal View History

2022-04-23 13:37:54 -05:00
import os
2022-04-23 15:33:19 -05:00
import signal
2022-04-23 18:25:09 -05:00
import time
from traceback import print_exc
2022-04-23 18:25:09 -05:00
from importlib import import_module
2022-04-23 15:44:15 -05:00
from icecream import ic
2022-04-23 13:37:54 -05:00
from menu import Menu, MenuItem, MenuType
from cinput import ControlInput
from graphics import Graphics
2022-04-23 13:37:54 -05:00
menu_config = [
2022-12-27 13:13:51 -06:00
MenuItem("Music",
2022-04-23 15:33:19 -05:00
MenuType.SUB_MENU,
{"sub_menu": [
2022-12-27 13:13:51 -06:00
MenuItem("Artists",
2022-04-23 15:44:15 -05:00
MenuType.PLUGIN,
2022-12-27 13:13:51 -06:00
{"plugin": "music",
"arg": "artists"}),
MenuItem("Genres",
2022-04-30 22:06:56 -05:00
MenuType.PLUGIN,
2022-12-27 13:13:51 -06:00
{"plugin": "music",
"arg": "genres"}),
MenuItem("Playlists",
2022-04-24 13:32:14 -05:00
MenuType.PLUGIN,
2022-12-27 13:13:51 -06:00
{"plugin": "music",
"arg": "playlists"}),
2022-04-23 15:33:19 -05:00
]}),
2022-12-27 13:13:51 -06:00
MenuItem("System",
2022-04-30 22:06:56 -05:00
MenuType.SUB_MENU,
{"sub_menu": [
2022-12-27 13:13:51 -06:00
MenuItem("Information",
2022-04-30 22:06:56 -05:00
MenuType.PLUGIN,
2022-12-27 13:13:51 -06:00
{"plugin": "info",
"arg": None}),
MenuItem("Reboot",
MenuType.EXIT_CMD,
{"command": "sudo reboot"}),
MenuItem("Shutdown",
MenuType.EXIT_CMD,
{"command": "sudo shutdown now"})
2022-04-30 22:06:56 -05:00
]}),
2022-04-23 13:37:54 -05:00
cinput = ControlInput()
graphics = Graphics()
menu = Menu(menu_config, cinput, graphics)
2022-04-23 15:33:19 -05:00
def program_exit(*_):
2022-04-23 13:37:54 -05:00
graphics.clear()
graphics.show()
os._exit(0)
2022-04-23 15:33:19 -05:00
signal.signal(signal.SIGINT, program_exit)
signal.signal(signal.SIGTERM, program_exit)
try:
while True:
item = menu.get_selection()
2022-04-23 18:25:09 -05:00
if item.menu_type == MenuType.PLUGIN:
try:
2022-04-24 10:07:39 -05:00
graphics.clear()
graphics.text("Loading...", 0, 0, 1)
graphics.show()
2022-04-30 22:06:56 -05:00
ic(item)
2022-04-23 18:25:09 -05:00
plugin = import_module("plugin." + item.data["plugin"])
ic(plugin)
2022-04-24 10:07:39 -05:00
plugin.execute(cinput, graphics, item.data["arg"])
except:
print_exc()
2022-04-23 18:25:09 -05:00
graphics.clear()
graphics.text("Plugin error!", 0, 0, 1)
graphics.show()
time.sleep(3)
elif item.menu_type == MenuType.EXIT_CMD:
2022-04-23 15:33:19 -05:00
os.system(item.data["command"])
2022-04-23 15:44:15 -05:00
program_exit()
except:
print_exc()
2022-04-23 15:33:19 -05:00
program_exit()