Mercurial > libervia-web
comparison src/browser/sat_browser/contact_widget.py @ 676:849ffb24d5bf frontends_multi_profiles
browser side: menus refactorisation:
- use of the new quick_frontends.quick_menus module, resulting in a big code simplification in Libervia
- menu are added in there respective modules: main menus are done directely in libervia_main, while tarot and radiocol menus are done in game_tarot and game_radiocol
- launchAction has the same signature as in QuickApp
- base_menu: there are now 2 classes to launch an action: MenuCmd which manage quick_menus classes, and SimpleCmd to launch a generic callback
- base_menu: MenuNode has been removed as logic is now in quick_menus
- base_menu: GenericMenuBar.update method can be called to fully (re)build the menus
- base_widget: removed WidgetSubMenuBar which is no more useful (GenericMenuBar do the same thing)
- plugin_menu_context is used in LiberviaWidget and other classes with menus to indicate which menu types must be used
- otr menus hooks are temporarily removed, will be fixed soon
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 17 Mar 2015 20:42:02 +0100 |
parents | 2201ff543a05 |
children | e876f493dccc |
comparison
equal
deleted
inserted
replaced
675:941e53b3af5c | 676:849ffb24d5bf |
---|---|
20 import pyjd # this is dummy in pyjs | 20 import pyjd # this is dummy in pyjs |
21 from sat.core.log import getLogger | 21 from sat.core.log import getLogger |
22 log = getLogger(__name__) | 22 log = getLogger(__name__) |
23 | 23 |
24 from sat.core import exceptions | 24 from sat.core import exceptions |
25 from sat_frontends.quick_frontend import quick_menus | |
25 from pyjamas.ui.VerticalPanel import VerticalPanel | 26 from pyjamas.ui.VerticalPanel import VerticalPanel |
26 from pyjamas.ui.HTML import HTML | 27 from pyjamas.ui.HTML import HTML |
27 from pyjamas.ui.Image import Image | 28 from pyjamas.ui.Image import Image |
28 from pyjamas.ui.ClickListener import ClickHandler | 29 from pyjamas.ui.ClickListener import ClickHandler |
29 from constants import Const as C | 30 from constants import Const as C |
112 self.items[0].setHTML('<img src="%s" />' % url) | 113 self.items[0].setHTML('<img src="%s" />' % url) |
113 | 114 |
114 | 115 |
115 class ContactBox(VerticalPanel, ClickHandler, libervia_widget.DragLabel): | 116 class ContactBox(VerticalPanel, ClickHandler, libervia_widget.DragLabel): |
116 | 117 |
117 def __init__(self, host, jid_, style_name=None, menu_types=None, display=C.CONTACT_DEFAULT_DISPLAY): | 118 def __init__(self, host, jid_, style_name=None, display=C.CONTACT_DEFAULT_DISPLAY, plugin_menu_context=None): |
118 """ | 119 """ |
119 @param host (SatWebFrontend): host instance | 120 @param host (SatWebFrontend): host instance |
120 @param jid_ (jid.JID): contact JID | 121 @param jid_ (jid.JID): contact JID |
121 @param style_name (unicode): CSS style name | 122 @param style_name (unicode): CSS style name |
122 @param menu_types (tuple): define the menu types that fit this | |
123 contact panel, with values from the menus type constants. | |
124 @param contacts_display (tuple): prioritize the display methods of the | 123 @param contacts_display (tuple): prioritize the display methods of the |
125 contact's label with values in ("jid", "nick", "bare", "resource"). | 124 contact's label with values in ("jid", "nick", "bare", "resource"). |
125 @param plugin_menu_context (iterable): contexts of menus to have (list of C.MENU_* constant) | |
126 | 126 |
127 """ | 127 """ |
128 self.plugin_menu_context = [] if plugin_menu_context is None else plugin_menu_context | |
128 VerticalPanel.__init__(self, StyleName=style_name or 'contactBox', VerticalAlignment='middle') | 129 VerticalPanel.__init__(self, StyleName=style_name or 'contactBox', VerticalAlignment='middle') |
129 ClickHandler.__init__(self) | 130 ClickHandler.__init__(self) |
130 libervia_widget.DragLabel.__init__(self, jid_, "CONTACT", host) | 131 libervia_widget.DragLabel.__init__(self, jid_, "CONTACT", host) |
131 self.jid = jid_ | 132 self.jid = jid_ |
132 self.label = ContactLabel(host, self.jid, display=display) | 133 self.label = ContactLabel(host, self.jid, display=display) |
133 self.menu_types = menu_types | 134 self.avatar = ContactMenuBar(self, host) if plugin_menu_context else Image() |
134 self.avatar = ContactMenuBar(self, host) if menu_types else Image() | |
135 try: # FIXME: dirty hack to force using an Image when the menu is actually empty | 135 try: # FIXME: dirty hack to force using an Image when the menu is actually empty |
136 self.avatar.items[0] | 136 self.avatar.items[0] |
137 except IndexError: | 137 except IndexError: |
138 self.avatar = Image() | 138 self.avatar = Image() |
139 self.updateAvatar(host.getAvatarURL(self.jid.bare)) | 139 self.updateAvatar(host.getAvatarURL(self.jid.bare)) |
140 self.add(self.avatar) | 140 self.add(self.avatar) |
141 self.add(self.label) | 141 self.add(self.label) |
142 self.addClickListener(self) | 142 self.addClickListener(self) |
143 | |
144 def addMenus(self, menu_bar): | |
145 for menu_type in self.menu_types: | |
146 menu_bar.addCachedMenus(menu_type, {'jid': unicode(self.jid.bare)}) | |
147 | 143 |
148 def setAlert(self, alert): | 144 def setAlert(self, alert): |
149 """Show a visual indicator | 145 """Show a visual indicator |
150 | 146 |
151 @param alert: True if alert indicator show be shown""" | 147 @param alert: True if alert indicator show be shown""" |
170 self.parent.onClick(self.jid.bare) | 166 self.parent.onClick(self.jid.bare) |
171 except (AttributeError, TypeError): | 167 except (AttributeError, TypeError): |
172 pass | 168 pass |
173 else: | 169 else: |
174 self.setAlert(False) | 170 self.setAlert(False) |
171 | |
172 quick_menus.QuickMenusManager.addDataCollector(C.MENU_JID_CONTEXT, lambda caller, dummy: {'jid': unicode(caller.jid.bare)}) |