Discussion:
[Pythoncard-users] List components
Azam, Naweed
2013-09-18 03:42:46 UTC
Permalink
Hello,

I have a question about list components. When I try to specify text to appear in a List box, each character appears on a line alone and nothing shows up in the stringSelection drop down box.

How do I get the full text of each item (not individual characters) to appear in the List box as well as in the stringSelection drop down box?

This command lists everything in a static text box:
self.components.ClipList.text = str(clips)

This command lists everything with a single character on each line in the List box:
self.components.List1.items = str(clips)

I thought this command would work, but the List box appears empty:
self.components.List1.stringSelection = str(clips)

Note that "clips" is a list of movie titles.

Thanks for any help and guidance.

Regards,
Naweed.
Steven D'Aprano
2013-09-18 04:32:57 UTC
Permalink
Post by Azam, Naweed
Hello,
I have a question about list components. When I try to specify text
to appear in a List box, each character appears on a line alone and
nothing shows up in the stringSelection drop down box.
I'm not an expert on Pythoncard, but given the description of the error,
I would try passing the list of movie titles directly rather than a
single string. E.g. instead of:

# clips is a list of movie titles
self.components.List1.items = str(clips)

I would use this:

self.components.List1.items = clips


This assumes that each movie title is a string.

Calling str() on a list of strings gives you a single string:

py> clips = ['Warm Bodies', 'Gone With The Wind', 'Alien']
py> str(clips)
"['Warm Bodies', 'Gone With The Wind', 'Alien']"


and then iterating over that string gives you individual characters,
including those from the list itself:

py> for element in str(clips):
... print element
...
[
'
W
a
r
m
[... snip long output ...]


Does this help?
--
Steven
Azam, Naweed
2013-09-19 00:30:20 UTC
Permalink
Thank you Steven - that worked perfectly! That was exactly the solution for my problem.

Thanks also for the explanation of why I was seeing that behavior.

Regards,
Naweed.


-----Original Message-----
From: Steven D'Aprano [mailto:***@pearwood.info]
Sent: Wednesday, September 18, 2013 12:33 AM
To: pythoncard-***@lists.sourceforge.net
Subject: Re: [Pythoncard-users] List components
Post by Azam, Naweed
Hello,
I have a question about list components. When I try to specify text
to appear in a List box, each character appears on a line alone and
nothing shows up in the stringSelection drop down box.
I'm not an expert on Pythoncard, but given the description of the error, I would try passing the list of movie titles directly rather than a single string. E.g. instead of:

# clips is a list of movie titles
self.components.List1.items = str(clips)

I would use this:

self.components.List1.items = clips


This assumes that each movie title is a string.

Calling str() on a list of strings gives you a single string:

py> clips = ['Warm Bodies', 'Gone With The Wind', 'Alien']
py> str(clips)
"['Warm Bodies', 'Gone With The Wind', 'Alien']"


and then iterating over that string gives you individual characters, including those from the list itself:

py> for element in str(clips):
... print element
...
[
'
W
a
r
m
[... snip long output ...]


Does this help?



--
Steven

Loading...