comparison sat_frontends/tools/xmlui.py @ 2669:bdb8276fd2da

frontends (xmlui): class_map is now an arg of create function: class_map was so far used as a global value, but in some cases, several XMLUI managers may be used (it's the case in Cagou's remote controllers plugins, template_xmlui is used to manage remotes). This patch set class_map as a create argument, this way it can be set with partial, and several XMLUI managers can be instanced at the same time.
author Goffi <goffi@goffi.org>
date Fri, 31 Aug 2018 16:03:12 +0200
parents c274201cea94
children 5c2ed8a5ae22
comparison
equal deleted inserted replaced
2668:c274201cea94 2669:bdb8276fd2da
23 log = getLogger(__name__) 23 log = getLogger(__name__)
24 from sat_frontends.quick_frontend.constants import Const as C 24 from sat_frontends.quick_frontend.constants import Const as C
25 from sat.core import exceptions 25 from sat.core import exceptions
26 26
27 27
28 class_map = {} 28 _class_map = {}
29 CLASS_PANEL = "panel" 29 CLASS_PANEL = "panel"
30 CLASS_DIALOG = "dialog" 30 CLASS_DIALOG = "dialog"
31 CURRENT_LABEL = "current_label" 31 CURRENT_LABEL = "current_label"
32 HIDDEN = "hidden" 32 HIDDEN = "hidden"
33 33
984 @param type_: one of: 984 @param type_: one of:
985 CLASS_PANEL: classical XMLUI interface 985 CLASS_PANEL: classical XMLUI interface
986 CLASS_DIALOG: XMLUI dialog 986 CLASS_DIALOG: XMLUI dialog
987 @param class_: the class to use to instanciate given type 987 @param class_: the class to use to instanciate given type
988 """ 988 """
989 # TODO: remove this method, as there are seme use cases where different XMLUI
990 # classes can be used in the same frontend, so a global value is not good
989 assert type_ in (CLASS_PANEL, CLASS_DIALOG) 991 assert type_ in (CLASS_PANEL, CLASS_DIALOG)
990 class_map[type_] = class_ 992 log.warning(u"registerClass for XMLUI is deprecated, please use partial with "
991 993 u"xmlui.create and class_map instead")
992 994 if type_ in _class_map:
993 def create( 995 log.debug(_(u"XMLUI class already registered for {type_}, ignoring").format(
994 host, 996 type_=type_))
995 xml_data, 997 return
996 title=None, 998
997 flags=None, 999 _class_map[type_] = class_
998 dom_parse=None, 1000
999 dom_free=None, 1001
1000 callback=None, 1002 def create(host, xml_data, title=None, flags=None, dom_parse=None, dom_free=None,
1001 ignore=None, 1003 callback=None, ignore=None, whitelist=None, class_map=None,
1002 whitelist=None, 1004 profile=C.PROF_KEY_NONE):
1003 profile=C.PROF_KEY_NONE,
1004 ):
1005 """ 1005 """
1006 @param dom_parse: methode equivalent to minidom.parseString (but which must manage unicode), or None to use default one 1006 @param dom_parse: methode equivalent to minidom.parseString (but which must manage unicode), or None to use default one
1007 @param dom_free: method used to free the parsed DOM 1007 @param dom_free: method used to free the parsed DOM
1008 @param ignore(list[unicode], None): name of widgets to ignore 1008 @param ignore(list[unicode], None): name of widgets to ignore
1009 widgets with name in this list and their label will be ignored 1009 widgets with name in this list and their label will be ignored
1010 @param whitelist(list[unicode], None): name of widgets to keep 1010 @param whitelist(list[unicode], None): name of widgets to keep
1011 when not None, only widgets in this list and their label will be kept 1011 when not None, only widgets in this list and their label will be kept
1012 mutually exclusive with ignore 1012 mutually exclusive with ignore
1013 """ 1013 """
1014 if class_map is None:
1015 class_map = _class_map
1014 if dom_parse is None: 1016 if dom_parse is None:
1015 from xml.dom import minidom 1017 from xml.dom import minidom
1016 1018
1017 dom_parse = lambda xml_data: minidom.parseString(xml_data.encode("utf-8")) 1019 dom_parse = lambda xml_data: minidom.parseString(xml_data.encode("utf-8"))
1018 dom_free = lambda parsed_dom: parsed_dom.unlink() 1020 dom_free = lambda parsed_dom: parsed_dom.unlink()