×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    Sep 2007
    Location
    Buenos Aires, Argentina
    Posts
    5

    Post Friendly Listbox, or a mix between list and Listbox ;)

    After suffering the original Listbox on several projects, and discard the canvas based too (because lost the phone visual theme), I try making a more easy -almost for me!- version (for PyS60 >= v1.9).
    The only 'strange' part is for convert the builtin method Listbox to a class (why is not a class in first place like Canvas?).

    You have two classes. The first, 'Item', is optional but I miss this style from the appuifw2 extension from the old PyS60 .
    Item(caption, desc=None, icon=None)
    desc is the second line of text, and icon can be an appuifw.Icon.
    For example:
    >>> i = lbp.Item(u'this is the title', u'this is the description', Icon(u"z:\\resource\\apps\\avkon2.mif", 16424, 16425))
    >>> i.value()
    (u'titulo', u'texto', <appuifw.Icon object at 0xc2d810>)

    The params are properties, because this you can do:
    i.desc = 'This is another description'

    Next one is the ListboxPlus object. They act like a mix between the original Listbox and the Python's list type.

    obj = lbp.ListboxPlus(with_desc=True, with_icon=True, callback=None)

    Now you can do things like obj.append(Item(...)), obj.pop(), etc.
    Remember, you can use the classic tuple for all, like obj.append((u'title', u'description', Icon(...))).
    At the same time, all the original Listbox methods are here, like current, set_list, etc.

    You have this new methods:
    body.clear()
    Well... clear the list .
    body.refresh(current_item=None)
    Refresh the items, and try to select the same item selected before the set_list.

    For example (try in a console):
    Code:
    from appuifw import *
    import lbp
    app.body = body = lbp.ListboxPlus(with_icon=True)
    i1 = lbp.Item(u'1', u'texto', Icon(u"z:\\resource\\apps\\avkon2.mif", 16424, 16425))
    i2 = lbp.Item(u'2', u'texto', Icon(u"z:\\resource\\apps\\avkon2.mif", 16424, 16425))
    i3 = lbp.Item(u'3', u'texto', Icon(u"z:\\resource\\apps\\avkon2.mif", 16424, 16425))
    i4 = lbp.Item(u'4', u'texto', Icon(u"z:\\resource\\apps\\avkon2.mif", 16424, 16425))
    body.append(i3)
    body.append(i2)
    body.append(i4)
    body.append(i1)
    body.sort() #Don't see this method, is very dirty ;).
    I hope this can be useful for someone, and improvements or changes are very welcome.

    Is ugly, but a start. Dont't broke compatibility with old code, and is 'subclass capable' and more Pythonic I think .

    You can download from here:
    http://www.dosalinfinito.com.ar/lbp.zip

    Best regards and excuse my english,

    Sebastián Lezica
    Dos al Infinito

  2. #2
    Super Contributor
    Join Date
    Nov 2007
    Location
    Sertaozinho/Brazil
    Posts
    768

    Re: Friendly Listbox, or a mix between list and Listbox ;)

    Quote Originally Posted by slezica View Post
    The only 'strange' part is for convert the builtin method Listbox to a class (why is not a class in first place like Canvas?).
    I dont know the reason, but I liked the setattr/getattr solution

    Quote Originally Posted by slezica View Post
    body.sort() #Don't see this method, is very dirty .
    I hope this can be useful for someone, and improvements or changes are very welcome.
    Since you are trying to keep compatibility with list, Listbox and adding one more class to represent items, the proposed solution was necessary. I think I can not propose anything substantially better without forcing all list items to be an Item class. It is pretty fine Some cosmetics changes could be interesting to become more pythonic, like while self: instead while len(self)>0:. But it is not important.

    Are you thinking in a list with checkboxes ?
    Jouni sent a code months ago with this solution. In fact, he used checked/unchecked icons (from avkon), exchanging them after user selection.

    Thanks for sharing it !

  3. #3
    Registered User
    Join Date
    Sep 2007
    Location
    Buenos Aires, Argentina
    Posts
    5

    Re: Friendly Listbox, or a mix between list and Listbox ;)

    Quote Originally Posted by marcelobarrosalmeida View Post
    I dont know the reason, but I liked the setattr/getattr solution
    Since you are trying to keep compatibility with list, Listbox and adding one more class to represent items, the proposed solution was necessary. I think I can not propose anything substantially better without forcing all list items to be an Item class. It is pretty fine Some cosmetics changes could be interesting to become more pythonic, like while self: instead while len(self)>0:. But it is not important.
    An old bad habit..., thanks for the correction. I like Python, with the time come more and more readable .

    Quote Originally Posted by marcelobarrosalmeida View Post
    Are you thinking in a list with checkboxes ?
    Jouni sent a code months ago with this solution. In fact, he used checked/unchecked icons (from avkon), exchanging them after user selection.
    Excelent tip!. Is a good next step . I try to add the functionality when I finish the current project.

    Thanks for the response and for your 'window.py' library, is very handy .

  4. #4
    Super Contributor
    Join Date
    Nov 2007
    Location
    Sertaozinho/Brazil
    Posts
    768

    Re: Friendly Listbox, or a mix between list and Listbox ;)

    Well remembered ... I need to update window.py, current version supports tabs ..

  5. #5
    Registered User
    Join Date
    Mar 2011
    Posts
    44

    Re: Friendly Listbox, or a mix between list and Listbox ;)

    Hi

    Is it possible to put the text first then the icon? I mean something like:

    items1 = [(icon1, u"1"), (icon2, u"2"), (icon3, u"3")]

    I tried this but it is giving error

    Is it possible to make the icon big? Currently it is about 1cm*1cm.I want it to be like 1cm height and 5cm length.So my listbox will be like:

    1" ................................... "(image will be within the quotes)
    2"....................................."
    3"....................................."

    Hope I am clear with my problems.Hope to get response as soon as possible

    Regards
    Simil

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

    Re: Friendly Listbox, or a mix between list and Listbox ;)

    Quote Originally Posted by Simil Susan View Post
    Hi

    Is it possible to put the text first then the icon? I mean something like:

    items1 = [(icon1, u"1"), (icon2, u"2"), (icon3, u"3")]

    I tried this but it is giving error

    Is it possible to make the icon big? Currently it is about 1cm*1cm.I want it to be like 1cm height and 5cm length.So my listbox will be like:

    1" ................................... "(image will be within the quotes)
    2"....................................."
    3"....................................."

    Hope I am clear with my problems.Hope to get response as soon as possible

    Regards
    Simil
    Hi,

    No, it is not possible to do those things, unfortunately.

    There are 2 possible solutions, but both require a lot of work: create an extension (in Symbian C++) for a Listbox the way you want it, or draw your Listbox on a Canvas and handle its events (similar to this).

  7. #7
    Registered User
    Join Date
    Sep 2011
    Posts
    29

    Re: Friendly Listbox, or a mix between list and Listbox ;)

    import appuifw, e32
    app_lock = e32.Ao_lock()

    def quit():
    app_lock.signal()
    appuifw.app.exit_key_handler = quit

    icon1 = appuifw.Icon(u"help.mbm", 10,12)
    icon2 = appuifw.Icon(u"help.mbm", 10,12)

    #items = [(u"A"), (u"B")]
    items = [(u"A", icon1),(u"B", icon2)]

    #Define a function that is called when an item is selected

    def handle_selection():
    if items[lb.current()][0] == "A":
    appuifw.note(u"hi")
    elif items[lb.current()][0] == "B":
    appuifw.note(u"hello")

    #Create an instance of Listbox and set it as the application's body

    lb = appuifw.Listbox(items, handle_selection)
    appuifw.app.body = lb

    #Wait for the user to request the exit
    app_lock.wait()

    I' using this code to display icons along with listbox, but when I execute it i'm gettin Symbian Error:KErrnot found.
    What changes do I have to make in the code.

    Pls do let me know.

  8. #8
    Registered User
    Join Date
    Sep 2011
    Posts
    29

    Re: Friendly Listbox, or a mix between list and Listbox ;)

    I fixed it...

  9. #9
    Registered User
    Join Date
    Sep 2011
    Posts
    29

    Re: Friendly Listbox, or a mix between list and Listbox ;)

    import appuifw, e32
    app_lock = e32.Ao_lock()
    s == 0

    def quit():
    app_lock.signal()
    appuifw.app.exit_key_handler = quit

    icon1 = appuifw.Icon(u"help.mbm", 0, 0 )

    item = [(u"A", icon1)]

    def stop():
    global s
    s.stop()
    s.close()

    s = audio.sound.open(u"Var.mp3")
    s.play()

    lb = appuifw.Listbox(item, s )
    appuifw.app.body = lb

    app_lock.wait()

    Hi..
    As i'm trying to display listbox with Audio file. From the above code I'm getting an Error as
    NameError:global name 's' is not defined.

    What do I do to overcome this error.

Similar Threads

  1. how to display the Listbox
    By arungupta_2jan in forum Symbian
    Replies: 4
    Last Post: 2009-03-03, 21:10
  2. Using the font from setting list in custom listbox
    By alav in forum Symbian User Interface
    Replies: 1
    Last Post: 2008-11-05, 17:17
  3. Listbox...
    By harsh_vs in forum Symbian User Interface
    Replies: 2
    Last Post: 2008-02-15, 20:29
  4. Listbox inside listbox
    By Zefa in forum Symbian User Interface
    Replies: 2
    Last Post: 2007-05-09, 02:32
  5. Replies: 0
    Last Post: 2003-08-29, 08:25

Posting Permissions

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