You Are Here:

Community: Developer Discussion Boards

#1 Old How to create an empty listbox, WIKI - 2007-11-29, 09:13

Join Date: Nov 2007
Posts: 10
JereKuusela
Offline
Registered User
I need help with understanding the code in "How to" list.
I just couldn't find explanations anywhere.

Link to it

or here:

Quote:
import e32, appuifw

class CustomList( object ):
def __init__( self, aList=[], aObserver=lambda:None,
aEmptyMessage=u'No data'):
self._iList = aList
self._mObserver = aObserver
self._iEmptyMessage = unicode(aEmptyMessage)
self._iCnv = appuifw.Canvas( self._redraw,
resize_callback=self._redraw )
self._iBindings = {}
appuifw.app.body = self._iCnv
if self._iList:
self._iListbox = appuifw.Listbox(self._iList, self._observer)
else:
self._iListbox = None

def _showEmpty( self ):
if not self._iCnv:
self._iCnv = appuifw.Canvas()
appuifw.app.body = self._iCnv

def _redraw(self, aRect=None):
try:
self._iCnv.clear()
dimentions = self._iCnv.measure_text(self._iEmptyMessage,
font='dense')
width = abs(dimentions[0][0])+abs(dimentions[0][2])
height = abs(dimentions[0][1])+abs(dimentions[0][3])
self._iCnv.text(((self._iCnv.size[0]-width)/2,
(self._iCnv.size[1]-height)/2),
self._iEmptyMessage)
exceptass

def _observer(self):
self._mObserver()

def bind(self, aEventCode, aCallback):
self._iBindings[aEventCode] = aCallback
self._iCnv.bind(aEventCode, aCallback)
if self._iListbox:
self._iListbox.bind(aEventCode, aCallback)

def current(self):
return self._iListbox.current()

def set_list(self, aList, current=None):
self._iList = aList
if self._iList and current:
if not self._iListbox:
self._iListbox = appuifw.Listbox(self._iList, self._observer)
appuifw.app.body = self._iListbox
for key in self._iBindings:
self._iListbox.bind(key, self._iBindings[key])

self._iListbox.set_list( aList, current )

if appuifw.app.body is not self._iListbox:
appuifw.app.body = self._iListbox

elif self._iList and not current:
if not self._iListbox:
self._iListbox = appuifw.Listbox(self._iList, self._observer)
appuifw.app.body = self._iListbox
for key in self._iBindings:
self._iListbox.bind(key, self._iBindings[key])

self._iListbox.set_list( aList )

if appuifw.app.body is not self._iListbox:
appuifw.app.body = self._iListbox

else:
self._showEmpty()




if __name__ == "__main__":
from key_codes import EScancode5
def feed():
lb.set_list([u'Item0',u'Item1',u'Item2',u'Item3',
u'Item4',u'Item5',u'Item6',u'...'],3)
appuifw.app.menu = ([(u'Empty list', lambda:empty(),
(u'Exit', lambda:APP_LOCK.signal()))])

def empty():
lb.set_list([])
appuifw.app.menu = ([(u'Feed list', lambda:feed(),
(u'Exit', lambda:APP_LOCK.signal()))])


def observer():
appuifw.note(u'Index: %d'%(lb.current()), 'info', 1)


APP_LOCK = e32.Ao_lock()
appuifw.app.title = u'Custom listbox'
appuifw.app.exit_key_handler = APP_LOCK.signal
appuifw.app.menu = ([(u'Feed list', lambda:feed(),
(u'Exit', lambda:APP_LOCK.signal()))])

lb = CustomList(aObserver=observer)
lb.bind(EScancode5, lambda:appuifw.note(u'Key 5', 'info', 1))
APP_LOCK.wait()


Thanks in advance.
Reply With Quote

#2 Old Smile Re: How to create an empty listbox, WIKI - 2007-11-29, 09:20

Join Date: Mar 2006
Posts: 6,293
Location: Helsinki, Finland
kiran10182's Avatar
kiran10182
Offline
Forum Nokia Champion
Welcome to the Forum Nokia Discussion Boards.

The article you are referring is in Python. And you are in Symbian C++ category.
I think moderator will move this to an appropriate category.

Now onwards ask Python questions here: http://discussion.forum.nokia.com/fo...play.php?f=102

Kiran.
Reply With Quote

#3 Old Re: How to create an empty listbox, WIKI - 2007-11-29, 13:30

Join Date: Nov 2007
Posts: 10
JereKuusela
Offline
Registered User
Ups :P
Not sure what I was thinking...
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
Full screen listbox skin not rendered correctly template60 General Symbian C++ 2 2007-09-11 05:34
ListBox Errors javadi82 Symbian User Interface 7 2006-11-08 14:29
Query ~ Listbox | functional but no text series60nubee General Symbian C++ 5 2006-03-24 07:09
listbox in multi view / tab problem jmprince80 Symbian User Interface 1 2005-06-17 20:41
Is it necessary to create ListBox in Dialog saurbh_g Symbian User Interface 0 2005-06-10 15:38

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia