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

87 lines
2.6 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 = [
MenuItem("Apps",
2022-04-23 15:33:19 -05:00
MenuType.SUB_MENU,
{"sub_menu": [
2022-04-30 22:06:56 -05:00
MenuItem("Chess Game",
2022-04-23 15:44:15 -05:00
MenuType.PLUGIN,
2022-04-24 10:07:39 -05:00
{"plugin": "chess",
2022-04-30 22:06:56 -05:00
"arg": "game"}),
MenuItem("Chess Puzzles",
MenuType.PLUGIN,
{"plugin": "chess",
"arg": "puzzles"}),
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-30 22:06:56 -05:00
MenuItem("Config",
MenuType.SUB_MENU,
{"sub_menu": [
MenuItem("Brightness",
MenuType.PLUGIN,
{"plugin": "config",
"arg": "brightness"}),
MenuItem("Wifi",
MenuType.PLUGIN,
{"plugin": "config",
"arg": "wifi"}),
]}),
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
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()