Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User bagindraerix's Avatar
    Join Date
    Jul 2008
    Posts
    26
    can we make list (for "popup_menu" and "selection_list") in pys60 more object-oriented?

    for example:

    import appuifw
    choices = [u"Symbian",u"PyS60",u"MobileArt"]
    index = appuifw.popup_menu (choices,u"Select:")
    if index == 0 :
    appuifw.note (u"Symbian,aha")
    elif index == 1 :
    appuifw.note (u"PyS60-yeah")
    elif index == 2 :
    appuifw.note (u"IloveMobileArt")
    #########################################

    in script above, we have to make "if statement".
    and if we add more item in list "choices", we have to add also the "if statement".

    i think that is more near to procedural programming.
    can we make it more object-oriented.
    for example, if we have 5 item in list, automatically we have 5 "if statement"
    and if we have 10 item,automatically we will have 10 "if statement".
    without we manually add the "if statement.

    can we do that?

  2. #2
    Nokia Developer Moderator croozeus's Avatar
    Join Date
    May 2007
    Location
    21.46 N 72.11 E
    Posts
    3,650
    Hmph, have you seen a listbox in PyS60?

    We can have something like listbox.current()][0] for indicating the selected option.

    Cheers,
    Croozeus
    Pankaj Nathani
    www.croozeus.com

  3. #3
    Registered User bagindraerix's Avatar
    Join Date
    Jul 2008
    Posts
    26
    oh i forget about that.
    let me try.

  4. #4
    Registered User bagindraerix's Avatar
    Join Date
    Jul 2008
    Posts
    26
    i have tried using Listbox, but i recognize that i have already used UI (appuifw.app.body) CANVAS. so i can't use UI Listbox. is there any other options?

  5. #5
    Super Contributor Rafael T.'s Avatar
    Join Date
    Feb 2008
    Location
    Belo Horizonte, Brazil
    Posts
    744
    Quote Originally Posted by bagindraerix View Post
    i have tried using Listbox, but i recognize that i have already used UI (appuifw.app.body) CANVAS. so i can't use UI Listbox. is there any other options?
    Well, you can change your canvas body to listbox whenever you need. Although you can know the selected item using popup menu too.

    Example:

    Code:
    import appuifw
    
    choices = [u"Symbian",u"PyS60",u"MobileArt"]
    index = appuifw.popup_menu(choices,u"Select:")
    
    if index != None:
        appuifw.note(choices[index])
    Hope it helps,

    Rafael.

  6. #6
    Regular Contributor aaaaapo's Avatar
    Join Date
    Sep 2005
    Location
    Finland, Helsinki
    Posts
    323
    Quote Originally Posted by Rafael T. View Post
    Although you can know the selected item using popup menu too.

    Example:

    Code:
    import appuifw
    
    choices = [u"Symbian",u"PyS60",u"MobileArt"]
    index = appuifw.popup_menu(choices,u"Select:")
    
    if index != None:
        appuifw.note(choices[index])
    And remember, Python is very powerful manipulator of lists. You can construct a single list containing all the choices and "answers":

    Code:
    choices = [
        (u"Symbian", u"Symbian,aha"),
        (u"PyS60", u"PyS60-yeah"),
        (u"MobileArt", u"IloveMobileArt"),
    ]
    index = appuifw.popup_menu([a[0] for a in choices],
                               u"Select:")
    if index != None:
        appuifw.note(choices[index][1])
    And of course you can use callable functions too:

    Code:
    def handle_symbian_stuff():
        appuifw.note(u"Symbian,aha")
    
    choices = [
        (u"Symbian", handle_symbian_stuff),
        # [...]
    ]
    index = appuifw.popup_menu([a[0] for a in choices],
                               u"Select:")
    if index != None:
        choices[index][1]() # This calls function handle_symbian_stuff
                            # If user selected "Symbian" from popup_menu
    --
    Aapo Rista
    http://code.google.com/p/pys60gps/
    http://opennetmap.org/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved