×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    26

    Question can we make list (for "popup_menu" and "selection_list") more OOP?

    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
    Join Date
    May 2007
    Location
    21.46 N 72.11 E
    Posts
    3,800

    Re: can we make list (for "popup_menu" and "selection_list") more OOP?

    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
    Join Date
    Jul 2008
    Posts
    26

    Re: can we make list (for "popup_menu" and "selection_list") more OOP?

    oh i forget about that.
    let me try.

  4. #4
    Registered User
    Join Date
    Jul 2008
    Posts
    26

    Re: can we make list (for "popup_menu" and "selection_list") more OOP?

    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
    Join Date
    Feb 2008
    Location
    Belo Horizonte, Brazil
    Posts
    744

    Re: can we make list (for "popup_menu" and "selection_list") more OOP?

    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
    Join Date
    Sep 2005
    Location
    Finland, Helsinki
    Posts
    323

    Re: can we make list (for "popup_menu" and "selection_list") more OOP?

    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
  •  
×