comparison frontends/src/primitivus/chat.py @ 2335:b226f545f67e

primitivus(chat): fixed scroll down (was broken when Primitivus had not the focus and was receiving messages)
author Goffi <goffi@goffi.org>
date Mon, 17 Jul 2017 16:20:55 +0200
parents a21b3b31086d
children 8b37a62336c3
comparison
equal deleted inserted replaced
2334:ca14e1ced3b5 2335:b226f545f67e
403 except KeyError: 403 except KeyError:
404 return False 404 return False
405 else: 405 else:
406 return info_type in quick_chat.ROOM_USER_MOVED 406 return info_type in quick_chat.ROOM_USER_MOVED
407 407
408 def _scrollDown(self):
409 """scroll down message only if we are already at the bottom (minus 1)"""
410 current_focus = self.mess_widgets.focus_position
411 bottom = len(self.mess_walker) - 1
412 if current_focus == bottom - 1:
413 self.mess_widgets.focus_position = bottom # scroll down
414 self.host.redraw() # FIXME: should not be necessary
415
408 def appendMessage(self, message): 416 def appendMessage(self, message):
409 """Create a MessageWidget and append it 417 """Create a MessageWidget and append it
410 418
411 Can merge messages together is desirable (e.g.: multiple joined/leave) 419 Can merge messages together is desirable (e.g.: multiple joined/leave)
412 @param message(quick_chat.Message): message to add 420 @param message(quick_chat.Message): message to add
440 if self.focus_marker is not None: 448 if self.focus_marker is not None:
441 self.mess_walker.remove(self.focus_marker) 449 self.mess_walker.remove(self.focus_marker)
442 self.focus_marker = urwid.Divider('—') 450 self.focus_marker = urwid.Divider('—')
443 self.mess_walker.append(self.focus_marker) 451 self.mess_walker.append(self.focus_marker)
444 self.focus_marker_set = True 452 self.focus_marker_set = True
453 self._scrollDown()
445 else: 454 else:
446 if self.focus_marker_set: 455 if self.focus_marker_set:
447 self.focus_marker_set = False 456 self.focus_marker_set = False
448 457
449 if not message.message: 458 if not message.message:
450 log.error(u"Received an empty message for uid {}".format(message.uid)) 459 log.error(u"Received an empty message for uid {}".format(message.uid))
451 else: 460 else:
452 wid = MessageWidget(message) 461 wid = MessageWidget(message)
453 self.mess_walker.append(wid) 462 self.mess_walker.append(wid)
454 current_focus = self.mess_widgets.focus_position 463 self._scrollDown()
455 bottom = len(self.mess_walker) - 1
456 if current_focus == bottom - 1:
457 self.mess_widgets.focus_position = bottom # scroll down
458 self.host.redraw() # FIXME: should not be necessary
459 if self._user_moved(message): 464 if self._user_moved(message):
460 return # no notification for moved messages 465 return # no notification for moved messages
461 466
462 # notifications 467 # notifications
463 468