Mercurial > libervia-backend
diff src/tools/xml_tools.py @ 760:73a0077f80cc
backend, frontends: XMLUI refactoring:
- session_id is resent in result data if found in incoming data
- list now use distinct labels and values (label is the one displayed, value is the one used for everything else)
- misc refactoring
/!\ urwid SàtExt must be updated ! /!\
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 24 Dec 2013 15:19:18 +0100 |
parents | 93bd868b8fb6 |
children | 2f8d72226bc0 |
line wrap: on
line diff
--- a/src/tools/xml_tools.py Tue Dec 24 15:19:08 2013 +0100 +++ b/src/tools/xml_tools.py Tue Dec 24 15:19:18 2013 +0100 @@ -219,7 +219,7 @@ class XMLUI(object): """This class is used to create a user interface (form/window/parameters/etc) using SàT XML""" - def __init__(self, panel_type, layout="vertical", title=None, submit_id=None): + def __init__(self, panel_type, layout="vertical", title=None, submit_id=None, session_id=None): """Init SàT XML Panel @param panel_type: one of - window (new window) @@ -234,9 +234,10 @@ @param title: title or default if None @param submit_id: callback id to call for panel_type we can submit (form, param) """ - if not panel_type in ['window', 'form', 'param']: - error(_("Unknown panel type [%s]") % panel_type) - assert(False) + if panel_type not in ['window', 'form', 'param']: + raise exceptions.DataError(_("Unknown panel type [%s]") % panel_type) + if panel_type == 'form' and submit_id is None: + raise exceptions.DataError(_("form XMLUI need a submit_id")) self.type_ = panel_type impl = minidom.getDOMImplementation() @@ -247,6 +248,8 @@ top_element.setAttribute("title", title) if submit_id: top_element.setAttribute("submit", submit_id) + if session_id is not None: + top_element.setAttribute("session_id", session_id) self.parentTabsLayout = None # used only we have 'tabs' layout self.currentCategory = None # used only we have 'tabs' layout self.currentLayout = None @@ -255,6 +258,12 @@ def __del__(self): self.doc.unlink() + def setSessionId(self, session_id): + assert(session_id) + top_element = self.doc.documentElement + top_element.setAttribute("session_id", session_id) + + def _createLayout(self, layout, parent=None): """Create a layout element @param type: layout type (cf init doc) @@ -415,7 +424,12 @@ @param parent: multi-values element""" for option in options: opt = self.doc.createElement('option') - opt.setAttribute('value', option) + if isinstance(option, basestring): + value, label = option, option + elif isinstance(option, tuple): + value, label = option + opt.setAttribute('value', value) + opt.setAttribute('label', label) parent.appendChild(opt) # Advanced list