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("Apps", MenuType.SUB_MENU, {"sub_menu": [ MenuItem("Chess", MenuType.PLUGIN, {"plugin": "chess", "arg": None}), MenuItem("Cube Timer", MenuType.PLUGIN, {"plugin": "cube", "arg": None}), ]}), MenuItem("Information", MenuType.PLUGIN, {"plugin": "info", "arg": None}), 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() ic(item) if item.menu_type == MenuType.PLUGIN: try: graphics.clear() graphics.text("Loading...", 0, 0, 1) graphics.show() 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.EXIT_CMD: os.system(item.data["command"]) program_exit() except: print_exc() program_exit()