comparison frontends/src/primitivus/chat.py @ 1360:8ea8fa13c351 frontends_multi_profiles

frontends (quick_frontend, primitivus): fixes room games: - add quick_frontend.quick_games for registering the signals and registering the UI classes - rename the signals handlers to fit the convention (e.g.: tarotGameScoreHandler) - rename card_game to game_tarot, quick_card_game to quick_game_tarot, CardGame to TarotGame
author souliane <souliane@mailoo.org>
date Wed, 11 Mar 2015 12:43:48 +0100
parents faa1129559b8
children d3e9848b9574
comparison
equal deleted inserted replaced
1359:83127a4c89ce 1360:8ea8fa13c351
23 import urwid 23 import urwid
24 from urwid_satext import sat_widgets 24 from urwid_satext import sat_widgets
25 from urwid_satext.files_management import FileDialog 25 from urwid_satext.files_management import FileDialog
26 from sat_frontends.quick_frontend import quick_widgets 26 from sat_frontends.quick_frontend import quick_widgets
27 from sat_frontends.quick_frontend.quick_chat import QuickChat 27 from sat_frontends.quick_frontend.quick_chat import QuickChat
28 from sat_frontends.primitivus.card_game import CardGame 28 from sat_frontends.quick_frontend import quick_games
29 from sat_frontends.primitivus import game_tarot
29 from sat_frontends.primitivus.constants import Const as C 30 from sat_frontends.primitivus.constants import Const as C
30 from sat_frontends.primitivus.keys import action_key_map as a_key 31 from sat_frontends.primitivus.keys import action_key_map as a_key
31 from sat_frontends.primitivus.widget import PrimitivusWidget 32 from sat_frontends.primitivus.widget import PrimitivusWidget
32 import time 33 import time
33 from sat_frontends.tools import jid 34 from sat_frontends.tools import jid
195 for widget, options in self.chat_colums.contents: 196 for widget, options in self.chat_colums.contents:
196 if widget is self.present_panel: 197 if widget is self.present_panel:
197 self.chat_colums.contents.remove((widget, options)) 198 self.chat_colums.contents.remove((widget, options))
198 break 199 break
199 200
200 def _appendGamePanel(self, widget): 201 def addGamePanel(self, widget):
202 """Insert a game panel to this Chat dialog.
203
204 @param widget (Widget): the game panel
205 """
201 assert (len(self.pile.contents) == 1) 206 assert (len(self.pile.contents) == 1)
202 self.pile.contents.insert(0,(widget,('weight', 1))) 207 self.pile.contents.insert(0, (widget, ('weight', 1)))
203 self.pile.contents.insert(1,(urwid.Filler(urwid.Divider('-'),('fixed', 1)))) 208 self.pile.contents.insert(1, (urwid.Filler(urwid.Divider('-'), ('fixed', 1))))
204 self.host.redraw() 209 self.host.redraw()
205 210
206 def _removeGamePanel(self): 211 def removeGamePanel(self, widget):
212 """Remove the game panel from this Chat dialog.
213
214 @param widget (Widget): the game panel
215 """
207 assert (len(self.pile.contents) == 3) 216 assert (len(self.pile.contents) == 3)
208 del self.pile.contents[0] 217 del self.pile.contents[0]
209 self.host.redraw() 218 self.host.redraw()
210 219
211 def setSubject(self, subject, wrap='space'): 220 def setSubject(self, subject, wrap='space'):
330 if not self.host.x_notify.hasFocus(): 339 if not self.host.x_notify.hasFocus():
331 if self.type == C.CHAT_ONE2ONE: 340 if self.type == C.CHAT_ONE2ONE:
332 self.host.x_notify.sendNotification(_("Primitivus: %s is talking to you") % from_jid) 341 self.host.x_notify.sendNotification(_("Primitivus: %s is talking to you") % from_jid)
333 elif self.getUserNick().lower() in msg.lower(): 342 elif self.getUserNick().lower() in msg.lower():
334 self.host.x_notify.sendNotification(_("Primitivus: %(user)s mentioned you in room '%(room)s'") % {'user': from_jid, 'room': self.target}) 343 self.host.x_notify.sendNotification(_("Primitivus: %(user)s mentioned you in room '%(room)s'") % {'user': from_jid, 'room': self.target})
335
336 def startGame(self, game_type, referee, players):
337 """Configure the chat window to start a game"""
338 if game_type=="Tarot":
339 self.tarot_wid = CardGame(self, referee, players, self.nick)
340 self._appendGamePanel(self.tarot_wid)
341
342 def getGame(self, game_type):
343 """Return class managing the game type"""
344 #TODO: check that the game is launched, and manage errors
345 if game_type=="Tarot":
346 return self.tarot_wid
347 344
348 #MENU EVENTS# 345 #MENU EVENTS#
349 def onTarotRequest(self, menu): 346 def onTarotRequest(self, menu):
350 # TODO: move this to plugin_misc_tarot with dynamic menu 347 # TODO: move this to plugin_misc_tarot with dynamic menu
351 if len(self.occupants) != 4: 348 if len(self.occupants) != 4:
377 self.host.addProgress(progress_id,filepath) 374 self.host.addProgress(progress_id,filepath)
378 self.host.showDialog(_(u"You file request has been sent, we are waiting for your contact answer"), title=_("File request sent")) 375 self.host.showDialog(_(u"You file request has been sent, we are waiting for your contact answer"), title=_("File request sent"))
379 376
380 377
381 quick_widgets.register(QuickChat, Chat) 378 quick_widgets.register(QuickChat, Chat)
379 quick_widgets.register(quick_games.Tarot, game_tarot.TarotGame)