×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 16

Thread: List

  1. #1
    Regular Contributor
    Join Date
    Dec 2005
    Posts
    54

    List

    Hi guys
    How can i create a list with 2 array?
    I've tried with

    Code:
    list = [array1,array2]
    without success.

  2. #2
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: List

    Do you mean create an array that contains the two arrays? You can do that like you said. What do you mean by "without success"?
    Code:
    >>> a=[1,2,3]
    >>> b=["a","b","c"]
    >>> c=[a,b]
    c
    [[1, 2, 3], ['a', 'b', 'c']]
    Do you mean create an array that has the elements of the two arrays? You simply add the two arrays:
    Code:
    >>> a=[1,2,3]
    >>> b=["a","b","c"]
    >>> c=a+b
    >>> c
    [1, 2, 3, 'a', 'b', 'c']

  3. #3
    Regular Contributor
    Join Date
    Dec 2005
    Posts
    54

    Re: List

    I would like to create a double-item listbox with 2 arrays.

  4. #4
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: List

    Well that's different. You should have said that from the start. Read the PyS60 Library Reference, the section about Listbox, to see how you can do it (basically you just call the Listbox constructor with an array of 2 tuples). And you can check out this article.

  5. #5
    Regular Contributor
    Join Date
    Dec 2005
    Posts
    54

    Re: List

    I've readed the article and the pdf but i can not understand how to create a list with the two arrays.

  6. #6
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: List

    You don't actually create a Listbox with 2 arrays. You create it with one array that contains the 2 arrays (in the form of tuples). For example:
    Code:
    array1 = (u"Item1", u"Description1")
    array2 = (u"Item2", u"Description2")
    #Now make one array that contains the two
    myarray = [array1, array2]
    #Make the listbox
    appuifw.Listbox(myarray, lambda:None)

  7. #7
    Regular Contributor
    Join Date
    Dec 2005
    Posts
    54

    Re: List

    My code is:

    Code:
    inb = inbox.Inbox()
    sms_ids = inb.sms_messages()
    mittente = []
    msgs = []
    
    for id in sms_ids:
    	msgs.append(inb.content(id))
    	mittente.append(inb.address(id))
    
    items = [msgs, mittente]
    
    appuifw.Listbox(items,lambda:None)
    This is the error:

    Code:
    appuifw.Listbox(items,lambda:None)
    SymbianError: [Errno -6] KErrArgument

  8. #8
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: List

    That's because your arrays are lists, not tuples (like I said before). You have to use msgs=tuple(msgs) and the same for mittente before using them to create the Listbox.

  9. #9
    Regular Contributor
    Join Date
    Dec 2005
    Posts
    54

    Re: List

    Now i've this error:

    Code:
    ValueError: tuple must include 2 or 3 elements

  10. #10
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: List

    That's because a tuple used in a double-line Listbox can only have 2 items as Unicode strings (that's why it's called double-item) or 3 items as Unicode strings and an Icon object.

    If you want to add several entries in your Listbox (I guess you have quite a few messages in your inbox), simply make a tuple for each message, with its content and address. Then put all those tuples in one list and use it to create the Listbox.

  11. #11
    Regular Contributor
    Join Date
    Dec 2005
    Posts
    54

    Re: List

    I would use the double-item listbox like as the http://wiki.forum.nokia.com/index.ph...to_use_Listbox
    where in the first line there are the sms and in the second line the sender of the sms.

  12. #12
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: List

    Exactly. And for each SMS you need to have a tuple. Each tuple has two elements: the content of the SMS and the sender of the SMS. Then put those tuples in one list and make the Listbox with it.
    Code:
    tuple1 = (u"Message1", u"Sender1")
    tuple2 = (u"Message2", u"Sender2")
    ...
    mylist = [tuple1, tuple2,...]
    appuifw.Listbox(mylist, lambda:None)

  13. #13
    Regular Contributor
    Join Date
    Dec 2005
    Posts
    54

    Re: List

    Ok, but if you do not know the number of text messages in advance how do you know how many tuples you should use?

  14. #14
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: List

    The number of messages you have is the same as the number of indexes returned by the sms_messages method. But you don't need that. Make an empty array and append the tuples to it as you create them.
    Code:
    mylist = []
    for id in sms_ids:
      mylist.append((inb.content(id), inb.address(id)))

  15. #15
    Regular Contributor
    Join Date
    Dec 2005
    Posts
    54

    Re: List

    Code:
    items = [mylist]
    
    appuifw.Listbox(items,lambda:None)
    Code:
     appuifw.Listbox(items,lambda:None)
    SymbianError: [Errno -6] KErrArgument
    Edit:

    Now with this code works fine!

    Code:
    items = [mylist[0],mylist[1]]
    Thanks bogdan!
    Last edited by ikaroweb80; 2009-05-14 at 20:28. Reason: solved.

Similar Threads

  1. Display a text file
    By pierre_remi in forum Symbian
    Replies: 3
    Last Post: 2008-11-10, 09:29
  2. Problem with Skin enabling - disabling and Setting List in S60
    By sauvikds in forum Series 40 & S60 Platform Feedback Archive
    Replies: 6
    Last Post: 2008-08-23, 14:29
  3. Problem with Skin enabling - disabling and Setting List in S60
    By sauvikds in forum Symbian User Interface
    Replies: 1
    Last Post: 2008-08-22, 13:45
  4. Problem with Skin enabling - disabling and Setting List in S60
    By sauvikds in forum General Development Questions
    Replies: 1
    Last Post: 2008-08-21, 12:44
  5. 6680 and bluetooth service profiles
    By ceruault in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2005-10-08, 22:24

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×