mirror of
https://github.com/markqvist/NomadNet.git
synced 2025-02-25 01:19:57 -05:00
User interface skeleton
This commit is contained in:
parent
9fdcbf11b8
commit
fbc151060e
@ -1,7 +1,10 @@
|
|||||||
import os
|
import os
|
||||||
import RNS
|
|
||||||
import atexit
|
import atexit
|
||||||
|
|
||||||
|
import RNS
|
||||||
|
import nomadnet
|
||||||
|
|
||||||
|
from ._version import __version__
|
||||||
from .vendor.configobj import ConfigObj
|
from .vendor.configobj import ConfigObj
|
||||||
|
|
||||||
class NomadNetworkApp:
|
class NomadNetworkApp:
|
||||||
@ -9,14 +12,17 @@ class NomadNetworkApp:
|
|||||||
|
|
||||||
configdir = os.path.expanduser("~")+"/.nomadnetwork"
|
configdir = os.path.expanduser("~")+"/.nomadnetwork"
|
||||||
|
|
||||||
def exit_handler():
|
def exit_handler(self):
|
||||||
RNS.log("Nomad Network Client exit handler executing...")
|
RNS.log("Nomad Network Client exit handler executing...")
|
||||||
|
|
||||||
def __init__(self, configdir = None, rnsconfigdir = None):
|
def __init__(self, configdir = None, rnsconfigdir = None):
|
||||||
|
self.version = __version__
|
||||||
self.enable_client = False
|
self.enable_client = False
|
||||||
self.enable_node = False
|
self.enable_node = False
|
||||||
self.identity = None
|
self.identity = None
|
||||||
|
|
||||||
|
self.uimode = None
|
||||||
|
|
||||||
if configdir == None:
|
if configdir == None:
|
||||||
self.configdir = NomadNetworkApp.configdir
|
self.configdir = NomadNetworkApp.configdir
|
||||||
else:
|
else:
|
||||||
@ -47,7 +53,7 @@ class NomadNetworkApp:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
RNS.log("Could not parse the configuration at "+self.configpath, RNS.LOG_ERROR)
|
RNS.log("Could not parse the configuration at "+self.configpath, RNS.LOG_ERROR)
|
||||||
RNS.log("Check your configuration file for errors!", RNS.LOG_ERROR)
|
RNS.log("Check your configuration file for errors!", RNS.LOG_ERROR)
|
||||||
RNS.panic()
|
nomadnet.panic()
|
||||||
else:
|
else:
|
||||||
RNS.log("Could not load config file, creating default configuration file...")
|
RNS.log("Could not load config file, creating default configuration file...")
|
||||||
self.createDefaultConfig()
|
self.createDefaultConfig()
|
||||||
@ -62,11 +68,11 @@ class NomadNetworkApp:
|
|||||||
RNS.log("Loaded Primary Identity %s from %s" % (str(self.identity), self.identitypath))
|
RNS.log("Loaded Primary Identity %s from %s" % (str(self.identity), self.identitypath))
|
||||||
else:
|
else:
|
||||||
RNS.log("Could not load the Primary Identity from "+self.identitypath, RNS.LOG_ERROR)
|
RNS.log("Could not load the Primary Identity from "+self.identitypath, RNS.LOG_ERROR)
|
||||||
RNS.panic()
|
nomadnet.panic()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
RNS.log("Could not load the Primary Identity from "+self.identitypath, RNS.LOG_ERROR)
|
RNS.log("Could not load the Primary Identity from "+self.identitypath, RNS.LOG_ERROR)
|
||||||
RNS.log("The contained exception was: %s" % (str(e)), RNS.LOG_ERROR)
|
RNS.log("The contained exception was: %s" % (str(e)), RNS.LOG_ERROR)
|
||||||
RNS.panic()
|
nomadnet.panic()
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
RNS.log("No Primary Identity file found, creating new...")
|
RNS.log("No Primary Identity file found, creating new...")
|
||||||
@ -79,11 +85,11 @@ class NomadNetworkApp:
|
|||||||
RNS.panic()
|
RNS.panic()
|
||||||
|
|
||||||
self.applyConfig()
|
self.applyConfig()
|
||||||
|
|
||||||
self.rns = RNS.Reticulum(configdir = rnsconfigdir)
|
self.rns = RNS.Reticulum(configdir = rnsconfigdir)
|
||||||
|
|
||||||
atexit.register(self.exit_handler)
|
atexit.register(self.exit_handler)
|
||||||
|
|
||||||
|
self.ui = nomadnet.ui.spawn(self.uimode)
|
||||||
|
|
||||||
|
|
||||||
def createDefaultConfig(self):
|
def createDefaultConfig(self):
|
||||||
self.config = ConfigObj(__default_nomadnet_config__)
|
self.config = ConfigObj(__default_nomadnet_config__)
|
||||||
@ -114,6 +120,19 @@ class NomadNetworkApp:
|
|||||||
value = self.config["client"].as_bool(option)
|
value = self.config["client"].as_bool(option)
|
||||||
self.enable_client = value
|
self.enable_client = value
|
||||||
|
|
||||||
|
if option == "user_interface":
|
||||||
|
value = value.lower()
|
||||||
|
if value == "none":
|
||||||
|
self.uimode = nomadnet.ui.UI_NONE
|
||||||
|
if value == "menu":
|
||||||
|
self.uimode = nomadnet.ui.UI_MENU
|
||||||
|
if value == "text":
|
||||||
|
self.uimode = nomadnet.ui.UI_TEXT
|
||||||
|
if value == "graphical":
|
||||||
|
self.uimode = nomadnet.ui.UI_GRAPHICAL
|
||||||
|
if value == "web":
|
||||||
|
self.uimode = nomadnet.ui.UI_WEB
|
||||||
|
|
||||||
if "node" in self.config:
|
if "node" in self.config:
|
||||||
for option in self.config["node"]:
|
for option in self.config["node"]:
|
||||||
value = self.config["node"][option]
|
value = self.config["node"][option]
|
||||||
@ -155,6 +174,7 @@ loglevel = 4
|
|||||||
[client]
|
[client]
|
||||||
|
|
||||||
enable_client = Yes
|
enable_client = Yes
|
||||||
|
user_interface = text
|
||||||
|
|
||||||
[node]
|
[node]
|
||||||
|
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
import os
|
import os
|
||||||
import glob
|
import glob
|
||||||
|
|
||||||
|
from .NomadNetworkApp import NomadNetworkApp
|
||||||
|
from .ui import *
|
||||||
|
|
||||||
|
|
||||||
modules = glob.glob(os.path.dirname(__file__)+"/*.py")
|
modules = glob.glob(os.path.dirname(__file__)+"/*.py")
|
||||||
__all__ = [ os.path.basename(f)[:-3] for f in modules if not f.endswith('__init__.py')]
|
__all__ = [ os.path.basename(f)[:-3] for f in modules if not f.endswith('__init__.py')]
|
||||||
|
|
||||||
|
def panic():
|
||||||
|
os._exit(255)
|
@ -1,14 +1,13 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import argparse
|
|
||||||
|
|
||||||
from ._version import __version__
|
from ._version import __version__
|
||||||
from .NomadNetworkApp import NomadNetworkApp
|
|
||||||
|
import argparse
|
||||||
|
import nomadnet
|
||||||
|
|
||||||
|
|
||||||
def program_setup(configdir, rnsconfigdir):
|
def program_setup(configdir, rnsconfigdir):
|
||||||
app = NomadNetworkApp(configdir = configdir, rnsconfigdir = rnsconfigdir)
|
app = nomadnet.NomadNetworkApp(configdir = configdir, rnsconfigdir = rnsconfigdir)
|
||||||
input()
|
|
||||||
app.quit()
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
try:
|
try:
|
||||||
|
8
nomadnet/ui/GraphicalUI.py
Normal file
8
nomadnet/ui/GraphicalUI.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import RNS
|
||||||
|
import nomadnet
|
||||||
|
|
||||||
|
class GraphicalUI:
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
RNS.log("Graphical UI not implemented", RNS.LOG_ERROR)
|
||||||
|
nomadnet.panic()
|
8
nomadnet/ui/MenuUI.py
Normal file
8
nomadnet/ui/MenuUI.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import RNS
|
||||||
|
import nomadnet
|
||||||
|
|
||||||
|
class MenuUI:
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
RNS.log("Menu UI not implemented", RNS.LOG_ERROR)
|
||||||
|
nomadnet.panic()
|
39
nomadnet/ui/TextUI.py
Normal file
39
nomadnet/ui/TextUI.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import RNS
|
||||||
|
from nomadnet import NomadNetworkApp
|
||||||
|
import importlib
|
||||||
|
|
||||||
|
class TextUI:
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.app = NomadNetworkApp.get_shared_instance()
|
||||||
|
|
||||||
|
self.loop = None
|
||||||
|
self.main_widget = None
|
||||||
|
|
||||||
|
if importlib.util.find_spec("urwid") != None:
|
||||||
|
import urwid
|
||||||
|
else:
|
||||||
|
RNS.log("The text-mode user interface requires Urwid to be installed on your system.", RNS.LOG_ERROR)
|
||||||
|
RNS.log("You can install it with the command: pip3 install urwid", RNS.LOG_ERROR)
|
||||||
|
nomadnet.panic()
|
||||||
|
|
||||||
|
loop = urwid.MainLoop(self.build_intro())
|
||||||
|
loop.run()
|
||||||
|
|
||||||
|
def build_intro(self):
|
||||||
|
import urwid
|
||||||
|
|
||||||
|
font = urwid.font.HalfBlock5x4Font()
|
||||||
|
|
||||||
|
big_text = "Nomad Network"
|
||||||
|
big_text = urwid.BigText(("intro_bigtext", big_text), font)
|
||||||
|
big_text = urwid.Padding(big_text, align="center", width="clip")
|
||||||
|
|
||||||
|
intro = urwid.Pile([
|
||||||
|
big_text,
|
||||||
|
urwid.Text(["Version %s" % (str(self.app.version))], align="center"),
|
||||||
|
urwid.Divider(),
|
||||||
|
urwid.Text(("intro_smalltext", "-= Starting =-"), align="center"),
|
||||||
|
])
|
||||||
|
|
||||||
|
return urwid.Filler(intro)
|
8
nomadnet/ui/WebUI.py
Normal file
8
nomadnet/ui/WebUI.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import RNS
|
||||||
|
import nomadnet
|
||||||
|
|
||||||
|
class WebUI:
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
RNS.log("Web UI not implemented", RNS.LOG_ERROR)
|
||||||
|
nomadnet.panic()
|
@ -1,5 +1,37 @@
|
|||||||
import os
|
import os
|
||||||
import glob
|
import glob
|
||||||
|
import RNS
|
||||||
|
import nomadnet
|
||||||
|
|
||||||
|
from .MenuUI import MenuUI
|
||||||
|
from .TextUI import TextUI
|
||||||
|
from .GraphicalUI import GraphicalUI
|
||||||
|
from .WebUI import WebUI
|
||||||
|
|
||||||
|
UI_NONE = 0x00
|
||||||
|
UI_MENU = 0x01
|
||||||
|
UI_TEXT = 0x02
|
||||||
|
UI_GRAPHICAL = 0x03
|
||||||
|
UI_WEB = 0x04
|
||||||
|
|
||||||
|
UI_MODES = [UI_MENU, UI_TEXT, UI_GRAPHICAL, UI_WEB]
|
||||||
|
|
||||||
modules = glob.glob(os.path.dirname(__file__)+"/*.py")
|
modules = glob.glob(os.path.dirname(__file__)+"/*.py")
|
||||||
__all__ = [ os.path.basename(f)[:-3] for f in modules if not f.endswith('__init__.py')]
|
__all__ = [ os.path.basename(f)[:-3] for f in modules if not f.endswith('__init__.py')]
|
||||||
|
|
||||||
|
def spawn(uimode):
|
||||||
|
if uimode in UI_MODES:
|
||||||
|
RNS.log("Starting user interface...", RNS.LOG_INFO)
|
||||||
|
if uimode == UI_MENU:
|
||||||
|
return MenuUI()
|
||||||
|
elif uimode == UI_TEXT:
|
||||||
|
return TextUI()
|
||||||
|
elif uimode == UI_GRAPHICAL:
|
||||||
|
return GraphicalUI()
|
||||||
|
elif uimode == UI_WEB:
|
||||||
|
return WebUI()
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
RNS.log("Invalid UI mode", RNS.LOG_ERROR)
|
||||||
|
nomadnet.panic()
|
Loading…
x
Reference in New Issue
Block a user