From 5fbe44e849398078951912100a94ef755189b6ac Mon Sep 17 00:00:00 2001 From: Goffi Date: Thu, 29 Mar 2018 09:09:32 +0200 Subject: [PATCH] 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) --- frontends/src/jp/xmlui_manager.py | 29 +++++++++++++++++------ src/plugins/plugin_misc_merge_requests.py | 1 + src/tools/xml_tools.py | 2 +- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/frontends/src/jp/xmlui_manager.py b/frontends/src/jp/xmlui_manager.py index c7dd3875..41b82e01 100644 --- a/frontends/src/jp/xmlui_manager.py +++ b/frontends/src/jp/xmlui_manager.py @@ -235,6 +235,10 @@ class ListWidget(xmlui_manager.ListWidget, OptionsWidget): # 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 @@ class ListWidget(xmlui_manager.ListWidget, OptionsWidget): 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 @@ class Container(Base): 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 @@ class LabelContainer(xmlui_manager.PairsContainer, Container): 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 WidgetFactory(object): 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 @@ class XMLUIPanel(xmlui_manager.XMLUIPanel): 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 @@ class XMLUIPanel(xmlui_manager.XMLUIPanel): 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 XMLUIPanel(xmlui_manager.XMLUIPanel): class XMLUIDialog(xmlui_manager.XMLUIDialog): type = 'dialog' dialog_factory = WidgetFactory() - readonly = False + read_only = False def show(self, dummy=None): self.dlg.show() diff --git a/src/plugins/plugin_misc_merge_requests.py b/src/plugins/plugin_misc_merge_requests.py index 73bee612..70f6eaac 100755 --- a/src/plugins/plugin_misc_merge_requests.py +++ b/src/plugins/plugin_misc_merge_requests.py @@ -145,6 +145,7 @@ class MergeRequests(object): other params are the same as for [TICKETS._get] @return (tuple[list[unicode], list[dict[unicode, unicode]])): tuple with - XMLUI of the tickets, like [TICKETS._get] + - node metadata - list of parsed request data (if extra['parse'] is set, else empty list) """ if not node: diff --git a/src/tools/xml_tools.py b/src/tools/xml_tools.py index 7fb426f9..9d226cf7 100644 --- a/src/tools/xml_tools.py +++ b/src/tools/xml_tools.py @@ -1122,7 +1122,7 @@ class XMLUI(object): @param panel_type: one of - C.XMLUI_WINDOW (new window) - C.XMLUI_POPUP - - C.XMLUI_FORM (formulaire, depend of the frontend, usually a panel with cancel/submit buttons) + - C.XMLUI_FORM (form, depend of the frontend, usually a panel with cancel/submit buttons) - C.XMLUI_PARAM (parameters, presentation depend of the frontend) - C.XMLUI_DIALOG (one common dialog, presentation depend of frontend) @param container: disposition of elements, one of: