[Urwid] Best way to update a Frame "footer"

Rebecca Breu rebecca at rbreu.de
Fri Jul 14 03:06:21 EDT 2006


Zitat von Sébastien Pierre <sebastien at xprima.com>:


> focused. The problem I encounter is that there is a noticeable delay
> between the pressing of a key and the appearance of the footer on the
> screen.


>   def run(self):
>     size = self.currentSize = self.ui.get_cols_rows()
>     while True:
>       self.draw_screen( self.currentSize )
>       keys    = self.ui.get_input()
>       focused = self.listbox.get_focus()[0]
>       ...
>       if hasattr(focused, "onFocus"):
>         focused.onFocus(focused)
>       else:
>         self.footer("")
>       ...
>       for k in keys:
>         if k == "window resize":
>           size = self.ui.get_cols_rows()
>           continue
>         self.frame.keypress( size, k )


Mmh, I may be wrong, but to me it looks like you should put the lines
around

self.frame.keypress( size, k )

before the line changing the footer. As it is, you press a key, which is
read by get_input. Then comes the onFocus, which doesn't change anything yet,
because the key hasn't been passed to the frame until then. After that you
call the keypress() of the frame. OK, then loop is run again, the
redraw doesn't change anything yet ('cause the footer didn't) and another
get_input() is performed -- but the get_input blocks a moment if there are
no new keys. After that the footer reacts to the keypress of the *last* run
through the loop.

So the delay you notice may be the delay of the get_input which waits for
new keys.


Rebecca





More information about the Urwid mailing list