Mercurial > libervia-web
diff src/browser/sat_browser/contact_widget.py @ 671:2201ff543a05 frontends_multi_profiles
browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
author | souliane <souliane@mailoo.org> |
---|---|
date | Mon, 09 Mar 2015 16:30:06 +0100 |
parents | 267761bf7f08 |
children | 849ffb24d5bf |
line wrap: on
line diff
--- a/src/browser/sat_browser/contact_widget.py Mon Mar 09 16:27:20 2015 +0100 +++ b/src/browser/sat_browser/contact_widget.py Mon Mar 09 16:30:06 2015 +0100 @@ -38,6 +38,13 @@ """Display a contact in HTML, selecting best display (jid/nick/etc)""" def __init__(self, host, jid_, display=C.CONTACT_DEFAULT_DISPLAY): + """ + + @param host (SatWebFrontend): host instance + @param jid_ (jid.JID): contact JID + @param display (tuple): prioritize the display methods of the contact's + label with values in ("jid", "nick", "bare", "resource"). + """ # TODO: add a listener for nick changes HTML.__init__(self) self.host = host @@ -107,25 +114,36 @@ class ContactBox(VerticalPanel, ClickHandler, libervia_widget.DragLabel): - def __init__(self, parent, jid_, style_name=None, display=C.CONTACT_DEFAULT_DISPLAY): + def __init__(self, host, jid_, style_name=None, menu_types=None, display=C.CONTACT_DEFAULT_DISPLAY): """ - @param parent (ContactPanel): ContactPanel hosting this box + @param host (SatWebFrontend): host instance @param jid_ (jid.JID): contact JID + @param style_name (unicode): CSS style name + @param menu_types (tuple): define the menu types that fit this + contact panel, with values from the menus type constants. + @param contacts_display (tuple): prioritize the display methods of the + contact's label with values in ("jid", "nick", "bare", "resource"). + """ VerticalPanel.__init__(self, StyleName=style_name or 'contactBox', VerticalAlignment='middle') ClickHandler.__init__(self) - libervia_widget.DragLabel.__init__(self, jid_, "CONTACT", parent.host) + libervia_widget.DragLabel.__init__(self, jid_, "CONTACT", host) self.jid = jid_ - self.label = ContactLabel(parent.host, self.jid, display=display) - self.avatar = ContactMenuBar(self, parent.host) if parent.handle_menu else Image() - self.updateAvatar(parent.host.getAvatarURL(self.jid.bare)) + self.label = ContactLabel(host, self.jid, display=display) + self.menu_types = menu_types + self.avatar = ContactMenuBar(self, host) if menu_types else Image() + try: # FIXME: dirty hack to force using an Image when the menu is actually empty + self.avatar.items[0] + except IndexError: + self.avatar = Image() + self.updateAvatar(host.getAvatarURL(self.jid.bare)) self.add(self.avatar) self.add(self.label) self.addClickListener(self) def addMenus(self, menu_bar): - menu_bar.addCachedMenus(C.MENU_ROSTER_JID_CONTEXT, {'jid': unicode(self.jid.bare)}) - menu_bar.addCachedMenus(C.MENU_JID_CONTEXT, {'jid': unicode(self.jid.bare)}) + for menu_type in self.menu_types: + menu_bar.addCachedMenus(menu_type, {'jid': unicode(self.jid.bare)}) def setAlert(self, alert): """Show a visual indicator @@ -150,7 +168,7 @@ def onClick(self, sender): try: self.parent.onClick(self.jid.bare) - except AttributeError: + except (AttributeError, TypeError): pass else: self.setAlert(False)