[Urwid] Resizing windows in urwid: how small is too small?

James Reeves jreeves at monkeyengines.co.uk
Wed May 16 20:13:50 EDT 2007


Ian Ward wrote:
>
> Hello,
>
> please try the latest svn version to see if it works for you now. 
> Changeset 137 allows box widgets to render 0-row canvases, which should 
> fix your problem.
>
> Ian
>   
I'll be sure to take a look! Though it might have to wait until Saturday :)

I've been working on a patch to add "layout hint" wrapper classes to 
replace the tuple system, as I mentioned in my last email, but I got a 
little side-tracked when I started modifying the classes. I factored out 
some common code for calculating sizes, and tried to see if there were 
less verbose ways of writing some of the functions - not an easy thing 
to do, as often less verbose equates to less efficient.

I was trying to wrap Pile.get_item_rows in a cache decorator, but then I 
realised that it wouldn't work for flow widgets (as even if the size, 
focus and widget_list stay the same, the individual widgets may return 
different values for their rows()). Before the weekend ended, I was 
seeing if using thunks would allow me to cut down on the boiler-plate:

def thunk(func, *args, **kwargs):
    value = []
    def inner():
        if value == []:
            value.append(func(*args, **kwargs))
        return value[0]
    return inner

item_rows = thunk(self.get_item_rows, size, focus)

item_rows()    # calculates value
item_rows()    # returns value in cache


Whether that's a good solution I'm uncertain, and it's not like it cuts 
down on a whole lot of code (probably slightly more expensive than an 
if-statement, too), but I figure it's interesting enough for me to explore.

On the subject of efficiency, have you considered adding support for 
Psyco? Since a lot of code appears to be purely computational (handling 
size and layout calculations), there may be some significant speed-ups 
to be had for relatively little effort.

--
James Reeves




More information about the Urwid mailing list