comparison frontends/src/quick_frontend/quick_widgets.py @ 1304:1a61b18703c4 frontends_multi_profiles

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)
author Goffi <goffi@goffi.org>
date Fri, 06 Feb 2015 19:05:51 +0100
parents d3ef3894254d
children 9512590dc3d7
comparison
equal deleted inserted replaced
1303:d3ef3894254d 1304:1a61b18703c4
38 38
39 @param base_cls: "Quick..." base class (like QuickChat or QuickContact), must inherit from QuickWidget 39 @param base_cls: "Quick..." base class (like QuickChat or QuickContact), must inherit from QuickWidget
40 @param child_cls: inherited class to use when Quick... class is requested, must inherit from base_cls. 40 @param child_cls: inherited class to use when Quick... class is requested, must inherit from base_cls.
41 Can be None if it's the base_cls itself which register 41 Can be None if it's the base_cls itself which register
42 """ 42 """
43 classes_map[base_cls] = child_cls 43 # FIXME: we use base_cls.__name__ instead of base_cls directly because pyjamas because
44 # in the second case
45 classes_map[base_cls.__name__] = child_cls
46
47
44 class WidgetAlreadyExistsError(Exception): 48 class WidgetAlreadyExistsError(Exception):
45 pass 49 pass
46 50
47 51
48 class QuickWidgetsManager(object): 52 class QuickWidgetsManager(object):
64 68
65 @param class_: subclass of QuickWidget 69 @param class_: subclass of QuickWidget
66 @return: class actually used to create widget 70 @return: class actually used to create widget
67 """ 71 """
68 try: 72 try:
69 cls = classes_map[class_] 73 # FIXME: we use base_cls.__name__ instead of base_cls directly because pyjamas bugs
74 # in the second case
75 cls = classes_map[class_.__name__]
70 except KeyError: 76 except KeyError:
71 cls = class_ 77 cls = class_
72 if cls is None: 78 if cls is None:
73 raise exceptions.InternalError("There is not class registered for {}".format(class_)) 79 raise exceptions.InternalError("There is not class registered for {}".format(class_))
74 return cls 80 return cls
79 @param class_: subclass of QuickWidget, same parameter as used in [getOrCreateWidget] 85 @param class_: subclass of QuickWidget, same parameter as used in [getOrCreateWidget]
80 @return: iterator on widgets 86 @return: iterator on widgets
81 """ 87 """
82 class_ = self.getRealClass(class_) 88 class_ = self.getRealClass(class_)
83 try: 89 try:
84 widgets_map = self._widgets[class_] 90 widgets_map = self._widgets[class_.__name__]
85 except KeyError: 91 except KeyError:
86 return iter([]) 92 return iter([])
87 else: 93 else:
88 return widgets_map.itervalues() 94 return widgets_map.itervalues()
89 95
137 try: 143 try:
138 hash_ = _kwargs.pop('force_hash') 144 hash_ = _kwargs.pop('force_hash')
139 except KeyError: 145 except KeyError:
140 hash_ = cls.getWidgetHash(target, _kwargs['profiles']) 146 hash_ = cls.getWidgetHash(target, _kwargs['profiles'])
141 147
142 # widget creation or retrieval 148 ## widget creation or retrieval ##
143 widgets_map = self._widgets.setdefault(cls, {}) # we sorts widgets by classes 149
150 widgets_map = self._widgets.setdefault(cls.__name__, {}) # we sorts widgets by classes
144 if not cls.SINGLE: 151 if not cls.SINGLE:
145 widget = None # if the class is not SINGLE, we always create a new widget 152 widget = None # if the class is not SINGLE, we always create a new widget
146 else: 153 else:
147 try: 154 try:
148 widget = widgets_map[hash_] 155 widget = widgets_map[hash_]