On Tue, Aug 13, 2013 at 9:52 AM, Matthew Mosesohn
<[email protected]> wrote:
> Actually, I just found a better solution:
>
> def render(self, size, focus=False):
>        if focus:
>          self.toolbar.set_text(self.tip)
>        canv = super(EditWithTip, self).render(size, focus)
>
> Render gets called all the time for the object, but focus is only True if
> it's in focus. It's good enough for my needs and I don't need to handle
> ListBox indexes and check positions. I just want to be able to add
> tooltip-enhanced Edits arbitrarily anywhere and not have to track it or
> store tooltip strings separately.

Be careful with this, render() gets called when the widget is actually
rendering, so it's possible that the previous tool tip has been used
to calculate how much space it needs on the screen. If you swap in a
tool-tip that takes more rows or less rows you could cause the render
to fail.

With the methods I describe you can still store your tool-tips on the
widgets themselves, just just a standard attribute name on the widget
and getattr(), you don't need to handle widget positions.

_______________________________________________
Urwid mailing list
[email protected]
http://lists.excess.org/mailman/listinfo/urwid

Reply via email to