NomadNet/nomadnet/ui/__init__.py

43 lines
1.2 KiB
Python
Raw Normal View History

import os
import glob
2021-04-08 14:57:31 -04:00
import RNS
import nomadnet
2021-04-09 16:07:38 -04:00
modules = glob.glob(os.path.dirname(__file__)+"/*.py")
__all__ = [ os.path.basename(f)[:-3] for f in modules if not f.endswith('__init__.py')]
2021-04-08 14:57:31 -04:00
UI_NONE = 0x00
UI_MENU = 0x01
UI_TEXT = 0x02
UI_GRAPHICAL = 0x03
UI_WEB = 0x04
2022-05-17 07:11:04 -04:00
UI_MODES = [UI_NONE, UI_MENU, UI_TEXT, UI_GRAPHICAL, UI_WEB]
2021-04-08 14:57:31 -04:00
def spawn(uimode):
if uimode in UI_MODES:
2022-05-17 07:11:04 -04:00
if uimode == UI_NONE:
RNS.log("Starting Nomad Network daemon...", RNS.LOG_INFO)
else:
RNS.log("Starting user interface...", RNS.LOG_INFO)
2021-04-08 14:57:31 -04:00
if uimode == UI_MENU:
2021-05-04 14:53:03 -04:00
from .MenuUI import MenuUI
2021-04-08 14:57:31 -04:00
return MenuUI()
elif uimode == UI_TEXT:
2021-05-04 14:53:03 -04:00
from .TextUI import TextUI
2021-04-08 14:57:31 -04:00
return TextUI()
elif uimode == UI_GRAPHICAL:
2021-05-04 14:53:03 -04:00
from .GraphicalUI import GraphicalUI
2021-04-08 14:57:31 -04:00
return GraphicalUI()
elif uimode == UI_WEB:
2021-05-04 14:53:03 -04:00
from .WebUI import WebUI
2021-04-08 14:57:31 -04:00
return WebUI()
2022-05-17 07:11:04 -04:00
elif uimode == UI_NONE:
from .NoneUI import NoneUI
return NoneUI()
2021-04-08 14:57:31 -04:00
else:
return None
else:
2022-05-17 07:11:04 -04:00
RNS.log("Invalid UI mode", RNS.LOG_ERROR, _override_destination=True)
2021-04-08 14:57:31 -04:00
nomadnet.panic()