Wrong attached file. Sorry. A problem with Firefox.

2010/9/22 Juanjo Conti <[email protected]>

> BTW, if you wanna try my snippet you have to have a log.txt file in the
> same directory as the script. I have this logmaker.sh bash script that fills
> it.
>
> 2010/9/22 Juanjo Conti <[email protected]>
>
> 2010/9/22 Mariusz Kruk <[email protected]>
>>
>> If I understand you right, you want the newly appended content to appear
>>> on
>>> the screen and the whole listbox to automaticaly scroll accodringly.
>>> You'd have to call set_focus() from the ListBox.
>>>
>>
>> I see. Great. I changed the __call__ method in ReadFile class like this:
>>
>>     def __call__(self, loop, data):
>>         line = self.fd.readline()
>>         if line:
>>             line = line.strip()
>>             self.walker.append(urwid.Text(line))
>>             self.listbox.set_focus(self.walker.focus + 1)
>>         loop.set_alarm_in(1, self)
>>
>> It's ok to use walker.focus or should I use walker.get_focus()[1] instead?
>>
>> BTW, if i hit the up and down keys the behaviour is a little weird. The
>> auto scroll stops until I use again the keys to go to the button of the
>> "stream".
>>
>> I'll keep playing with this and let you know any new.
>>
>> Thanks,
>>
>> --
>> Juanjo Conti
>> blog: http://www.juanjoconti.com.ar
>>
>
>
>
> --
> Juanjo Conti
> blog: http://www.juanjoconti.com.ar
>



-- 
Juanjo Conti
blog: http://www.juanjoconti.com.ar

Attachment: logmaker.sh
Description: Bourne shell script

#!/usr/bin/python

import urwid

class ReadFile(object):

    def __init__(self, filename, walker, listbox):
        self.fd = open(filename, 'r')
        self.fd.seek(0, 2)
        self.walker = walker
        self.listbox = listbox

    def __call__(self, loop, data):
        line = self.fd.readline()
        if line:
            line = line.strip()
            self.walker.append(urwid.Text(line))
            self.listbox.set_focus(self.walker.focus + 1)
        loop.set_alarm_in(0.5, self)

def main():
    palette = [
        ('body','black','dark cyan', 'standout'),
        ('foot','light gray', 'black'),
        ('key','light cyan', 'black', 'underline'),
        ('title', 'white', 'black',),
        ]

    footer_text = [
        ('title', "Fibonacci Set Viewer"), "    ",
        ('key', "UP"), ", ", ('key', "DOWN"), ", ",
        ('key', "PAGE UP"), " and ", ('key', "PAGE DOWN"),
        " move view  ",
        ('key', "Q"), " exits",
        ]

    def exit_on_q(input):
        if input in ('q', 'Q'):
            raise urwid.ExitMainLoop()

    walker = urwid.SimpleListWalker([])
    listbox = urwid.ListBox(walker)
    read_file = ReadFile('log.txt', walker, listbox)
    footer = urwid.AttrMap(urwid.Text(footer_text), 'foot') #EDIT
    view = urwid.Frame(urwid.AttrWrap(listbox, 'body'), footer=footer)
    loop = urwid.MainLoop(view, palette, unhandled_input=exit_on_q)
    loop.set_alarm_in(0.5, read_file)
    loop.run()


if __name__=="__main__":
    main()
_______________________________________________
Urwid mailing list
[email protected]
http://lists.excess.org/mailman/listinfo/urwid

Reply via email to