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 ! /!\
This commit is contained in:
Goffi 2013-12-24 15:19:18 +01:00
commit 80a7423f02

View file

@ -219,7 +219,7 @@ class Field(object):
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 @@ class XMLUI(object):
@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 @@ class XMLUI(object):
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 @@ class XMLUI(object):
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 @@ class XMLUI(object):
@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