changeset 342:44491e963eee

browser_side: muc user symbols (used for showing who is playing) can also be removed
author souliane <souliane@mailoo.org>
date Fri, 17 Jan 2014 17:20:04 +0100
parents 31c105017d6b
children b66028d21a1c
files browser_side/base_panels.py browser_side/panels.py
diffstat 2 files changed, 23 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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("<div class='occupant'>%s%s</div>" % (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):
--- 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