Discussion:
[Urwid] unable to append to a Pile
SHAIKH TAUSEEF HUSSAIN
2013-08-03 17:45:47 UTC
Permalink
I have a list of key values in a map tmpMap, each of the key is text.
I want to created a pile of text widgets, make this pile added to the
second column of a Columns widget.
I used the code snippet below

userChoices = urwid.Pile([])
listofKeysIntmpMap = tmpMap.keys()
i=1

for j in range(3,len(tmpMap)) :

userChoicesText =
urwid.Text(tmpMap.get(listofKeysIntmpMap[j])) #this text gets updated so
the forloop works

userChoices.contents.append(userChoicesText)
i+=1

box =
urwid.BoxAdapter(urwid.ListBox(urwid.SimpleListWalker([(userChoices)])),
height=i)
listBoxCell = urwid.AttrWrap(urwid.Columns([('fixed', 40,
displayText),box]))

But I am not able to use the append of the Pile.
The error shown is something like this :

File "./yamlUrwidUIPhase8FrameFinalAppD.py", line 230, in createBlock
userChoices.contents.append(userChoicesText)
File "/home/gehna/urwidWorkInProgress/urwid/monitored_list.py", line 400,
in append
slice(len(self), len(self)), [item])
File "/home/gehna/urwidWorkInProgress/urwid/monitored_list.py", line 239,
in _adjust_focus_on_contents_modified
focus = self._validate_contents_modified(indices, new_items)
File "/home/gehna/urwidWorkInProgress/urwid/container.py", line 1243, in
_contents_modified
raise PileError("added content invalid: %r" % (item,))
urwid.container.PileError: added content invalid: <Text flow widget
b'Peking University'>
--
Kind Regards
Tauseef Hussain
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.excess.org/pipermail/urwid/attachments/20130803/8dd91202/attachment.htm
Ian Ward
2013-08-04 17:11:35 UTC
Permalink
On Sat, Aug 3, 2013 at 1:45 PM, SHAIKH TAUSEEF HUSSAIN
Post by SHAIKH TAUSEEF HUSSAIN
userChoicesText =
urwid.Text(tmpMap.get(listofKeysIntmpMap[j])) #this text gets updated so the
forloop works
userChoices.contents.append(userChoicesText)
i+=1
You can append to the contents but you need an options value for each
item, so try changing your code above to:
userChoices.contents.append((userChoicesText, ('weight', 1)))

See also the reference for Pile.contents:
http://excess.org/urwid/docs/reference/widget.html#urwid.Pile.contents

Ian

Loading...