comparison src/browser/sat_browser/base_widget.py @ 589:a5019e62c3e9 frontends_multi_profiles

browser side: big refactoring to base Libervia on QuickFrontend, first draft: /!\ not finished, partially working and highly instable - add collections module with an OrderedDict like class - SatWebFrontend inherit from QuickApp - general sat_frontends tools.jid module is used - bridge/json methods have moved to json module - UniBox is partially removed (should be totally removed before merge to trunk) - Signals are now register with the generic registerSignal method (which is called mainly in QuickFrontend) - the generic getOrCreateWidget method from QuickWidgetsManager is used instead of Libervia's specific methods - all Widget are now based more or less directly on QuickWidget - with the new QuickWidgetsManager.getWidgets method, it's no more necessary to check all widgets which are instance of a particular class - ChatPanel and related moved to chat module - MicroblogPanel and related moved to blog module - global and overcomplicated send method has been disabled: each class should manage its own sending - for consistency with other frontends, former ContactPanel has been renamed to ContactList and vice versa - for the same reason, ChatPanel has been renamed to Chat - for compatibility with QuickFrontend, a fake profile is used in several places, it is set to C.PROF_KEY_NONE (real profile is managed server side for obvious security reasons) - changed default url for web panel to SàT website, and contact address to generic SàT contact address - ContactList is based on QuickContactList, UI changes are done in update method - bride call (now json module) have been greatly improved, in particular call can be done in the same way as for other frontends (bridge.method_name(arg1, arg2, ..., callback=cb, errback=eb). Blocking method must be called like async methods due to javascript architecture - in bridge calls, a callback can now exists without errback - hard reload on BridgeSignals remote error has been disabled, a better option should be implemented - use of constants where that make sens, some style improvments - avatars are temporarily disabled - lot of code disabled, will be fixed or removed before merge - various other changes, check diff for more details server side: manage remote exception on getEntityData, removed getProfileJid call, added getWaitingConf, added getRoomsSubjects
author Goffi <goffi@goffi.org>
date Sat, 24 Jan 2015 01:45:39 +0100
parents b07f0fe2763a
children a099990f77a6
comparison
equal deleted inserted replaced
585:bade589dbd5a 589:a5019e62c3e9
175 menu_styles = {'menu_bar': 'widgetHeader_buttonGroup'} 175 menu_styles = {'menu_bar': 'widgetHeader_buttonGroup'}
176 if styles: 176 if styles:
177 menu_styles.update(styles) 177 menu_styles.update(styles)
178 base_menu.GenericMenuBar.__init__(self, host, vertical=vertical, styles=menu_styles) 178 base_menu.GenericMenuBar.__init__(self, host, vertical=vertical, styles=menu_styles)
179 179
180 if hasattr(parent, 'addMenus'): 180 # FIXME
181 # regroup all the dynamic menu categories in a sub-menu 181 # if hasattr(parent, 'addMenus'):
182 sub_menu = WidgetSubMenuBar(host, vertical=True) 182 # # regroup all the dynamic menu categories in a sub-menu
183 parent.addMenus(sub_menu) 183 # sub_menu = WidgetSubMenuBar(host, vertical=True)
184 if len(sub_menu.getCategories()) > 0: 184 # parent.addMenus(sub_menu)
185 self.addCategory('', '', 'plugins', sub_menu) 185 # if len(sub_menu.getCategories()) > 0:
186 # self.addCategory('', '', 'plugins', sub_menu)
186 187
187 @classmethod 188 @classmethod
188 def getCategoryHTML(cls, menu_name_i18n, type_): 189 def getCategoryHTML(cls, menu_name_i18n, type_):
189 return cls.ITEM_TPL % type_ 190 return cls.ITEM_TPL % type_
190 191
229 class LiberviaWidget(DropCell, VerticalPanel, ClickHandler): 230 class LiberviaWidget(DropCell, VerticalPanel, ClickHandler):
230 """Libervia's widget which can replace itself with a dropped widget on DnD""" 231 """Libervia's widget which can replace itself with a dropped widget on DnD"""
231 232
232 def __init__(self, host, title='', info=None, selectable=False): 233 def __init__(self, host, title='', info=None, selectable=False):
233 """Init the widget 234 """Init the widget
235
234 @param host (SatWebFrontend): SatWebFrontend instance 236 @param host (SatWebFrontend): SatWebFrontend instance
235 @param title (str): title shown in the header of the widget 237 @param title (str): title shown in the header of the widget
236 @param info (str, callable): info shown in the header of the widget 238 @param info (str, callable): info shown in the header of the widget
237 @param selectable (bool): True is widget can be selected by user""" 239 @param selectable (bool): True is widget can be selected by user
240 """
238 VerticalPanel.__init__(self) 241 VerticalPanel.__init__(self)
239 DropCell.__init__(self, host) 242 DropCell.__init__(self, host)
240 ClickHandler.__init__(self) 243 ClickHandler.__init__(self)
241 self.__selectable = selectable 244 self._selectable = selectable
242 self.__title_id = HTMLPanel.createUniqueId() 245 self._title_id = HTMLPanel.createUniqueId()
243 self.__setting_button_id = HTMLPanel.createUniqueId() 246 self._setting_button_id = HTMLPanel.createUniqueId()
244 self.__close_button_id = HTMLPanel.createUniqueId() 247 self._close_button_id = HTMLPanel.createUniqueId()
245 self.__title = Label(title) 248 self._title = Label(title)
246 self.__title.setStyleName('widgetHeader_title') 249 self._title.setStyleName('widgetHeader_title')
247 if info is not None: 250 if info is not None:
248 if isinstance(info, str): 251 if isinstance(info, str):
249 self.__info = HTML(info) 252 self._info = HTML(info)
250 else: # the info will be set by a callback 253 else: # the info will be set by a callback
251 assert(callable(info)) 254 assert callable(info)
252 self.__info = HTML() 255 self._info = HTML()
253 info(self.__info.setHTML) 256 info(self._info.setHTML)
254 self.__info.setStyleName('widgetHeader_info') 257 self._info.setStyleName('widgetHeader_info')
255 else: 258 else:
256 self.__info = None 259 self._info = None
257 self._close_listeners = [] 260 self._close_listeners = []
258 header = WidgetHeader(self, host, self.__title, self.__info) 261 header = WidgetHeader(self, host, self._title, self._info)
259 self.add(header) 262 self.add(header)
260 self.setSize('100%', '100%') 263 self.setSize('100%', '100%')
261 self.addStyleName('widget') 264 self.addStyleName('widget')
262 if self.__selectable: 265 if self._selectable:
263 self.addClickListener(self) 266 self.addClickListener(self)
264 267
265 def onClose(sender): 268 def onClose(sender):
266 """Check dynamically if the unibox is enable or not""" 269 """Check dynamically if the unibox is enable or not"""
267 if self.host.uni_box: 270 if self.host.uni_box:
268 self.host.uni_box.onWidgetClosed(sender) 271 self.host.uni_box.onWidgetClosed(sender)
269 272
270 self.addCloseListener(onClose) 273 self.addCloseListener(onClose)
271 self.host.registerWidget(self) 274 # self.host.registerWidget(self) # FIXME
272 275
273 def getDebugName(self): 276 def getDebugName(self):
274 return "%s (%s)" % (self, self.__title.getText()) 277 return "%s (%s)" % (self, self._title.getText())
275 278
276 def getWidgetsPanel(self, expect=True): 279 def getWidgetsPanel(self, expect=True):
277 return self.getParent(WidgetsPanel, expect) 280 return self.getParent(WidgetsPanel, expect)
278 281
279 def getParent(self, class_=None, expect=True): 282 def getParent(self, class_=None, expect=True):
390 _dialog.show() 393 _dialog.show()
391 394
392 def setTitle(self, text): 395 def setTitle(self, text):
393 """change the title in the header of the widget 396 """change the title in the header of the widget
394 @param text: text of the new title""" 397 @param text: text of the new title"""
395 self.__title.setText(text) 398 self._title.setText(text)
396 399
397 def setHeaderInfo(self, text): 400 def setHeaderInfo(self, text):
398 """change the info in the header of the widget 401 """change the info in the header of the widget
399 @param text: text of the new title""" 402 @param text: text of the new title"""
400 try: 403 try:
401 self.__info.setHTML(text) 404 self._info.setHTML(text)
402 except TypeError: 405 except TypeError:
403 log.error("LiberviaWidget.setInfo: info widget has not been initialized!") 406 log.error("LiberviaWidget.setInfo: info widget has not been initialized!")
404 407
405 def isSelectable(self): 408 def isSelectable(self):
406 return self.__selectable 409 return self._selectable
407 410
408 def setSelectable(self, selectable): 411 def setSelectable(self, selectable):
409 if not self.__selectable: 412 if not self._selectable:
410 try: 413 try:
411 self.removeClickListener(self) 414 self.removeClickListener(self)
412 except ValueError: 415 except ValueError:
413 pass 416 pass
414 if self.selectable and not self in self._clickListeners: 417 if self.selectable and not self in self._clickListeners:
415 self.addClickListener(self) 418 self.addClickListener(self)
416 self.__selectable = selectable 419 self._selectable = selectable
417 420
418 def getWarningData(self): 421 def getWarningData(self):
419 """ Return exposition warning level when this widget is selected and something is sent to it 422 """ Return exposition warning level when this widget is selected and something is sent to it
420 This method should be overriden by children 423 This method should be overriden by children
421 @return: tuple (warning level type/HTML msg). Type can be one of: 424 @return: tuple (warning level type/HTML msg). Type can be one of:
423 - GROUP 426 - GROUP
424 - ONE2ONE 427 - ONE2ONE
425 - MISC 428 - MISC
426 - NONE 429 - NONE
427 """ 430 """
428 if not self.__selectable: 431 if not self._selectable:
429 log.error("getWarningLevel must not be called for an unselectable widget") 432 log.error("getWarningLevel must not be called for an unselectable widget")
430 raise Exception 433 raise Exception
431 # TODO: cleaner warning types (more general constants) 434 # TODO: cleaner warning types (more general constants)
432 return ("NONE", None) 435 return ("NONE", None)
433 436