[Urwid] How do you use SimpleListWalker?

Dominic LoBue dom.lobue at gmail.com
Mon Jun 22 09:57:23 EDT 2009


I figured it out with google's help. Here's my demo code:
class child(list):
    def __init__(self, parentmethod):
        self.parentmethod = parentmethod
    def more(self, value):
        self.parentmethod()
        self.append(value)


class parent(object):
    def __init__(self):
        self.label = 'blarg'
        self.stuffs = child(self.set_label)
    def set_label(self):
        self.label += "1"
    def show_label(self):
        print self.label


In the demo you instantiate parent and then just use the more method
to append values to the child list, and when its used it also calls
the parent method set_label. :)

Thanks for all your help, I really appreciate it!

Dominic

On Sat, Jun 20, 2009 at 3:18 PM, Dominic LoBue<dom.lobue at gmail.com> wrote:
> Ohh, I see. Thanks, that would never have occurred to me!
>
> That just leaves me with two remaining questions: If it is possible to
> share the same set of private variables between two classes (say
> parent and child, like how methods work with self), how is it done? If
> sharing is not possible, then how do I communicate to the
> convContainer dict that one of the lists it contains has been
> modified?
>
> Dominic
>
> On Sat, Jun 20, 2009 at 2:14 PM, Ian Ward<ian at excess.org> wrote:
>> Dominic LoBue wrote:
>>> I just found what you're talking about in browse.py. You basically
>>> have self.widget being set to urwid.Text(somevar) when you initialize
>>> the class, when somevar being passed when you instantiate the class.
>>> This would make the text that the widget displays static, wouldn't it?
>>> That won't work in my case since I plan on dynamically displaying a
>>> little summary on the newest messages in the thread (subject, labels,
>>> senders, date of last message, etc).
>>
>> You can always call self.widget.set_text(somevalue) when the subject,
>> senders, labels, etc change.  Then the widget knows it needs to be redrawn.
>>
>> Ian
>>
>>
>> _______________________________________________
>> Urwid mailing list
>> Urwid at lists.excess.org
>> http://lists.excess.org/mailman/listinfo/urwid
>>
>>
>




More information about the Urwid mailing list