Mercurial > libervia-web
diff 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 |
line wrap: on
line diff
--- a/libervia.py Thu Nov 21 16:05:14 2013 +0100 +++ b/libervia.py Thu Nov 21 16:13:14 2013 +0100 @@ -167,8 +167,8 @@ self.discuss_panel = self.panel.discuss_panel self.tab_panel = self.panel.tab_panel self.tab_panel.addTabListener(self) - self.room_list = set() #set of rooms self.libervia_widgets = set() # keep track of all actives LiberviaWidgets + self.room_list = [] # list of rooms self.mblog_cache = [] # used to keep our own blog entries in memory, to show them in new mblog panel self.avatars_cache = {} # keep track of jid's avatar hash (key=jid, value=file) self.current_action_ids = set() @@ -357,6 +357,8 @@ self._presenceUpdateCb(*args) elif name == 'roomJoined': self._roomJoinedCb(*args) + elif name == 'roomLeft': + self._roomLeftCb(*args) elif name == 'roomUserJoined': self._roomUserJoinedCb(*args) elif name == 'roomUserLeft': @@ -365,6 +367,8 @@ self._askConfirmation(*args) elif name == 'newAlert': self._newAlert(*args) + elif name == 'tarotGamePlayers': + self._tarotGameStartedCb(*args, waiting=True) elif name == 'tarotGameStarted': self._tarotGameStartedCb(*args) elif name == 'tarotGameNew' or \ @@ -375,6 +379,8 @@ name == 'tarotGameYourTurn' or \ name == 'tarotGameScore': self._tarotGameGenericCb(name, args[0], args[1:]) + elif name == 'radiocolPlayers': + self._radioColStartedCb(*args, waiting=True) elif name == 'radiocolStarted': self._radioColStartedCb(*args) elif name == 'radiocolPreload': @@ -577,7 +583,8 @@ def _roomJoinedCb(self, room_jid, room_nicks, user_nick): _target = JID(room_jid) - self.room_list.add(_target) + if _target not in self.room_list: + self.room_list.append(_target) chat_panel = panels.ChatPanel(self, _target, type_='group') chat_panel.setUserNick(user_nick) if _target.node.startswith('sat_tarot_'): #XXX: it's not really beautiful, but it works :) @@ -589,6 +596,15 @@ chat_panel.setPresents(room_nicks) chat_panel.historyPrint() + def _roomLeftCb(self, room_jid, room_nicks, user_nick): + # FIXME: room_list contains JID instances so why MUST we do + # 'remove(room_jid)' and not 'remove(JID(room_jid))' ????!! + # This looks like a pyjamas bug --> check/report + try: + self.room_list.remove(room_jid) + except KeyError: + pass + def _roomUserJoinedCb(self, room_jid_s, user_nick, user_data): for lib_wid in self.libervia_widgets: if isinstance(lib_wid, panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s: @@ -599,21 +615,20 @@ if isinstance(lib_wid, panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s: lib_wid.userLeft(user_nick, user_data) - def _tarotGameStartedCb(self, room_jid_s, referee, players): - print ("Tarot Game Started \o/") + def _tarotGameStartedCb(self, room_jid_s, referee, players, waiting=False): for lib_wid in self.libervia_widgets: if isinstance(lib_wid, panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s: - lib_wid.startGame("Tarot", referee, players) + lib_wid.startGame("Tarot", referee, players, waiting) def _tarotGameGenericCb(self, event_name, room_jid_s, args): for lib_wid in self.libervia_widgets: if isinstance(lib_wid, panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s: getattr(lib_wid.getGame("Tarot"), event_name)(*args) - def _radioColStartedCb(self, room_jid_s, referee): + def _radioColStartedCb(self, room_jid_s, referee, players, waiting=False): for lib_wid in self.libervia_widgets: if isinstance(lib_wid, panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid_s: - lib_wid.startGame("RadioCol", referee) + lib_wid.startGame("RadioCol", referee, players, waiting) def _radioColGenericCb(self, event_name, room_jid_s, args): for lib_wid in self.libervia_widgets: