changeset 2361:5defafc8ede6

core, frontends (xmlui): new LabelContainer: LabelContainer is like a PairContainer where first widget can only be LabelWidget or EmptyWidget. This case is the most common, and allow to generate better code when label can be associated to widget (e.g. in HTML).
author Goffi <goffi@goffi.org>
date Sun, 24 Sep 2017 16:36:11 +0200
parents 72cbb6478f97
children 3acbaf5c29f5
files frontends/src/primitivus/xmlui.py frontends/src/tools/xmlui.py src/tools/xml_tools.py
diffstat 3 files changed, 21 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/primitivus/xmlui.py	Sun Sep 24 16:32:22 2017 +0200
+++ b/frontends/src/primitivus/xmlui.py	Sun Sep 24 16:36:11 2017 +0200
@@ -279,6 +279,10 @@
         self.addWidget(widget)
 
 
+class PrimitivusLabelContainer(PrimitivusPairsContainer, xmlui.LabelContainer):
+    pass
+
+
 class PrimitivusTabsContainer(xmlui.TabsContainer, sat_widgets.TabsContainer):
 
     def __init__(self, _xmlui_parent):
--- a/frontends/src/tools/xmlui.py	Sun Sep 24 16:32:22 2017 +0200
+++ b/frontends/src/tools/xmlui.py	Sun Sep 24 16:36:11 2017 +0200
@@ -150,7 +150,12 @@
 
 
 class PairsContainer(Container):
-    """Widgets are disposed in rows of two (usually label/input) """
+    """Widgets are disposed in rows of two (usually label/input)"""
+    pass
+
+
+class LabelContainer(Container):
+    """Widgets are associated with label or empty widget"""
     pass
 
 
@@ -364,6 +369,9 @@
                 elif type_ == "pairs":
                     cont = self.widget_factory.createPairsContainer(_xmlui_parent)
                     self._parseChilds(cont, node, ('widget', 'container'))
+                elif type_ == "label":
+                    cont = self.widget_factory.createLabelContainer(_xmlui_parent)
+                    self._parseChilds(cont, node, ('widget', 'container'))
                 elif type_ == "advanced_list":
                     try:
                         columns = int(node.getAttribute('columns'))
--- a/src/tools/xml_tools.py	Sun Sep 24 16:32:22 2017 +0200
+++ b/src/tools/xml_tools.py	Sun Sep 24 16:36:11 2017 +0200
@@ -111,7 +111,7 @@
     if form.instructions:
         form_ui.addText('\n'.join(form.instructions), 'instructions')
 
-    form_ui.changeContainer("pairs")
+    form_ui.changeContainer("label")
 
     for field in form.fieldList:
         widget_type, widget_args, widget_kwargs = _dataFormField2XMLUIData(field, read_only)
@@ -303,7 +303,7 @@
         label = category.getAttribute('label')
         if not category_name:
             raise exceptions.DataError(_('INTERNAL ERROR: params categories must have a name'))
-        tabs_cont.addTab(category_name, label=label, container=PairsContainer)
+        tabs_cont.addTab(category_name, label=label, container=LabelContainer)
         for param in category.getElementsByTagName("param"):
             widget_kwargs = {}
 
@@ -596,6 +596,10 @@
     type = "pairs"
 
 
+class LabelContainer(Container):
+    type = "label"
+
+
 class TabsContainer(Container):
     type = "tabs"
 
@@ -1042,6 +1046,8 @@
             - horizontal: elements are disposed left to right
             - pairs: elements come on two aligned columns
               (usually one for a label, the next for the element)
+            - label: associations of one LabelWidget or EmptyWidget with an other widget
+                similar to pairs but specialized in LabelWidget, and not necessarily arranged in 2 columns
             - tabs: elemens are in categories with tabs (notebook)
         @param dialog_opt: only used if panel_type == C.XMLUI_DIALOG. Dictionnary (string/string) where key can be:
             - C.XMLUI_DATA_TYPE: type of dialog, value can be: