# AppKill - frontend for the appswitch module
# (c) Goetz Schwandtner 12-2006

import appuifw, e32
import appswitch

class AppKill(object):
    def __init__(self):
        self.showall = False
        appuifw.app.title = u'AppKill (c) G.Schwandtner'
	self.appl = list(appswitch.application_list(self.showall))
	self.lb = appuifw.Listbox(self.appl,self.switch_to)
	appuifw.app.menu=[(u'kill app',self.kill_app),(u'about',self.about),(u'toggle hidden',self.toggle_hidden),(u'refresh',self.refresh)]
	appuifw.app.body=self.lb
	appuifw.app.exit_key_handler=self.quit
	self.lock=e32.Ao_lock()
	self.lock.wait()
    def about(self):
        appuifw.note(u'(c) 2006 Goetz Schwandtner')
    def refresh(self):
    	self.appl=list(appswitch.application_list(self.showall))
	self.lb.set_list(self.appl)
    def cur_app(self):
	return self.appl[self.lb.current()]
    def switch_to(self):
	appswitch.switch_to_fg(self.cur_app())
    def kill_app(self):
	appswitch.kill_app(self.cur_app())
	self.refresh()
    def toggle_hidden(self):
	self.showall = not self.showall
	self.refresh()
    def quit(self):
	self.lock.signal()
	appuifw.app.set_exit()
    
if __name__ == '__main__':
    ak=AppKill()
