# HG changeset patch # User souliane # Date 1389975604 -3600 # Node ID 44491e963eee08038736c80806c815263bfb70b5 # Parent 31c105017d6bcd9ab9ee6c611634ea643256ea45 browser_side: muc user symbols (used for showing who is playing) can also be removed diff -r 31c105017d6b -r 44491e963eee browser_side/base_panels.py --- a/browser_side/base_panels.py Thu Jan 16 11:51:52 2014 +0100 +++ b/browser_side/base_panels.py Fri Jan 17 17:20:04 2014 +0100 @@ -65,11 +65,20 @@ def __str__(self): return self.nick - def addSpecial(self, special=""): + def addSpecial(self, special): + """@param special: unicode""" if special not in self.special: self.special += special self._refresh() + def removeSpecials(self, special): + """@param special: unicode or list""" + if not isinstance(special, list): + special = [special] + for symbol in special: + self.special = self.special.replace(symbol, "") + self._refresh() + def _refresh(self): special = "" if len(self.special) == 0 else " %s" % self.special self.setHTML("
%s%s
" % (html_sanitize(self.nick), special)) @@ -98,15 +107,24 @@ self.occupants_list.clear() AbsolutePanel.clear(self) - def addSpecials(self, occupants=[], html=""): + def updateSpecials(self, occupants=[], html=""): + """Set the specified html "symbol" to the listed occupants, + and eventually remove it from the others (if they got it). + This is used for example to visualize who is playing a game. + @param occupants: list of the occupants that need the symbol + @param html: unicode symbol (actually one character or more) + or a list to assign different symbols of the same family. + """ index = 0 special = html - for occupant in occupants: - if occupant in self.occupants_list.keys(): + for occupant in self.occupants_list.keys(): + if occupant in occupants: if isinstance(html, list): special = html[index] index = (index + 1) % len(html) self.occupants_list[occupant].addSpecial(special) + else: + self.occupants_list[occupant].removeSpecials(html) class PopupMenuPanel(PopupPanel): diff -r 31c105017d6b -r 44491e963eee browser_side/panels.py --- a/browser_side/panels.py Thu Jan 16 11:51:52 2014 +0100 +++ b/browser_side/panels.py Fri Jan 17 17:20:04 2014 +0100 @@ -1169,7 +1169,7 @@ if game_type not in classes.keys(): return # unknown game attr = game_type.lower() - self.occupants_list.addSpecials(players, SYMBOLS[attr]) + self.occupants_list.updateSpecials(players, SYMBOLS[attr]) if waiting or not self.nick in players: return # waiting for player or not playing attr = "%s_panel" % attr