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 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 10:08:56 -05:00
|
|
|
|
2022-04-23 13:37:54 -05:00
|
|
|
menu_config = [
|
|
|
|
MenuItem("Apps",
|
2022-04-23 15:33:19 -05:00
|
|
|
MenuType.SUB_MENU,
|
|
|
|
{"sub_menu": [
|
|
|
|
MenuItem("Chess",
|
2022-04-23 15:44:15 -05:00
|
|
|
MenuType.PLUGIN,
|
2022-04-24 10:07:39 -05:00
|
|
|
{"plugin": "chess",
|
|
|
|
"arg": None}),
|
2022-04-24 13:32:14 -05:00
|
|
|
MenuItem("Cube Timer",
|
|
|
|
MenuType.PLUGIN,
|
|
|
|
{"plugin": "cube",
|
|
|
|
"arg": None}),
|
2022-04-23 15:33:19 -05:00
|
|
|
]}),
|
2022-04-23 18:25:09 -05:00
|
|
|
MenuItem("Information",
|
|
|
|
MenuType.PLUGIN,
|
2022-04-24 10:07:39 -05:00
|
|
|
{"plugin": "info",
|
|
|
|
"arg": None}),
|
2022-04-23 13:37:54 -05:00
|
|
|
MenuItem("Reboot",
|
2022-04-23 15:44:15 -05:00
|
|
|
MenuType.EXIT_CMD,
|
2022-04-23 15:33:19 -05:00
|
|
|
{"command": "sudo reboot"}),
|
2022-04-23 13:37:54 -05:00
|
|
|
MenuItem("Shutdown",
|
2022-04-23 15:44:15 -05:00
|
|
|
MenuType.EXIT_CMD,
|
2022-04-23 15:33:19 -05:00
|
|
|
{"command": "sudo shutdown now"})]
|
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
|
|
|
ic(item)
|
|
|
|
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-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 Exception as e:
|
|
|
|
ic(e)
|
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()
|
2022-04-23 15:33:19 -05:00
|
|
|
except Exception as e:
|
|
|
|
ic(e)
|
|
|
|
program_exit()
|
|
|
|
|