comparison src/browser/sat_browser/chat.py @ 672:b39a9eddfe56 frontends_multi_profiles

browser_side: fixes room games: - use quick_frontend.quick_games - rename the signals handlers to fit the convention (e.g.: tarotGameScoreHandler) - rename card_game to game_tarot, radiocol to game_radiocol, CardGame to TarotPanel
author souliane <souliane@mailoo.org>
date Wed, 11 Mar 2015 12:50:19 +0100
parents 2201ff543a05
children e489218886d7
comparison
equal deleted inserted replaced
671:2201ff543a05 672:b39a9eddfe56
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 26 from sat_frontends.quick_frontend import quick_widgets, quick_games
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
41 import html_tools 41 import html_tools
42 import libervia_widget 42 import libervia_widget
43 import base_panel 43 import base_panel
44 import contact_panel 44 import contact_panel
45 import editor_widget 45 import editor_widget
46 import card_game
47 import radiocol
48 import contact_list 46 import contact_list
49 from constants import Const as C 47 from constants import Const as C
50 import plugin_xep_0085 48 import plugin_xep_0085
49 import game_tarot
50 import game_radiocol
51 51
52 52
53 unicode = str # FIXME: pyjamas workaround 53 unicode = str # FIXME: pyjamas workaround
54 54
55 55
279 # None is returned, the message is managed 279 # None is returned, the message is managed
280 return 280 return
281 self.content.add(ChatText(nick, mymess, msg, extra)) 281 self.content.add(ChatText(nick, mymess, msg, extra))
282 self.content_scroll.scrollToBottom() 282 self.content_scroll.scrollToBottom()
283 283
284 def startGame(self, game_type, waiting, referee, players, *args):
285 """Configure the chat window to start a game"""
286 classes = {"Tarot": card_game.CardPanel, "RadioCol": radiocol.RadioColPanel}
287 if game_type not in classes.keys():
288 return # unknown game
289 attr = game_type.lower()
290 # self.occupants_panel.updateSpecials(players, SYMBOLS[attr]) # FIXME
291 if waiting or not self.nick in players:
292 return # waiting for player or not playing
293 attr = "%s_panel" % attr
294 if hasattr(self, attr):
295 return
296 log.info("%s Game Started \o/" % game_type)
297 panel = classes[game_type](self, referee, self.nick, players, *args)
298 setattr(self, attr, panel)
299 self.vpanel.insert(panel, 0)
300 self.vpanel.setCellHeight(panel, panel.getHeight())
301
302 def getGame(self, game_type):
303 """Return class managing the game type"""
304 # TODO: check that the game is launched, and manage errors
305 if game_type == "Tarot":
306 return self.tarot_panel
307 elif game_type == "RadioCol":
308 return self.radiocol_panel
309
310 def setState(self, state, nick=None): 284 def setState(self, state, nick=None):
311 """Set the chat state (XEP-0085) of the contact. Leave nick to None 285 """Set the chat state (XEP-0085) of the contact. Leave nick to None
312 to set the state for a one2one conversation, or give a nickname or 286 to set the state for a one2one conversation, or give a nickname or
313 C.ALL_OCCUPANTS to set the state of a participant within a MUC. 287 C.ALL_OCCUPANTS to set the state of a participant within a MUC.
314 @param state: the new chat state 288 @param state: the new chat state
349 323
350 def updateChatState(self, from_jid, state): 324 def updateChatState(self, from_jid, state):
351 #TODO 325 #TODO
352 pass 326 pass
353 327
328 def addGamePanel(self, widget):
329 """Insert a game panel to this Chat dialog.
330
331 @param widget (Widget): the game panel
332 """
333 self.vpanel.insert(widget, 0)
334 self.vpanel.setCellHeight(widget, widget.getHeight())
335
336 def removeGamePanel(self, widget):
337 """Remove the game panel from this Chat dialog.
338
339 @param widget (Widget): the game panel
340 """
341 self.vpanel.remove(widget)
342
354 343
355 quick_widgets.register(QuickChat, Chat) 344 quick_widgets.register(QuickChat, Chat)
345 quick_widgets.register(quick_games.Tarot, game_tarot.TarotPanel)
346 quick_widgets.register(quick_games.Radiocol, game_radiocol.RadioColPanel)
356 libervia_widget.LiberviaWidget.addDropKey("CONTACT", lambda host, item: host.displayWidget(Chat, jid.JID(item), dropped=True)) 347 libervia_widget.LiberviaWidget.addDropKey("CONTACT", lambda host, item: host.displayWidget(Chat, jid.JID(item), dropped=True))