comparison libervia.py @ 275:a763b2ac5d41

bridge + browser_side: bridge signals for games and their callbacks: - added radiocolPlayers and tarotGamePlayers to get the list of players - added roomLeft to remove the muc from the host's room list - display symbols to identify the players in a muc - factorization of ChatPanel.startGame
author souliane <souliane@mailoo.org>
date Thu, 21 Nov 2013 16:13:14 +0100
parents 886b47896f3c
children aebb96bfa8d1
comparison
equal deleted inserted replaced
274:886b47896f3c 275:a763b2ac5d41
165 self.contact_panel = ContactPanel(self) 165 self.contact_panel = ContactPanel(self)
166 self.panel = panels.MainPanel(self) 166 self.panel = panels.MainPanel(self)
167 self.discuss_panel = self.panel.discuss_panel 167 self.discuss_panel = self.panel.discuss_panel
168 self.tab_panel = self.panel.tab_panel 168 self.tab_panel = self.panel.tab_panel
169 self.tab_panel.addTabListener(self) 169 self.tab_panel.addTabListener(self)
170 self.room_list = set() #set of rooms
171 self.libervia_widgets = set() # keep track of all actives LiberviaWidgets 170 self.libervia_widgets = set() # keep track of all actives LiberviaWidgets
171 self.room_list = [] # list of rooms
172 self.mblog_cache = [] # used to keep our own blog entries in memory, to show them in new mblog panel 172 self.mblog_cache = [] # used to keep our own blog entries in memory, to show them in new mblog panel
173 self.avatars_cache = {} # keep track of jid's avatar hash (key=jid, value=file) 173 self.avatars_cache = {} # keep track of jid's avatar hash (key=jid, value=file)
174 self.current_action_ids = set() 174 self.current_action_ids = set()
175 #self.discuss_panel.addWidget(panels.EmptyPanel(self)) 175 #self.discuss_panel.addWidget(panels.EmptyPanel(self))
176 self.discuss_panel.addWidget(panels.MicroblogPanel(self, [])) 176 self.discuss_panel.addWidget(panels.MicroblogPanel(self, []))
355 self._newMessageCb(*args) 355 self._newMessageCb(*args)
356 elif name == 'presenceUpdate': 356 elif name == 'presenceUpdate':
357 self._presenceUpdateCb(*args) 357 self._presenceUpdateCb(*args)
358 elif name == 'roomJoined': 358 elif name == 'roomJoined':
359 self._roomJoinedCb(*args) 359 self._roomJoinedCb(*args)
360 elif name == 'roomLeft':
361 self._roomLeftCb(*args)
360 elif name == 'roomUserJoined': 362 elif name == 'roomUserJoined':
361 self._roomUserJoinedCb(*args) 363 self._roomUserJoinedCb(*args)
362 elif name == 'roomUserLeft': 364 elif name == 'roomUserLeft':
363 self._roomUserLeftCb(*args) 365 self._roomUserLeftCb(*args)
364 elif name == 'askConfirmation': 366 elif name == 'askConfirmation':
365 self._askConfirmation(*args) 367 self._askConfirmation(*args)
366 elif name == 'newAlert': 368 elif name == 'newAlert':
367 self._newAlert(*args) 369 self._newAlert(*args)
370 elif name == 'tarotGamePlayers':
371 self._tarotGameStartedCb(*args, waiting=True)
368 elif name == 'tarotGameStarted': 372 elif name == 'tarotGameStarted':
369 self._tarotGameStartedCb(*args) 373 self._tarotGameStartedCb(*args)
370 elif name == 'tarotGameNew' or \ 374 elif name == 'tarotGameNew' or \
371 name == 'tarotGameChooseContrat' or \ 375 name == 'tarotGameChooseContrat' or \
372 name == 'tarotGameShowCards' or \ 376 name == 'tarotGameShowCards' or \
373 name == 'tarotGameInvalidCards' or \ 377 name == 'tarotGameInvalidCards' or \
374 name == 'tarotGameCardsPlayed' or \ 378 name == 'tarotGameCardsPlayed' or \
375 name == 'tarotGameYourTurn' or \ 379 name == 'tarotGameYourTurn' or \
376 name == 'tarotGameScore': 380 name == 'tarotGameScore':
377 self._tarotGameGenericCb(name, args[0], args[1:]) 381 self._tarotGameGenericCb(name, args[0], args[1:])
382 elif name == 'radiocolPlayers':
383 self._radioColStartedCb(*args, waiting=True)
378 elif name == 'radiocolStarted': 384 elif name == 'radiocolStarted':
379 self._radioColStartedCb(*args) 385 self._radioColStartedCb(*args)
380 elif name == 'radiocolPreload': 386 elif name == 'radiocolPreload':
381 self._radioColGenericCb(name, args[0], args[1:]) 387 self._radioColGenericCb(name, args[0], args[1:])
382 elif name == 'radiocolPlay': 388 elif name == 'radiocolPlay':
575 if (not self.whoami or self.whoami.bare != _entity.bare): 581 if (not self.whoami or self.whoami.bare != _entity.bare):
576 self.contact_panel.setConnected(_entity.bare, _entity.resource, show, priority, statuses) 582 self.contact_panel.setConnected(_entity.bare, _entity.resource, show, priority, statuses)
577 583
578 def _roomJoinedCb(self, room_jid, room_nicks, user_nick): 584 def _roomJoinedCb(self, room_jid, room_nicks, user_nick):
579 _target = JID(room_jid) 585 _target = JID(room_jid)
580 self.room_list.add(_target) 586 if _target not in self.room_list:
587 self.room_list.append(_target)
581 chat_panel = panels.ChatPanel(self, _target, type_='group') 588 chat_panel = panels.ChatPanel(self, _target, type_='group')
582 chat_panel.setUserNick(user_nick) 589 chat_panel.setUserNick(user_nick)
583 if _target.node.startswith('sat_tarot_'): #XXX: it's not really beautiful, but it works :) 590 if _target.node.startswith('sat_tarot_'): #XXX: it's not really beautiful, but it works :)
584 self.addTab("Tarot", chat_panel) 591 self.addTab("Tarot", chat_panel)
585 elif _target.node.startswith('sat_radiocol_'): 592 elif _target.node.startswith('sat_radiocol_'):
587 else: 594 else:
588 self.addTab(_target.node, chat_panel) 595 self.addTab(_target.node, chat_panel)
589 chat_panel.setPresents(room_nicks) 596 chat_panel.setPresents(room_nicks)
590 chat_panel.historyPrint() 597 chat_panel.historyPrint()
591 598
599 def _roomLeftCb(self, room_jid, room_nicks, user_nick):
600 # FIXME: room_list contains JID instances so why MUST we do
601 # 'remove(room_jid)' and not 'remove(JID(room_jid))' ????!!
602 # This looks like a pyjamas bug --> check/report
603 try:
604 self.room_list.remove(room_jid)
605 except KeyError:
606 pass
607
592 def _roomUserJoinedCb(self, room_jid_s, user_nick, user_data): 608 def _roomUserJoinedCb(self, room_jid_s, user_nick, user_data):
593 for lib_wid in self.libervia_widgets: 609 for lib_wid in self.libervia_widgets:
594 if isinstance(lib_wid, panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s: 610 if isinstance(lib_wid, panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s:
595 lib_wid.userJoined(user_nick, user_data) 611 lib_wid.userJoined(user_nick, user_data)
596 612
597 def _roomUserLeftCb(self, room_jid_s, user_nick, user_data): 613 def _roomUserLeftCb(self, room_jid_s, user_nick, user_data):
598 for lib_wid in self.libervia_widgets: 614 for lib_wid in self.libervia_widgets:
599 if isinstance(lib_wid, panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s: 615 if isinstance(lib_wid, panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s:
600 lib_wid.userLeft(user_nick, user_data) 616 lib_wid.userLeft(user_nick, user_data)
601 617
602 def _tarotGameStartedCb(self, room_jid_s, referee, players): 618 def _tarotGameStartedCb(self, room_jid_s, referee, players, waiting=False):
603 print ("Tarot Game Started \o/")
604 for lib_wid in self.libervia_widgets: 619 for lib_wid in self.libervia_widgets:
605 if isinstance(lib_wid, panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s: 620 if isinstance(lib_wid, panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s:
606 lib_wid.startGame("Tarot", referee, players) 621 lib_wid.startGame("Tarot", referee, players, waiting)
607 622
608 def _tarotGameGenericCb(self, event_name, room_jid_s, args): 623 def _tarotGameGenericCb(self, event_name, room_jid_s, args):
609 for lib_wid in self.libervia_widgets: 624 for lib_wid in self.libervia_widgets:
610 if isinstance(lib_wid, panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s: 625 if isinstance(lib_wid, panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s:
611 getattr(lib_wid.getGame("Tarot"), event_name)(*args) 626 getattr(lib_wid.getGame("Tarot"), event_name)(*args)
612 627
613 def _radioColStartedCb(self, room_jid_s, referee): 628 def _radioColStartedCb(self, room_jid_s, referee, players, waiting=False):
614 for lib_wid in self.libervia_widgets: 629 for lib_wid in self.libervia_widgets:
615 if isinstance(lib_wid, panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s: 630 if isinstance(lib_wid, panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s:
616 lib_wid.startGame("RadioCol", referee) 631 lib_wid.startGame("RadioCol", referee, players, waiting)
617 632
618 def _radioColGenericCb(self, event_name, room_jid_s, args): 633 def _radioColGenericCb(self, event_name, room_jid_s, args):
619 for lib_wid in self.libervia_widgets: 634 for lib_wid in self.libervia_widgets:
620 if isinstance(lib_wid, panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s: 635 if isinstance(lib_wid, panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s:
621 getattr(lib_wid.getGame("RadioCol"), event_name)(*args) 636 getattr(lib_wid.getGame("RadioCol"), event_name)(*args)