quick frontend (quick widgets): class' __name__ method is used for classes_map hash because the use of class directly was causing bugs with pyjamas (difficult to find, several MicroblogPanel instances were added only once in Libervia's TabPanel, hash method seemed buggy)

This commit is contained in:
Goffi 2015-02-06 19:05:51 +01:00
commit 679e5759bb

View file

@ -40,7 +40,11 @@ def register(base_cls, child_cls=None):
@param child_cls: inherited class to use when Quick... class is requested, must inherit from base_cls.
Can be None if it's the base_cls itself which register
"""
classes_map[base_cls] = child_cls
# FIXME: we use base_cls.__name__ instead of base_cls directly because pyjamas because
# in the second case
classes_map[base_cls.__name__] = child_cls
class WidgetAlreadyExistsError(Exception):
pass
@ -66,7 +70,9 @@ class QuickWidgetsManager(object):
@return: class actually used to create widget
"""
try:
cls = classes_map[class_]
# FIXME: we use base_cls.__name__ instead of base_cls directly because pyjamas bugs
# in the second case
cls = classes_map[class_.__name__]
except KeyError:
cls = class_
if cls is None:
@ -81,7 +87,7 @@ class QuickWidgetsManager(object):
"""
class_ = self.getRealClass(class_)
try:
widgets_map = self._widgets[class_]
widgets_map = self._widgets[class_.__name__]
except KeyError:
return iter([])
else:
@ -139,8 +145,9 @@ class QuickWidgetsManager(object):
except KeyError:
hash_ = cls.getWidgetHash(target, _kwargs['profiles'])
# widget creation or retrieval
widgets_map = self._widgets.setdefault(cls, {}) # we sorts widgets by classes
## widget creation or retrieval ##
widgets_map = self._widgets.setdefault(cls.__name__, {}) # we sorts widgets by classes
if not cls.SINGLE:
widget = None # if the class is not SINGLE, we always create a new widget
else: