Added Sections to GUI

This commit is contained in:
Felipe Martín 2013-11-26 15:22:27 +01:00
parent c66cc06154
commit 5dda61c441
4 changed files with 36 additions and 6 deletions

View File

@ -36,3 +36,13 @@ def panel(panel_id=None):
"""
panel = controller.load_panel(panel_id)
return "{}".format(panel().__slug__)
@server.route("/<panel_id>.<section_id>")
def section(panel_id=None, section_id=None):
"""
Section
"""
panel = controller.load_panel(panel_id)
section = panel.get_section(section_id)
return "{}.{}".format(panel.__slug__, section.__slug__)

View File

@ -26,10 +26,32 @@ class GUIPanel(GUIComponent):
# List of sections
sections = []
# Section mapping by id
_section_map = {}
def __init__(self):
if not self.id and self.name:
self.id = slugify(self.name)
self._map_sections()
def get_section(self, section_id):
if section_id in self._section_map:
return self.sections[self._section_map[section_id]]()
#
# Privates
#
def _map_sections(self):
"""
Map section list position to its id in a dict()
"""
i = 0
for section in self.sections:
ins = section()
self._section_map[ins.__slug__] = i
i += 1
@property
def __slug__(self):
return self.id
@ -49,10 +71,8 @@ class GUISection(GUIComponent):
name = None
def __init__(self):
if not self.id and (self.name and self.panel):
self.id = "{}.{}".format(
slugify(self.panel), slugify(self.name)
)
if not self.id and self.name:
self.id = "{}".format(slugify(self.name))
@property
def __slug__(self):

View File

@ -34,4 +34,4 @@ class GUIController(object):
def load_panel(self, panel_id):
if panel_id in self._panels:
return self._panels[panel_id]
return self._panels[panel_id]()

View File

@ -6,7 +6,7 @@ controller = GUIController()
class Main(GUISection):
name = 'main'
name = 'Main'
class VersionInfo(GUISection):