Mercurial > libervia-backend
comparison frontends/src/primitivus/chat.py @ 1979:70e83ca721c8
primitivus (chat): fixed timestamp/nick (un)hiding + new redraw and printMessages methods
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 28 Jun 2016 18:29:56 +0200 |
parents | a9908e751c42 |
children | 2a85c818751a |
comparison
equal
deleted
inserted
replaced
1978:8156f2116dc9 | 1979:70e83ca721c8 |
---|---|
79 log.error(u"Can't find message for uid {}".format(self.mess_data.uid)) | 79 log.error(u"Can't find message for uid {}".format(self.mess_data.uid)) |
80 | 80 |
81 @message.setter | 81 @message.setter |
82 def message(self, value): | 82 def message(self, value): |
83 self.mess_data.message = {'':value} | 83 self.mess_data.message = {'':value} |
84 self._w.set_text(self.markup) | 84 self.redraw() |
85 | 85 |
86 @property | 86 @property |
87 def type(self): | 87 def type(self): |
88 try: | 88 try: |
89 return self.mess_data.type | 89 return self.mess_data.type |
90 except AttributeError: | 90 except AttributeError: |
91 return C.MESS_TYPE_INFO | 91 return C.MESS_TYPE_INFO |
92 | |
93 def redraw(self): | |
94 self._w.set_text(self.markup) | |
92 | 95 |
93 def selectable(self): | 96 def selectable(self): |
94 return True | 97 return True |
95 | 98 |
96 def keypress(self, size, key): | 99 def keypress(self, size, key): |
239 self._removeOccupantsPanel() | 242 self._removeOccupantsPanel() |
240 else: | 243 else: |
241 self._appendOccupantsPanel() | 244 self._appendOccupantsPanel() |
242 elif key == a_key['TIMESTAMP_HIDE']: # user wants to (un)hide timestamp | 245 elif key == a_key['TIMESTAMP_HIDE']: # user wants to (un)hide timestamp |
243 self.show_timestamp = not self.show_timestamp | 246 self.show_timestamp = not self.show_timestamp |
244 for wid in self.mess_walker: | 247 self.redraw() |
245 wid._invalidate() | |
246 elif key == a_key['SHORT_NICKNAME']: # user wants to (not) use short nick | 248 elif key == a_key['SHORT_NICKNAME']: # user wants to (not) use short nick |
247 self.show_short_nick = not self.show_short_nick | 249 self.show_short_nick = not self.show_short_nick |
248 for wid in self.mess_walker: | 250 self.redraw() |
249 wid._invalidate() | |
250 elif key == a_key['SUBJECT_SWITCH']: # user wants to (un)hide group's subject or change its apperance | 251 elif key == a_key['SUBJECT_SWITCH']: # user wants to (un)hide group's subject or change its apperance |
251 if self.subject: | 252 if self.subject: |
252 self.show_title = (self.show_title + 1) % 3 | 253 self.show_title = (self.show_title + 1) % 3 |
253 if self.show_title == 0: | 254 if self.show_title == 0: |
254 self.setSubject(self.subject, 'clip') | 255 self.setSubject(self.subject, 'clip') |
311 if args: | 312 if args: |
312 if args[0].startswith("lang="): | 313 if args[0].startswith("lang="): |
313 lang = args[0][5:].strip() | 314 lang = args[0][5:].strip() |
314 self.filters.append(lambda mess_data: lang in mess_data.message) | 315 self.filters.append(lambda mess_data: lang in mess_data.message) |
315 | 316 |
316 del self.mess_walker[:] | 317 self.printMessages() |
317 for message in self.messages.itervalues(): | |
318 self.appendMessage(message) | |
319 | 318 |
320 def presenceListener(self, entity, show, priority, statuses, profile): | 319 def presenceListener(self, entity, show, priority, statuses, profile): |
321 """Update entity's presence status | 320 """Update entity's presence status |
322 | 321 |
323 @param entity (jid.JID): entity updated | 322 @param entity (jid.JID): entity updated |
474 self.chat_widget.header = urwid.AttrMap(self.subj_wid, 'title') | 473 self.chat_widget.header = urwid.AttrMap(self.subj_wid, 'title') |
475 self.host.redraw() | 474 self.host.redraw() |
476 | 475 |
477 ## Messages | 476 ## Messages |
478 | 477 |
478 def printMessages(self, clear=True): | |
479 """generate message widgets | |
480 | |
481 @param clear(bool): clear message before printing if true | |
482 """ | |
483 if clear: | |
484 del self.mess_walker[:] | |
485 for message in self.messages.itervalues(): | |
486 self.appendMessage(message) | |
487 | |
488 def redraw(self): | |
489 """redraw all messages""" | |
490 for w in self.mess_walker: | |
491 try: | |
492 w.redraw() | |
493 except AttributeError: | |
494 pass | |
495 | |
479 def updateHistory(self, size=C.HISTORY_LIMIT_DEFAULT, search='', profile='@NONE@'): | 496 def updateHistory(self, size=C.HISTORY_LIMIT_DEFAULT, search='', profile='@NONE@'): |
480 del self.mess_walker[:] | 497 del self.mess_walker[:] |
481 if search: | 498 if search: |
482 self.mess_walker.append(urwid.Text(_(u"Results for searching the globbing pattern: {}").format(search))) | 499 self.mess_walker.append(urwid.Text(_(u"Results for searching the globbing pattern: {}").format(search))) |
483 self.mess_walker.append(urwid.Text(_(u"Type ':history <lines>' to reset the chat history").format(search))) | 500 self.mess_walker.append(urwid.Text(_(u"Type ':history <lines>' to reset the chat history").format(search))) |
484 super(Chat, self).updateHistory(size, search, profile) | 501 super(Chat, self).updateHistory(size, search, profile) |
485 | 502 |
486 def _onHistoryPrinted(self): | 503 def _onHistoryPrinted(self): |
487 """Refresh or scroll down the focus after the history is printed""" | 504 """Refresh or scroll down the focus after the history is printed""" |
488 for message in self.messages.itervalues(): | 505 self.printMessages(clear=False) |
489 self.appendMessage(message) | |
490 super(Chat, self)._onHistoryPrinted() | 506 super(Chat, self)._onHistoryPrinted() |
491 | 507 |
492 def onPrivateCreated(self, widget): | 508 def onPrivateCreated(self, widget): |
493 self.host.contact_lists[widget.profile].specialResourceVisible(widget.target) | 509 self.host.contact_lists[widget.profile].specialResourceVisible(widget.target) |
494 | 510 |