frontends (xmlui): added an attribute to ignore some widgets (and their label) in create

This commit is contained in:
Goffi 2017-11-05 13:53:28 +01:00
commit fc2af0da9e
4 changed files with 40 additions and 8 deletions

View file

@ -390,8 +390,14 @@ class XMLUIPanel(xmlui_manager.XMLUIPanel):
workflow = None
_submit_cb = None
def __init__(self, host, parsed_dom, title=None, flags=None, callback=None, profile=None):
xmlui_manager.XMLUIPanel.__init__(self, host, parsed_dom, title, flags, profile=host.profile)
def __init__(self, host, parsed_dom, title=None, flags=None, callback=None, ignore=None, profile=None):
xmlui_manager.XMLUIPanel.__init__(self,
host,
parsed_dom,
title = title,
flags = flags,
ignore = ignore,
profile=host.profile)
self.submitted = False
@property

View file

@ -393,10 +393,17 @@ class WidgetFactory(GenericFactory):
class XMLUIPanel(xmlui.XMLUIPanel, PrimitivusWidget):
widget_factory = WidgetFactory()
def __init__(self, host, parsed_xml, title=None, flags=None, callback=None, profile=C.PROF_KEY_NONE):
def __init__(self, host, parsed_xml, title=None, flags=None, callback=None, ignore=None, profile=C.PROF_KEY_NONE):
self.widget_factory._xmlui_main = self
self._dest = None
xmlui.XMLUIPanel.__init__(self, host, parsed_xml, title, flags, callback, profile)
xmlui.XMLUIPanel.__init__(self,
host,
parsed_xml,
title = title,
flags = flags,
callback = callback,
ignore = ignore,
profile = profile)
PrimitivusWidget.__init__(self, self.main_cont, self.xmlui_title)
def constructUI(self, parsed_dom):

View file

@ -340,7 +340,7 @@ class XMLUIPanel(XMLUIBase):
"""
widget_factory = None
def __init__(self, host, parsed_dom, title=None, flags=None, callback=None, profile=C.PROF_KEY_NONE):
def __init__(self, host, parsed_dom, title=None, flags=None, callback=None, ignore=None, profile=C.PROF_KEY_NONE):
"""
@property widgets(dict): widget name => widget map
@property widget_value(ValueGetter): retrieve widget value from it's name
@ -350,6 +350,9 @@ class XMLUIPanel(XMLUIBase):
self.widgets = {} # allow to access any named widgets
self.widget_value = ValueGetter(self.widgets)
self._main_cont = None
if ignore is None:
ignore = []
self._ignore = ignore
self.constructUI(parsed_dom)
def escape(self, name):
@ -453,6 +456,12 @@ class XMLUIPanel(XMLUIBase):
elif node.nodeName == "widget":
name = node.getAttribute("name")
if name in self._ignore:
# current widget is ignored, but there may be already a label
if CURRENT_LABEL in data:
# if so, we remove it from parent
_xmlui_parent._xmluiRemove(data.pop(CURRENT_LABEL))
continue
type_ = node.getAttribute("type")
value_elt = self._getChildNode(node, "value")
if value_elt is not None:
@ -748,7 +757,7 @@ class XMLUIPanel(XMLUIBase):
class XMLUIDialog(XMLUIBase):
dialog_factory = None
def __init__(self, host, parsed_dom, title=None, flags=None, callback=None, profile=C.PROF_KEY_NONE):
def __init__(self, host, parsed_dom, title=None, flags=None, callback=None, ignore=None, profile=C.PROF_KEY_NONE):
super(XMLUIDialog, self).__init__(host, parsed_dom, title=title, flags=flags, callback=callback, profile=profile)
top=parsed_dom.documentElement
dlg_elt = self._getChildNode(top, "dialog")
@ -802,10 +811,12 @@ def registerClass(type_, class_):
class_map[type_] = class_
def create(host, xml_data, title=None, flags=None, dom_parse=None, dom_free=None, callback=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, 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
"""
if dom_parse is None:
from xml.dom import minidom
@ -825,6 +836,11 @@ def create(host, xml_data, title=None, flags=None, dom_parse=None, dom_free=None
except KeyError:
raise ClassNotRegistedError(_("You must register classes with registerClass before creating a XMLUI"))
xmlui = cls(host, parsed_dom, title, flags, callback, profile)
xmlui = cls(host, parsed_dom,
title = title,
flags = flags,
callback = callback,
ignore = ignore,
profile = profile)
dom_free(parsed_dom)
return xmlui

View file

@ -145,6 +145,9 @@ class Container(object):
def _xmluiAppend(self, widget):
self.children.append(widget)
def _xmluiRemove(self, widget):
self.children.remove(widget)
class VerticalContainer(xmlui.VerticalContainer, Container):
type = u'vertical'