Mercurial > libervia-web
comparison browser_side/base_panels.py @ 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 | ce5b33f499c5 |
children | 82f9e92379b0 |
comparison
equal
deleted
inserted
replaced
341:31c105017d6b | 342:44491e963eee |
---|---|
63 self._refresh() | 63 self._refresh() |
64 | 64 |
65 def __str__(self): | 65 def __str__(self): |
66 return self.nick | 66 return self.nick |
67 | 67 |
68 def addSpecial(self, special=""): | 68 def addSpecial(self, special): |
69 """@param special: unicode""" | |
69 if special not in self.special: | 70 if special not in self.special: |
70 self.special += special | 71 self.special += special |
72 self._refresh() | |
73 | |
74 def removeSpecials(self, special): | |
75 """@param special: unicode or list""" | |
76 if not isinstance(special, list): | |
77 special = [special] | |
78 for symbol in special: | |
79 self.special = self.special.replace(symbol, "") | |
71 self._refresh() | 80 self._refresh() |
72 | 81 |
73 def _refresh(self): | 82 def _refresh(self): |
74 special = "" if len(self.special) == 0 else " %s" % self.special | 83 special = "" if len(self.special) == 0 else " %s" % self.special |
75 self.setHTML("<div class='occupant'>%s%s</div>" % (html_sanitize(self.nick), special)) | 84 self.setHTML("<div class='occupant'>%s%s</div>" % (html_sanitize(self.nick), special)) |
96 | 105 |
97 def clear(self): | 106 def clear(self): |
98 self.occupants_list.clear() | 107 self.occupants_list.clear() |
99 AbsolutePanel.clear(self) | 108 AbsolutePanel.clear(self) |
100 | 109 |
101 def addSpecials(self, occupants=[], html=""): | 110 def updateSpecials(self, occupants=[], html=""): |
111 """Set the specified html "symbol" to the listed occupants, | |
112 and eventually remove it from the others (if they got it). | |
113 This is used for example to visualize who is playing a game. | |
114 @param occupants: list of the occupants that need the symbol | |
115 @param html: unicode symbol (actually one character or more) | |
116 or a list to assign different symbols of the same family. | |
117 """ | |
102 index = 0 | 118 index = 0 |
103 special = html | 119 special = html |
104 for occupant in occupants: | 120 for occupant in self.occupants_list.keys(): |
105 if occupant in self.occupants_list.keys(): | 121 if occupant in occupants: |
106 if isinstance(html, list): | 122 if isinstance(html, list): |
107 special = html[index] | 123 special = html[index] |
108 index = (index + 1) % len(html) | 124 index = (index + 1) % len(html) |
109 self.occupants_list[occupant].addSpecial(special) | 125 self.occupants_list[occupant].addSpecial(special) |
126 else: | |
127 self.occupants_list[occupant].removeSpecials(html) | |
110 | 128 |
111 | 129 |
112 class PopupMenuPanel(PopupPanel): | 130 class PopupMenuPanel(PopupPanel): |
113 """This implementation of a popup menu (context menu) allow you to assign | 131 """This implementation of a popup menu (context menu) allow you to assign |
114 two special methods which are common to all the items, in order to hide | 132 two special methods which are common to all the items, in order to hide |