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.
>>> i = lbp.Item(u'this is the title', u'this is the description', Icon(u"z:\\resource\\apps\\avkon2.mif", 16424, 16425))
(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:
Well... clear the list .
Refresh the items, and try to select the same item selected before the set_list.
For example (try in a console):
I hope this can be useful for someone, and improvements or changes are very welcome.
from appuifw import *
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.sort() #Don't see this method, is very dirty ;).
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:
Best regards and excuse my english,
Dos al Infinito