# HG changeset patch # User Goffi # Date 1522306999 -7200 # Node ID 3e03de7691ce318402665f2779b0743af10e0878 # Parent dcc77f23e37034f7ede76e749d2af7d92165cb2c frontends (xmlui): added whitelist argument: when set whitelist indicate that only widgets (and their eventual labels) with names in this list are to be kept. This option is mutually exclusive with ignore. diff -r dcc77f23e370 -r 3e03de7691ce frontends/src/tools/xmlui.py --- a/frontends/src/tools/xmlui.py Thu Mar 29 08:59:38 2018 +0200 +++ b/frontends/src/tools/xmlui.py Thu Mar 29 09:03:19 2018 +0200 @@ -21,7 +21,7 @@ from sat.core.log import getLogger log = getLogger(__name__) from sat_frontends.quick_frontend.constants import Const as C -from sat.core.exceptions import DataError +from sat.core import exceptions class_map = {} @@ -271,7 +271,7 @@ self.host.actionManager(data, profile=profile) def _isAttrSet(self, name, node): - """Returnw widget boolean attribute status + """Return widget boolean attribute status @param name: name of the attribute (e.g. "read_only") @param node: Node instance @@ -334,14 +334,16 @@ class XMLUIPanel(XMLUIBase): """XMLUI Panel - New frontends can inherite this class to easily implement XMLUI + New frontends can inherit this class to easily implement XMLUI @property widget_factory: factory to create frontend-specific widgets @property dialog_factory: factory to create frontend-specific dialogs """ widget_factory = None - def __init__(self, host, parsed_dom, title=None, flags=None, callback=None, ignore=None, profile=C.PROF_KEY_NONE): + def __init__(self, host, parsed_dom, title=None, flags=None, callback=None, ignore=None, whitelist=None, profile=C.PROF_KEY_NONE): """ + + @param title(unicode, None): title of the @property widgets(dict): widget name => widget map @property widget_value(ValueGetter): retrieve widget value from it's name """ @@ -353,6 +355,12 @@ if ignore is None: ignore = [] self._ignore = ignore + if whitelist is not None: + if ignore: + raise exceptions.InternalError('ignore and whitelist must not be used at the same time') + self._whitelist = whitelist + else: + self._whitelist = None self.constructUI(parsed_dom) def escape(self, name): @@ -405,7 +413,7 @@ try: columns = int(node.getAttribute('columns')) except (TypeError, ValueError): - raise DataError("Invalid columns") + raise exceptions.DataError("Invalid columns") selectable = node.getAttribute('selectable') or 'no' auto_index = node.getAttribute('auto_index') == C.BOOL_TRUE data = {'index': 0} if auto_index else None @@ -456,7 +464,7 @@ elif node.nodeName == "widget": name = node.getAttribute("name") - if name in self._ignore: + if name and (name in self._ignore or self._whitelist is not None and name not in self._whitelist): # current widget is ignored, but there may be already a label if CURRENT_LABEL in data: # if so, we remove it from parent @@ -811,12 +819,15 @@ class_map[type_] = class_ -def create(host, xml_data, title=None, flags=None, dom_parse=None, dom_free=None, callback=None, ignore=None, profile=C.PROF_KEY_NONE): +def create(host, xml_data, title=None, flags=None, dom_parse=None, dom_free=None, callback=None, ignore=None, whitelist=None, profile=C.PROF_KEY_NONE): """ @param dom_parse: methode equivalent to minidom.parseString (but which must manage unicode), or None to use default one @param dom_free: method used to free the parsed DOM @param ignore(list[unicode], None): name of widgets to ignore widgets with name in this list and their label will be ignored + @param whitelist(list[unicode], None): name of widgets to keep + when not None, only widgets in this list and their label will be kept + mutually exclusive with ignore """ if dom_parse is None: from xml.dom import minidom @@ -841,6 +852,7 @@ flags = flags, callback = callback, ignore = ignore, + whitelist = whitelist, profile = profile) dom_free(parsed_dom) return xmlui