From c76f53daab50e9604d033d679409afbd5e45abbe Mon Sep 17 00:00:00 2001 From: John Mertz Date: Fri, 1 Mar 2024 18:21:48 -0700 Subject: [PATCH] Working scroll to bottom function --- voipms-sms-tui.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/voipms-sms-tui.py b/voipms-sms-tui.py index 02f32b6..5d5959d 100644 --- a/voipms-sms-tui.py +++ b/voipms-sms-tui.py @@ -135,10 +135,12 @@ class ConversationView(urwid.WidgetWrap): super().__init__(self.main_window()) def update_conversation(self, force_update=False): - return urwid.SimpleListWalker(self.model.get_messages()) + return self.model.get_messages() def on_conversation_button(self, button, state): """Notify the model of a new conversation setting.""" + self.scroll_to_bottom() + return 1 if state: self.model.set_conversation(button.get_label().split("\n")[0]) self.model.set_conversation(self.conversation) @@ -162,7 +164,7 @@ class ConversationView(urwid.WidgetWrap): conversation = self.model.get_conversations()[0] def conversation(self): - return urwid.ListBox(self.update_conversation()) + return self.update_conversation() def button(self, t, fn): w = urwid.Button(t, fn) @@ -202,6 +204,9 @@ class ConversationView(urwid.WidgetWrap): def send_update(self, field, msg): field=msg.edit_text + def scroll_to_bottom(self): + self.scrollable.set_scrollpos(-1) + def main_window(self): self.chat = self.conversation() self.send_content = "Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. Oh, Hi. wassup!" @@ -218,23 +223,25 @@ class ConversationView(urwid.WidgetWrap): left=0, right=0 ) + self.char_count="0/140"; + self.send_pile = urwid.Pile([ + self.send_button, + urwid.Text(self.char_count, align=urwid.CENTER) + ]) self.send = urwid.Columns([ (urwid.WEIGHT, 8, self.send_box), - self.send_button, + self.send_pile, ]) self.header = urwid.Text("VoIP.ms SMS TUI", urwid.CENTER) + self.scrollable = urwid.Scrollable(urwid.Pile(self.chat)) + self.sb = urwid.ScrollBar(self.scrollable, trough_char=urwid.ScrollBar.Symbols.LITE_SHADE) self.view = urwid.Pile([ ('pack', urwid.AttrMap(self.header, "header")), - urwid.AttrMap( - urwid.ScrollBar( - self.chat, - trough_char=urwid.ScrollBar.Symbols.LITE_SHADE - ), - "body" - ), + urwid.AttrMap(self.sb, "body"), ('pack', urwid.AttrMap(self.send, "footer")), ] ) + self.scroll_to_bottom() c = self.conversation_selection() w = urwid.Columns( [ @@ -272,6 +279,7 @@ def main(): view.on_conversation_change(conversation) view.update_conversation(True) urwid.MainLoop(view, view.palette, unhandled_input=unhandled).run() + view.scroll_to_bottom() def setup():