71 lines
2.0 KiB
Python
71 lines
2.0 KiB
Python
import os
|
|
import signal
|
|
import time
|
|
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 Exception as e:
|
|
ic(e)
|
|
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 Exception as e:
|
|
ic(e)
|
|
program_exit()
|
|
|