×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Regular Contributor
    Join Date
    Jul 2009
    Posts
    101

    redefining exit_key_handler

    I have a class with two levels of listboxes. The first level is a list of categories and the second is a list of items in each category. When you are in the first level, you can choose a category and up comes a listbox with the relevant items.

    I'd like to set exit_key_handler so that it exits the program when in level 1 and returns to level 1 when in level 2.

    Each level is created with functions in the class. I switch between the levels with an 'app.body = self.LB1' or ' = LB2' statement, where LB = Listbox(...) as approprite.

    Setting exit_key_handler = lock.signal works fine to exit the program.

    However when I try to set exit_key_handler in level 2 to show the level 1 listbox, I get a syntax error. For example, app.exit_key_handler = self.show_level_1 results in "NameError: name 'self' is not defined". This is odd, as app.menu = [(u'Items', self.show_level_1)] works fine.

    I'm using 1.9.6 and the emulator, if that matters. All else is working properly, including setting menus, displaying lists, etc.

  2. #2
    Regular Contributor
    Join Date
    Jul 2009
    Posts
    101

    Re: redefining exit_key_handler

    I'm not sure what I was doing wrong, but when I tried to create a simple example, it worked:

    Code:
    from appuifw import *
    import e32
    
    class lbfun:
    
    	def __init__(self):
    
    		self.categories = [u'Pets', u'Colors']
    		self.listcats()
    		self.where= 'cat'
    
    	def listcats(self):
    		self.catslb = Listbox(self.categories, self.choosecat)
    		app.body = self.catslb
    		app.menu = [(u'Choose category', self.choosecat)]
    		self.where = 'cat'
    
    	def choosecat(self):
    		currentcat = self.catslb.current()
    		if currentcat == 0:
    			self.items = [u'cats', u'dogs', u'goldfish']
    		if currentcat == 1:
    			self.items = [u'red', u'blue', u'green']
    		self.itemslb = Listbox(self.items, self.itemfunc)
    		app.body = self.itemslb
    		app.menu = [(u'Show', self.itemfunc)]
    		self.where = 'item'
    
    	def itemfunc(self):
    		pos = self.itemslb.current()
    		note(u'%s' % self.items[pos])
    
    	def exit_hand(self):
    		if self.where == 'cat':
    			lock.signal()
    		elif self.where == 'item':
    			self.listcats()
    
    
    x = lbfun()
    lock = e32.Ao_lock()
    app.exit_key_handler = x.exit_hand
    lock.wait()

Posting Permissions

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