comparison frontends/src/primitivus/chat.py @ 2007:19b9d3f8a6c7

plugin XEP-0085, quick_frontends, primitivus: chat states are working again
author Goffi <goffi@goffi.org>
date Sun, 17 Jul 2016 16:47:33 +0200
parents 981e2abbb56c
children 8a749ec21c50
comparison
equal deleted inserted replaced
2006:0ddf3edf643a 2007:19b9d3f8a6c7
150 150
151 def __lt__(self, other): 151 def __lt__(self, other):
152 return self.occupant_data.nick.lower() < other.occupant_data.nick.lower() 152 return self.occupant_data.nick.lower() < other.occupant_data.nick.lower()
153 153
154 @property 154 @property
155 def markup(self):
156 return self._generateMarkup()
157
158 @property
155 def parent(self): 159 def parent(self):
156 return self.mess_data.parent 160 return self.mess_data.parent
157 161
158 @property 162 @property
159 def nick(self): 163 def nick(self):
160 return self.occupant_data.nick 164 return self.occupant_data.nick
165
166 def redraw(self):
167 self._w.set_text(self.markup)
168 self.occupant_data.parent.host.redraw() # FIXME: should not be necessary
161 169
162 def selectable(self): 170 def selectable(self):
163 return True 171 return True
164 172
165 def keypress(self, size, key): 173 def keypress(self, size, key):
179 def _generateMarkup(self): 187 def _generateMarkup(self):
180 # TODO: role and affiliation are shown in a Q&D way 188 # TODO: role and affiliation are shown in a Q&D way
181 # should be more intuitive and themable 189 # should be more intuitive and themable
182 o = self.occupant_data 190 o = self.occupant_data
183 markup = [] 191 markup = []
184 markup.append(('info_msg', '{}{} '.format( 192 markup.append(('info_msg', u'{}{} '.format(
185 o.role[0].upper(), 193 o.role[0].upper(),
186 o.affiliation[0].upper(), 194 o.affiliation[0].upper(),
187 ))) 195 )))
188 markup.append(o.nick) 196 markup.append(o.nick)
197 if o.state is not None:
198 markup.append(u' {}'.format(C.CHAT_STATE_ICON[o.state]))
189 return markup 199 return markup
200
201 # events
202 def updated(self, attributes):
203 self.redraw()
190 204
191 205
192 class OccupantsWidget(urwid.WidgetWrap): 206 class OccupantsWidget(urwid.WidgetWrap):
193 207
194 def __init__(self, parent): 208 def __init__(self, parent):
570 # FIXME: to be checked after refactoring 584 # FIXME: to be checked after refactoring
571 quick_chat.QuickChat.onDelete(self) 585 quick_chat.QuickChat.onDelete(self)
572 if self.type == C.CHAT_GROUP: 586 if self.type == C.CHAT_GROUP:
573 self.host.removeListener('presence', self.presenceListener) 587 self.host.removeListener('presence', self.presenceListener)
574 588
589 def onChatState(self, from_jid, state, profile):
590 super(Chat, self).onChatState(from_jid, state, profile)
591 if self.type == C.CHAT_ONE2ONE:
592 self.title_dynamic = C.CHAT_STATE_ICON[state]
593 self.host.redraw() # FIXME: should not be necessary
575 594
576 quick_widgets.register(quick_chat.QuickChat, Chat) 595 quick_widgets.register(quick_chat.QuickChat, Chat)
577 quick_widgets.register(quick_games.Tarot, game_tarot.TarotGame) 596 quick_widgets.register(quick_games.Tarot, game_tarot.TarotGame)