Working scroll to bottom function

This commit is contained in:
John Mertz 2024-03-01 18:21:48 -07:00
parent d04d674983
commit c76f53daab
Signed by: jpm
GPG Key ID: E9C5EA2D867501AB
1 changed files with 18 additions and 10 deletions

View File

@ -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():