diff frontends/src/jp/xmlui_manager.py @ 2541:65695b9343d3

jp (xmlui): added whitelist, read_only and values_only options: - whitelist is set on XMLUI creation, it's the same as for other frontends - read_only is set on XMLUI display, it indicates that input are not expected - values_only is set on XMLUI display, it indicates that only values are to be displayed (it implies read_only)
author Goffi <goffi@goffi.org>
date Thu, 29 Mar 2018 09:09:32 +0200
parents 0046283a285d
children
line wrap: on
line diff
--- a/frontends/src/jp/xmlui_manager.py	Thu Mar 29 09:03:19 2018 +0200
+++ b/frontends/src/jp/xmlui_manager.py	Thu Mar 29 09:09:32 2018 +0200
@@ -235,6 +235,10 @@
     # TODO: handle flags, notably multi
 
     def show(self):
+        if self.root.values_only:
+            for value in self.values:
+                self.disp(self.value)
+                return
         if not self.options:
             return
 
@@ -243,13 +247,13 @@
 
         for idx, (value, label) in enumerate(self.options):
             elems = []
-            if not self.root.readonly:
+            if not self.root.read_only:
                 elems.extend([C.A_SUBHEADER, unicode(idx), A.RESET, u': '])
             elems.append(label)
             self.verboseName(elems, value)
             self.disp(A.color(*elems))
 
-        if self.root.readonly:
+        if self.root.read_only:
             return
 
         if len(self.options) == 1:
@@ -307,6 +311,9 @@
     def _xmluiAppend(self, widget):
         self.children.append(widget)
 
+    def _xmluiRemove(self, widget):
+        self.children.remove(widget)
+
     def show(self):
         for child in self.children:
             child.show()
@@ -333,7 +340,7 @@
                 if for_name is not None:
                     for_widget = self.root.widgets[for_name]
                     wid_type = for_widget.type
-                    if wid_type in ('text', 'string', 'jid_input'):
+                    if self.root.values_only or wid_type in ('text', 'string', 'jid_input'):
                         no_lf = True
                     elif wid_type == 'bool' and for_widget.read_only:
                         no_lf = True
@@ -386,17 +393,19 @@
 class XMLUIPanel(xmlui_manager.XMLUIPanel):
     widget_factory = WidgetFactory()
     _actions = 0  # use to keep track of bridge's launchAction calls
-    readonly = False
+    read_only = False
+    values_only = False
     workflow = None
     _submit_cb = None
 
-    def __init__(self, host, parsed_dom, title=None, flags=None, callback=None, ignore=None, profile=None):
+    def __init__(self, host, parsed_dom, title=None, flags=None, callback=None, ignore=None, whitelist=None, profile=None):
         xmlui_manager.XMLUIPanel.__init__(self,
                                           host,
                                           parsed_dom,
                                           title = title,
                                           flags = flags,
                                           ignore = ignore,
+                                          whitelist = whitelist,
                                           profile=host.profile)
         self.submitted = False
 
@@ -404,7 +413,7 @@
     def command(self):
         return self.host.command
 
-    def show(self, workflow=None):
+    def show(self, workflow=None, read_only=False, values_only=False):
         """display the panel
 
         @param workflow(list, None): command to execute if not None
@@ -413,7 +422,13 @@
             command are a list of consts or lists:
                 - SUBMIT is the only constant so far, it submits the XMLUI
                 - list must contain widget name/widget value to fill
+        @param read_only(bool): if True, don't request values
+        @param values_only(bool): if True, only show select values (imply read_only)
         """
+        self.read_only = read_only
+        self.values_only = values_only
+        if self.values_only:
+            self.read_only = True
         if workflow:
             XMLUIPanel.workflow = workflow
         if XMLUIPanel.workflow:
@@ -491,7 +506,7 @@
 class XMLUIDialog(xmlui_manager.XMLUIDialog):
     type = 'dialog'
     dialog_factory = WidgetFactory()
-    readonly = False
+    read_only = False
 
     def show(self, dummy=None):
         self.dlg.show()