Advertisement
phjoe

Multiselect Checkbox

Dec 8th, 2014
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # multiselect checkbox
  2. import appuifw as A
  3. import graphics as G
  4.  
  5. run=1
  6. def exit():
  7.  global run
  8.  run=0
  9. A.app.exit_key_handler=exit
  10. img=G.Image.new(G.sysinfo.display_pixels())
  11.  
  12. class CSelect:
  13.  def __init__(self,items=[]):
  14.   self.cur=0
  15.   self.items=items
  16.   self.tmp=[]
  17.   self.c = A.Canvas(redraw_callback=self.redraw)
  18.   A.app.screen='full'
  19.   A.app.body=self.c
  20.  
  21.  def redraw(self,rect):
  22.   if img:
  23.    self.c.blit(img)
  24.  
  25.  def down(self):
  26.   self.cur+=1
  27.   if self.cur>len(self.items)-1:
  28.    self.cur=0
  29.  
  30.  def up(self):
  31.   self.cur-=1
  32.   if self.cur<0:
  33.    self.cur=len(self.items)-1
  34.  
  35.  def select(self):
  36.   if self.cur not in self.tmp:
  37.    self.tmp.append(self.cur)
  38.   else:
  39.    self.tmp.remove(self.cur)
  40.  
  41.  def show(self):
  42.   self.c.bind(63497,self.up)
  43.   self.c.bind(63498,self.down)
  44.   self.c.bind(63557,self.select)
  45.   px,py,th=20,20,14
  46.   while run:
  47.    img.clear(0)
  48.    for i in range(len(self.items)):
  49.     tc=(0xffffff,0x00ff00)[i==self.cur]
  50.     fc=(None,0x00ff00)[i in self.tmp]
  51.     img.text((px,py+(i*th)),self.items[i],tc,'legend')
  52.     img.rectangle((px-15,py+(i*th)-10,px-5,py+(i*th)),0xdadada)
  53.     img.rectangle((px-14,py+(i*th)-9,px-6,py+(i*th)-1),fill=fc)
  54.    img.text((px,160),u'Multiselect Test - Joe',0xdadada)
  55.    img.text((px,180),u'Sel: %s' %repr(self.tmp),0xdadada)
  56.    self.c.blit(img)
  57.    A.e32.ao_sleep(1E-08)
  58.  
  59. menu=[u'Item 1',u'Item 2',u'Item 3',u'Item 4',u'Item 5',u'Item 6']
  60. kk=CSelect(menu)
  61. kk.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement