Mercurial > libervia-backend
diff src/tools/xml_tools.py @ 2380:59636c4db2d0
core (xmlui): new "prepend" argument for dataForm2Widgets and dataFormResult2XMLUI:
This argument allow to create widgets which will be put first in LabelContainer of generated XMLUI.
An iterable of *args for XMLUI.addWidget must be used.
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 16 Oct 2017 07:36:03 +0200 |
parents | 318f0434d830 |
children | 2e05921df16a |
line wrap: on
line diff
--- a/src/tools/xml_tools.py Mon Oct 16 07:28:36 2017 +0200 +++ b/src/tools/xml_tools.py Mon Oct 16 07:36:03 2017 +0200 @@ -102,12 +102,15 @@ return widget_type, widget_args, widget_kwargs -def dataForm2Widgets(form_ui, form, read_only=False): +def dataForm2Widgets(form_ui, form, read_only=False, prepend=None): """Complete an existing XMLUI with widget converted from XEP-0004 data forms. @param form_ui (XMLUI): XMLUI instance @param form (data_form.Form): Wokkel's implementation of data form @param read_only (bool): if True and it makes sense, create a read only input widget + @param prepend(iterable, None): widgets to prepend to main LabelContainer + if not None, must be an iterable of *args for addWidget. Those widgets will + be added first to the container. @return: the completed XMLUI instance """ if form.instructions: @@ -115,6 +118,10 @@ form_ui.changeContainer("label") + if prepend is not None: + for widget_args in prepend: + form_ui.addWidget(*widget_args) + for field in form.fieldList: widget_type, widget_args, widget_kwargs = _dataFormField2XMLUIData(field, read_only) label = field.label or field.var @@ -228,13 +235,14 @@ dataForm2Widgets(xml_ui, parsed_form, read_only=True) return xml_ui -def dataFormResult2XMLUI(result_form, base_form, session_id=None): +def dataFormResult2XMLUI(result_form, base_form, session_id=None, prepend=None): """Convert data form result to SàT XMLUI. @param result_form (data_form.Form): result form to convert @param base_form (data_form.Form): initial form (i.e. of form type "form") this one is necessary to reconstruct options when needed (e.g. list elements) @param session_id (unicode): session id to return with the data + @param prepend: same as for [dataForm2Widgets] @return: XMLUI instance """ form = deepcopy(result_form) @@ -245,7 +253,7 @@ continue field.options = base_field.options xml_ui = XMLUI("window", "vertical", session_id=session_id) - dataForm2Widgets(xml_ui, form, read_only=True) + dataForm2Widgets(xml_ui, form, read_only=True, prepend=prepend) return xml_ui