×
Namespaces

Variants
Actions

Archived:How to create an empty listbox using PySymbian

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngAquivado: Este artigo foi arquivado, pois o conteúdo não é mais considerado relevante para se criar soluções comerciais atuais. Se você achar que este artigo ainda é importante, inclua o template {{ForArchiveReview|escreva a sua justificativa}}.

All PySymbian articles have been archived. PySymbian is no longer maintained by Nokia and is not guaranteed to work on more recent Symbian devices. It is not possible to submit apps to Nokia Store.

Article Metadata
Article
Created: lfd (24 Jul 2007)
Last edited: hamishwillee (31 May 2013)

Here is the source:

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)
except:pass
 
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()
This page was last modified on 31 May 2013, at 04:08.
51 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×