comparison src/browser/sat_browser/chat.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 e489218886d7
children a90cc8fc9605
comparison
equal deleted inserted replaced
675:941e53b3af5c 676:849ffb24d5bf
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 from sat.core.log import getLogger 20 from sat.core.log import getLogger
21 log = getLogger(__name__) 21 log = getLogger(__name__)
22 22
23 from sat_frontends.tools.games import SYMBOLS 23 # from sat_frontends.tools.games import SYMBOLS
24 from sat_frontends.tools import strings 24 from sat_frontends.tools import strings
25 from sat_frontends.tools import jid 25 from sat_frontends.tools import jid
26 from sat_frontends.quick_frontend import quick_widgets, quick_games 26 from sat_frontends.quick_frontend import quick_widgets, quick_games, quick_menus
27 from sat_frontends.quick_frontend.quick_chat import QuickChat 27 from sat_frontends.quick_frontend.quick_chat import QuickChat
28 from sat.core.i18n import _ 28 from sat.core.i18n import _
29 29
30 from pyjamas.ui.AbsolutePanel import AbsolutePanel 30 from pyjamas.ui.AbsolutePanel import AbsolutePanel
31 from pyjamas.ui.VerticalPanel import VerticalPanel 31 from pyjamas.ui.VerticalPanel import VerticalPanel
132 # FIXME: for unknow reason, pyjamas doesn't use the method inherited from QuickWidget 132 # FIXME: for unknow reason, pyjamas doesn't use the method inherited from QuickWidget
133 # FIXME: must remove this when either pyjamas is fixed, or we use an alternative 133 # FIXME: must remove this when either pyjamas is fixed, or we use an alternative
134 assert len(self.profiles) == 1 and not self.PROFILES_MULTIPLE and not self.PROFILES_ALLOW_NONE 134 assert len(self.profiles) == 1 and not self.PROFILES_MULTIPLE and not self.PROFILES_ALLOW_NONE
135 return list(self.profiles)[0] 135 return list(self.profiles)[0]
136 136
137 @property
138 def plugin_menu_context(self):
139 return (C.MENU_ROOM,) if self.type == C.CHAT_GROUP else (C.MENU_SINGLE,)
140
137 # @classmethod 141 # @classmethod
138 # def createPanel(cls, host, item, type_=C.CHAT_ONE2ONE): 142 # def createPanel(cls, host, item, type_=C.CHAT_ONE2ONE):
139 # assert(item) 143 # assert(item)
140 # _contact = item if isinstance(item, jid.JID) else jid.JID(item) 144 # _contact = item if isinstance(item, jid.JID) else jid.JID(item)
141 # host.contact_panel.setContactMessageWaiting(_contact.bare, False) 145 # host.contact_panel.setContactMessageWaiting(_contact.bare, False)
164 def onKeyDown(self, sender, keycode, modifiers): 168 def onKeyDown(self, sender, keycode, modifiers):
165 if keycode == KEY_ENTER: 169 if keycode == KEY_ENTER:
166 self.host.showWarning(None, None) 170 self.host.showWarning(None, None)
167 else: 171 else:
168 self.host.showWarning(*self.getWarningData()) 172 self.host.showWarning(*self.getWarningData())
169
170 def addMenus(self, menu_bar):
171 """Add cached menus to the header.
172
173 @param menu_bar (GenericMenuBar): menu bar of the widget's header
174 """
175 if self.type == C.CHAT_GROUP:
176 menu_bar.addCachedMenus(C.MENU_ROOM, {'room_jid': self.target.bare})
177 elif self.type == C.CHAT_ONE2ONE:
178 menu_bar.addCachedMenus(C.MENU_SINGLE, {'jid': self.target})
179 173
180 def getWarningData(self): 174 def getWarningData(self):
181 if self.type not in [C.CHAT_ONE2ONE, C.CHAT_GROUP]: 175 if self.type not in [C.CHAT_ONE2ONE, C.CHAT_GROUP]:
182 raise Exception("Unmanaged type !") 176 raise Exception("Unmanaged type !")
183 if self.type == C.CHAT_ONE2ONE: 177 if self.type == C.CHAT_ONE2ONE:
347 341
348 quick_widgets.register(QuickChat, Chat) 342 quick_widgets.register(QuickChat, Chat)
349 quick_widgets.register(quick_games.Tarot, game_tarot.TarotPanel) 343 quick_widgets.register(quick_games.Tarot, game_tarot.TarotPanel)
350 quick_widgets.register(quick_games.Radiocol, game_radiocol.RadioColPanel) 344 quick_widgets.register(quick_games.Radiocol, game_radiocol.RadioColPanel)
351 libervia_widget.LiberviaWidget.addDropKey("CONTACT", lambda host, item: host.displayWidget(Chat, jid.JID(item), dropped=True)) 345 libervia_widget.LiberviaWidget.addDropKey("CONTACT", lambda host, item: host.displayWidget(Chat, jid.JID(item), dropped=True))
346 quick_menus.QuickMenusManager.addDataCollector(C.MENU_ROOM, {'room_jid': 'target'})
347 quick_menus.QuickMenusManager.addDataCollector(C.MENU_SINGLE, {'jid': 'target'})