John Powell | 3 Oct 18:55 2007

ListBox selected item not displayed

Hey Guys,
 
I hope you can give me a clue as to what I am doing wrong here. I have attached a small example that demonstrates my problem. While moving through elements in the listbox I do not see the text foreground and background change as I expect it should. I must be missing something obvious.
 
Thanks in advance,
 
./John
Attachment (listboxtest.py): application/octet-stream, 2116 bytes
_______________________________________________
Urwid mailing list
Urwid <at> lists.excess.org
http://lists.excess.org/mailman/listinfo/urwid
John Powell | 3 Oct 22:49 2007

Re: ListBox selected item not displayed

ya.. well.. never mind
 
view.render(size, focus=True) was the parameter I was missing. I still don't fully understand the significance of that however it works well enough for now.
 
If anyone would care to enlighten me as to why this must be set please do so. More specifically why would you want it not set?
 
Regards,
 
John

From: urwid-bounces+jpowell=vmware.com <at> lists.excess.org [mailto:urwid-bounces+jpowell=vmware.com <at> lists.excess.org] On Behalf Of John Powell
Sent: Wednesday, October 03, 2007 9:55 AM
To: Urwid General Discussion
Subject: [Urwid] ListBox selected item not displayed

Hey Guys,
 
I hope you can give me a clue as to what I am doing wrong here. I have attached a small example that demonstrates my problem. While moving through elements in the listbox I do not see the text foreground and background change as I expect it should. I must be missing something obvious.
 
Thanks in advance,
 
./John
_______________________________________________
Urwid mailing list
Urwid <at> lists.excess.org
http://lists.excess.org/mailman/listinfo/urwid
Ian Ward | 5 Oct 03:10 2007

Re: ListBox selected item not displayed

John Powell wrote:
> ya.. well.. never mind
>  
> view.render(size, focus=True) was the parameter I was missing. I still
> don't fully understand the significance of that however it works well
> enough for now.
>  
> If anyone would care to enlighten me as to why this must be set please
> do so. More specifically why would you want it not set?

It's only interesting if you're writing your own widget classes.  It has
a default of False for historical reasons: at one point there was no
focus parameter to render(), and it meant there was less code for me to
change by giving it a default value.

I am planning to add a generic main loop that most applications will be
able to use to reduce the boiler-plate repetition and potential for
bugs, such as forgetting this parameter.

Ian
Aaron Gallagher | 26 Oct 09:18 2007
Picon

Rendering and caching

How are rendered objects cached, and how does urwid know when to call the render function? I've tried making my own widgets, but they only seem to work if I call render functions from preexisting widgets; returning my own canvases renders once, but never calls render again. I would also like to know how can I force rerendering given an object?

And is there any way to make text markup easier? Using lists of markup lists is bothering me a bit.

Aaron Gallagher


_______________________________________________
Urwid mailing list
Urwid <at> lists.excess.org
http://lists.excess.org/mailman/listinfo/urwid
Ian Ward | 26 Oct 16:28 2007

Re: Rendering and caching

Aaron Gallagher wrote:
> How are rendered objects cached, and how does urwid know when to call 
> the render function? I've tried making my own widgets, but they only 
> seem to work if I call render functions from preexisting widgets; 
> returning my own canvases renders once, but never calls render again. I 
> would also like to know how can I force rerendering given an object?

Since release 0.9.8 all widgets cache the result of the render function:
http://excess.org/urwid/wiki/ChangeLog#Urwid0.9.8

If the result is in the cache then it will be returned instead of 
calling the actual render function.  If your widget has changed and will 
render differently then it should call self._invalidate() to clear its 
canvas from the cache.

You can also disable the cache for your widget by including 
"no_cache=['render']" in your class definition, but that will have a 
negative impact on performance.

> And is there any way to make text markup easier? Using lists of markup 
> lists is bothering me a bit.

I'm open to suggestions.  Would you prefer some type of escape codes in 
the text?

Ian
Aaron Gallagher | 26 Oct 19:23 2007
Picon

Re: Rendering and caching

On Oct 26, 2007, at 7:28 AM, Ian Ward wrote:
>> And is there any way to make text markup easier? Using lists of  
>> markup
>> lists is bothering me a bit.
>
> I'm open to suggestions.  Would you prefer some type of escape  
> codes in
> the text?

I suppose that escape codes would be easier to write, but I assume  
that it's harder for urwid to deal with those because of the way that  
curses does formatting. Oh well, I can just write my code this way.

Aaron Gallagher
<habnabit <at> gmail.com>
Ian Ward | 27 Oct 17:43 2007

Re: Rendering and caching

Aaron Gallagher wrote:
> On Oct 26, 2007, at 7:28 AM, Ian Ward wrote:
>>> And is there any way to make text markup easier? Using lists of  
>>> markup
>>> lists is bothering me a bit.
>> I'm open to suggestions.  Would you prefer some type of escape  
>> codes in
>> the text?
> 
> I suppose that escape codes would be easier to write, but I assume  
> that it's harder for urwid to deal with those because of the way that  
> curses does formatting. Oh well, I can just write my code this way.

There's no real problem with implementing some kind of in-line markup:

"Here is some <important>brighter</important> text"
instead of:
["Here is some ", ('important', "brighter"), " text"]

I chose the latter because it meant that I would never have to worry
about escaping "special" characters in text.  If there is enough
interest in supporting something like the former example, it could be added.

Ian

Gmane