# HG changeset patch # User Goffi # Date 1508132163 -7200 # Node ID 59636c4db2d0821e65b701c7fec7c32dc82d1f39 # Parent 42a54cbc1872022f4e145473821cf7c12e6dbd93 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. diff -r 42a54cbc1872 -r 59636c4db2d0 src/tools/xml_tools.py --- 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