urwid make text 'autoscrolling' down

401 Views Asked by At

i'm currently trying to build a little ui for can bus testing on a raspberry pi. it's basically very easy built since it only has a main info screen and an input text. My problem is that i cannot find how to make that input text scroll automatically to the last text sent..

this is how my tiny ui is created..

        # create ui
        self.edit= urwid.Edit(caption="Input: ", edit_text='')
        header = urwid.AttrWrap(urwid.Text('Barobo CAN Control Center (type \'help\' for help, F8 or \'quit\' for exit)'), 'header')
        footer = urwid.AttrWrap(urwid.AttrWrap(self.edit,'editbx'), 'footer')

        self.txt= urwid.Text("")
        listbox_content = [self.txt,valign='bottom']
        listbox = urwid.ListBox(urwid.SimpleListWalker(listbox_content))
        self.frame = urwid.Frame(urwid.AttrWrap(listbox, 'body'), header=header, footer=footer, focus_part='footer')

so what i need now is something that makes self.txt the last text drawn there.. or even make it scrollable with page up and page down keys..

any hints there? Edit: I've learned that i have to append text as widgets to the listwalker. Before I just added text to the only text widget in my listbox

    def log(self, message, level='info'):
        '''
        append a message to the message window
        '''
        if self.__loglevel >= LogDisplay.level.index(level):
            txt = urwid.Text(message)
            self.__walker.append(txt)

but it still doesn't show the last items..

2

There are 2 best solutions below

1
Hassan Voyeau On

Can you use Tkinter then it would simple as

self.see("end")
0
TecDroiD On

Think I have found a solution urwid.ListBox has a function set_focus and all I have to do is to give it the last position in my walker list

            self.listbox.set_focus(self.__walker.positions(True)[0])

sadly, scrolling through them still doesn't work..