Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
This page was last modified 22:30, 12 October 2007.

How to create an empty listbox

From Forum Nokia Wiki


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()
Related Discussions
Thread Thread Starter Forum Replies Last Post
Icons in the Listbox... jayshahce Symbian User Interface 2 2008-05-13 09:01
empty square on xhtml thanray Browsing and Mark-ups 4 2006-05-31 16:00
Get the chosen colour from the actice theme? Megamack General Symbian C++ 4 2004-04-29 09:51
Listbox...my dear listbox!! letiziad General Symbian C++ 6 2006-11-06 15:19
How to create Numeric Editor in ListBox.. revasenthil General Symbian C++ 6 2008-01-05 18:21
 
Powered by MediaWiki
RDF Facets: qfnZtopicQUqfnTopicZpythonQ qfnZtopicQUqfnTopicZseriesE5f60Q qfnZtypeQUqfnTypeZCommunityContentQ qfnZtypeQUqfnTypeZWebpageQ qfnZtypeQUqfnTypeZWikiContentQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX