import os import signal import time from traceback import print_exc from importlib import import_module from icecream import ic from menu import Menu, MenuItem, MenuType from cinput import ControlInput from graphics import Graphics menu_config = [ MenuItem("Music", MenuType.PLUGIN, {"plugin": "music", "arg": "music"}), MenuItem("Podcasts", MenuType.PLUGIN, {"plugin": "music", "arg": "podcasts"}), MenuItem("Audiobooks", MenuType.PLUGIN, {"plugin": "music", "arg": "audiobooks"}), MenuItem("System", MenuType.SUB_MENU, {"sub_menu": [ MenuItem("Information", MenuType.PLUGIN, {"plugin": "info", "arg": None}), MenuItem("Wireless", MenuType.SUB_MENU, {"sub_menu": [ MenuItem("Reset Wifi", MenuType.CMD, {"command": "sudo sv restart wpa_supplicant"}), MenuItem("Reset Bluetooth", MenuType.CMD, {"command": "sudo sv restart bluetoothd"}), ]}), MenuItem("Reboot", MenuType.EXIT_CMD, {"command": "sudo reboot"}), MenuItem("Shutdown", MenuType.EXIT_CMD, {"command": "sudo shutdown now"}) ]}), ] cinput = ControlInput() graphics = Graphics() menu = Menu(menu_config, cinput, graphics) def program_exit(*_): graphics.clear() graphics.show() os._exit(0) signal.signal(signal.SIGINT, program_exit) signal.signal(signal.SIGTERM, program_exit) try: while True: item = menu.get_selection() if item.menu_type == MenuType.PLUGIN: try: graphics.clear() graphics.text("Loading...", 0, 0, 1) graphics.show() ic(item) plugin = import_module("plugin." + item.data["plugin"]) ic(plugin) plugin.execute(cinput, graphics, item.data["arg"]) except: print_exc() graphics.clear() graphics.text("Plugin error!", 0, 0, 1) graphics.show() time.sleep(3) elif item.menu_type == MenuType.CMD: graphics.clear() graphics.text("Executing...", 0, 0, 1) graphics.show() os.system(item.data["command"]) elif item.menu_type == MenuType.EXIT_CMD: os.system(item.data["command"]) program_exit() except: print_exc() program_exit()