Added core GUI components and manager

This commit is contained in:
Felipe Martín 2013-11-25 10:46:09 +01:00
parent afee9a32c8
commit f7a0188966
3 changed files with 89 additions and 0 deletions

View File

View File

@ -0,0 +1,44 @@
from iosfu.utils import slugify
class GUIComponent(object):
"""
Base GUI Component object
"""
# Component type, do NOT modify
_type = None
class GUIPanel(GUIComponent):
"""
Pene
"""
_type = 'panel'
# Identifier of the panel. Created automatically as a slug of the name if
# not set. GUIPanel identifiers MUST NOT BE REPEATED.
id = None
# Name of the panel (will be slugified to create an ID)
name = None
def __init__(self):
if not self.id and self.name:
self.id = slugify(self.name)
def __slug__(self):
return slugify(self.name)
class GUISection(GUIComponent):
"""
Pene
"""
_type = 'section'
# A GUIPanel ID
panel = None
# Name of the section
name = None

45
iosfu/gui/core.py Normal file
View File

@ -0,0 +1,45 @@
from importlib import import_module
class GUIController(object):
"""
Object that store and control all the UI compoennts.
"""
_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
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'),
'gui'
)
try:
import_module(gui_module)
except ImportError as error:
# Plugin with no GUI module.
print(error)