mirror of https://github.com/fmartingr/iosfu.git
Simplified GUI API: Now sections are included within the GUIPanel instance, instead of register GUIPanel and GUISection in separate ways. Easy.
This commit is contained in:
parent
e6ffc2f9b5
commit
c66cc06154
|
@ -1,33 +1,38 @@
|
|||
from flask import Flask
|
||||
from flask import Flask, session
|
||||
|
||||
from iosfu.conf import ROOT_PATH
|
||||
from iosfu.plugin.library import Library
|
||||
from iosfu.gui.core import GUIController
|
||||
|
||||
|
||||
server = Flask(__name__)
|
||||
|
||||
# Secret key for sessions
|
||||
server.secret_key = '123456' # Local app, simple session ID.
|
||||
|
||||
# Plugin library loading
|
||||
library = Library()
|
||||
library.discover()
|
||||
|
||||
# Gui controller loading
|
||||
controller = GUIController()
|
||||
controller.load_from_library(library)
|
||||
|
||||
|
||||
#
|
||||
# ROUTES
|
||||
#
|
||||
@server.route("/")
|
||||
def main():
|
||||
result = """
|
||||
Executed from: {0}<br />
|
||||
""".format(ROOT_PATH)
|
||||
return result
|
||||
"""
|
||||
Main page
|
||||
"""
|
||||
return 'Main page'
|
||||
|
||||
|
||||
@server.route("/<panel>/")
|
||||
@server.route("/<panel_id>")
|
||||
def panel(panel_id=None):
|
||||
"""
|
||||
Panel
|
||||
"""
|
||||
panel = controller.load_panel(panel_id)
|
||||
return panel
|
||||
|
||||
|
||||
@server.route("/<panel>/<section>/")
|
||||
def section(panel_id=None, section_id=None):
|
||||
return 'lol'
|
||||
return "{}".format(panel().__slug__)
|
||||
|
|
|
@ -23,6 +23,9 @@ class GUIPanel(GUIComponent):
|
|||
# Name of the panel (will be slugified to create an ID)
|
||||
name = None
|
||||
|
||||
# List of sections
|
||||
sections = []
|
||||
|
||||
def __init__(self):
|
||||
if not self.id and self.name:
|
||||
self.id = slugify(self.name)
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
from importlib import import_module
|
||||
|
||||
from .components.base import GUIPanel
|
||||
|
||||
|
||||
class GUIController(object):
|
||||
"""
|
||||
|
@ -9,33 +11,19 @@ class GUIController(object):
|
|||
_panels = {}
|
||||
_sections = {}
|
||||
|
||||
def register(self, component):
|
||||
"""
|
||||
Decorator to register plugins
|
||||
"""
|
||||
ins = component()
|
||||
|
||||
print(ins)
|
||||
|
||||
if ins._type == 'panel':
|
||||
self.register_panel(component)
|
||||
|
||||
if ins._type == 'section':
|
||||
self.register_section(component)
|
||||
|
||||
def register_panel(self, panel_component):
|
||||
self._panels['a'] = panel_component
|
||||
pass
|
||||
|
||||
def register_section(self, section_component):
|
||||
print('register section')
|
||||
pass
|
||||
"""
|
||||
Decorator to register GUIPanels
|
||||
"""
|
||||
ins = panel_component()
|
||||
assert isinstance(ins, GUIPanel)
|
||||
self._panels[ins.__slug__] = panel_component
|
||||
|
||||
def load_from_library(self, library):
|
||||
for k, plugin in library.plugins.items():
|
||||
plugin_module = plugin.__module__
|
||||
gui_module = "{0}.{1}".format(
|
||||
plugin_module.rstrip('.plugin'),
|
||||
plugin_module.rsplit('.', 1)[0],
|
||||
'gui'
|
||||
)
|
||||
try:
|
||||
|
@ -43,3 +31,7 @@ class GUIController(object):
|
|||
except ImportError as error:
|
||||
# Plugin with no GUI module.
|
||||
print(error)
|
||||
|
||||
def load_panel(self, panel_id):
|
||||
if panel_id in self._panels:
|
||||
return self._panels[panel_id]
|
||||
|
|
|
@ -1,11 +1,25 @@
|
|||
from iosfu.gui.core import GUIController, GUIPanel
|
||||
from iosfu.gui.core import GUIController
|
||||
from iosfu.gui.components.base import GUIPanel, GUISection
|
||||
|
||||
|
||||
controller = GUIController()
|
||||
|
||||
|
||||
@controller.register
|
||||
class Main(GUISection):
|
||||
name = 'main'
|
||||
|
||||
|
||||
class VersionInfo(GUISection):
|
||||
name = 'Version Info'
|
||||
|
||||
|
||||
@controller.register_panel
|
||||
class DeviceInfoPanel(GUIPanel):
|
||||
id = 'device-info'
|
||||
|
||||
name = 'Device info'
|
||||
|
||||
sections = [
|
||||
Main,
|
||||
VersionInfo
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue