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

91 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 = [
2022-12-27 13:40:50 -06:00
MenuItem("Music",
2022-12-28 08:35:28 -06:00
MenuType.PLUGIN,
{"plugin": "music",
"arg": "music"}),
MenuItem("Podcasts",
MenuType.PLUGIN,
{"plugin": "music",
"arg": "podcasts"}),
MenuItem("Audiobooks",
MenuType.PLUGIN,
{"plugin": "music",
"arg": "audiobooks"}),
2022-12-27 13:40:50 -06:00
MenuItem("System",
MenuType.SUB_MENU,
{"sub_menu": [
MenuItem("Information",
MenuType.PLUGIN,
{"plugin": "info",
"arg": None}),
2022-12-28 08:35:28 -06:00
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"}),
]}),
2022-12-27 13:40:50 -06:00
MenuItem("Reboot",
MenuType.EXIT_CMD,
{"command": "sudo reboot"}),
MenuItem("Shutdown",
MenuType.EXIT_CMD,
{"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)
2022-12-28 08:35:28 -06:00
elif item.menu_type == MenuType.CMD:
graphics.clear()
graphics.text("Executing...", 0, 0, 1)
graphics.show()
os.system(item.data["command"])
2022-04-23 18:25:09 -05:00
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()