[Urwid] How do you use SimpleListWalker?

Dominic LoBue dom.lobue at gmail.com
Sat Jun 20 16:50:38 EDT 2009


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).

Oh well. back to extending my custom classes. I'm mostly done with it,
but I ran into a problem with the Button class not having a rows
method. Added the Text class in there too, and now the class isn't
callable :(.

Dominic

On Sat, Jun 20, 2009 at 1:21 PM, Dominic LoBue<dom.lobue at gmail.com> wrote:
> Sorry, I meant the .widget attribute in the convContainer.
>
> Correct me if I am wrong, but methods are the only way to work with
> shared data in an instance implicitly, right? While I suppose that I
> could make a method that returns the widget with the data needed, that
> could create a new copy of the data set every time it was used,
> wouldn't it?
>
> Dominic
>
> On Sat, Jun 20, 2009 at 11:54 AM, Ian Ward<ian at excess.org> wrote:
>> This is just class inheritance.  ThreadedMessageWalker is a ListWalker
>> you can use to store your conversation objects.  If you pass it to a
>> ListBox, the ListBox will display the .widget members of your
>> conversation objects, instead of trying to use the conversation objects
>> themselves as a widgets.
>>
>> Ian
>>
>> Dominic LoBue wrote:
>>> A class within a class? How would I share the data from the parent
>>> class with the child class?
>>>
>>> Dominic
>>>
>>> On Jun 20, 2009, at 7:30, Ian Ward <ian at excess.org> wrote:
>>>
>>>> Corrected example below.
>>>>
>>>> Ian Ward wrote:
>>>>> What you describe should work, but I'm not a fan of mixing such
>>>>> different interfaces in the same class.
>>>>>
>>>>> I would use a slightly modified SimpleListWalker class for storing
>>>>> your
>>>>> list of conversations, and give each of your conversation objects a
>>>>> button object (or whatever widget you like) stored as ".widget"
>>>> class ThreadedMessageWalker(SimpleListWalker):
>>>>
>>>>    def get_focus(self):
>>>>        if len(self)==0: return None, None
>>>>        return self[self.focus].widget, self.focus
>>>>
>>>>    def get_next(self, start_from):
>>>>        pos = start_from+1
>>>>        if len(self) <= pos: return None, None
>>>>        return self[pos].widget, pos
>>>>
>>>>    def get_prev(self, start_from):
>>>>        pos = start_from-1
>>>>        if pos < 0: return None, None
>>>>        return self[pos].widget, pos
>>>>
>>>>> This way your list updates automatically, and the ListBox only sees
>>>>> the
>>>>> widgets.
>>>>>
>>>>> Ian
>>>>
>>>> _______________________________________________
>>>> Urwid mailing list
>>>> Urwid at lists.excess.org
>>>> http://lists.excess.org/mailman/listinfo/urwid
>>>>
>>>
>>>
>>> _______________________________________________
>>> Urwid mailing list
>>> Urwid at lists.excess.org
>>> http://lists.excess.org/mailman/listinfo/urwid
>>>
>>
>>
>>
>> _______________________________________________
>> Urwid mailing list
>> Urwid at lists.excess.org
>> http://lists.excess.org/mailman/listinfo/urwid
>>
>>
>




More information about the Urwid mailing list