Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 4x4_ButtonLayout_demo.py
- import appuifw, graphics, e32, key_codes, time
- RGB_GREEN = (000,255,000)
- RGB_RED = (255,000,000)
- RGB_BLACK = (000,000,000)
- appuifw.app.directional_pad = False
- appuifw.app.orientation='portrait'
- appuifw.app.screen='large'
- def draw(rect):
- try: canvas.blit(img)
- except: pass
- appuifw.app.body=canvas=appuifw.Canvas(redraw_callback=draw)
- img=graphics.Image.new(canvas.size)
- Total_x, Total_y = canvas.size
- x=y=90
- yy = 220 # for bottom layout
- xy_01 = ((x*0,y*0+yy), (x*1,y*1+yy))
- xy_02 = ((x*1,y*0+yy), (x*2,y*1+yy))
- xy_03 = ((x*2,y*0+yy), (x*3,y*1+yy))
- xy_04 = ((x*3,y*0+yy), (x*4,y*1+yy))
- xy_05 = ((x*0,y*1+yy), (x*1,y*2+yy))
- xy_06 = ((x*1,y*1+yy), (x*2,y*2+yy))
- xy_07 = ((x*2,y*1+yy), (x*3,y*2+yy))
- xy_08 = ((x*3,y*1+yy), (x*4,y*2+yy))
- xy_09 = ((x*0,y*2+yy), (x*1,y*3+yy))
- xy_10 = ((x*1,y*2+yy), (x*2,y*3+yy))
- xy_11 = ((x*2,y*2+yy), (x*3,y*3+yy))
- xy_12 = ((x*3,y*2+yy), (x*4,y*3+yy))
- xy_13 = ((x*0,y*3+yy), (x*1,y*4+yy))
- xy_14 = ((x*1,y*3+yy), (x*2,y*4+yy))
- xy_15 = ((x*2,y*3+yy), (x*3,y*4+yy))
- xy_16 = ((x*3,y*3+yy), (x*4,y*4+yy))
- def up_event(event):
- global BTN_COLOR
- BTN_COLOR=RGB_RED
- def dn_event(event):
- global BTN_COLOR,prev_xy
- BTN_COLOR=RGB_GREEN
- prev_xy=time.time()
- canvas.bind(key_codes.EButton1Up, up_event, ((x*0,y*0), (Total_x,Total_y)))
- canvas.bind(key_codes.EButton1Down, dn_event, ((x*0,y*0), (Total_x,Total_y)))
- def box_01(event):
- global xy
- xy=xy_01
- def box_02(event):
- global xy
- xy=xy_02
- def box_03(event):
- global xy
- xy=xy_03
- def box_04(event):
- global xy
- xy=xy_04
- def box_05(event):
- global xy
- xy=xy_05
- def box_06(event):
- global xy
- xy=xy_06
- def box_07(event):
- global xy
- xy=xy_07
- def box_08(event):
- global xy
- xy=xy_08
- def box_09(event):
- global xy
- xy=xy_09
- def box_10(event):
- global xy
- xy=xy_10
- def box_11(event):
- global xy
- xy=xy_11
- def box_12(event):
- global xy
- xy=xy_12
- def box_13(event):
- global xy
- xy=xy_13
- def box_14(event):
- global xy
- xy=xy_14
- def box_15(event):
- global xy
- xy=xy_15
- def box_16(event):
- global xy
- xy=xy_16
- canvas.bind(key_codes.EDrag, box_01, ((xy_01)))
- canvas.bind(key_codes.EDrag, box_02, ((xy_02)))
- canvas.bind(key_codes.EDrag, box_03, ((xy_03)))
- canvas.bind(key_codes.EDrag, box_04, ((xy_04)))
- canvas.bind(key_codes.EDrag, box_05, ((xy_05)))
- canvas.bind(key_codes.EDrag, box_06, ((xy_06)))
- canvas.bind(key_codes.EDrag, box_07, ((xy_07)))
- canvas.bind(key_codes.EDrag, box_08, ((xy_08)))
- canvas.bind(key_codes.EDrag, box_09, ((xy_09)))
- canvas.bind(key_codes.EDrag, box_10, ((xy_10)))
- canvas.bind(key_codes.EDrag, box_11, ((xy_11)))
- canvas.bind(key_codes.EDrag, box_12, ((xy_12)))
- canvas.bind(key_codes.EDrag, box_13, ((xy_13)))
- canvas.bind(key_codes.EDrag, box_14, ((xy_14)))
- canvas.bind(key_codes.EDrag, box_15, ((xy_15)))
- canvas.bind(key_codes.EDrag, box_16, ((xy_16)))
- def exit():
- global process
- process = 0
- appuifw.app.exit_key_handler=exit
- app_lock=e32.Ao_lock()
- xy =xy_16
- prev_xy=None
- BTN_COLOR=RGB_RED
- process = 1
- while process:
- if xy <> prev_xy or BTN_COLOR <> RGB_GREEN:
- prev_xy=xy
- img.clear()
- img.rectangle(((xy)), fill=BTN_COLOR, width=5)
- draw(())
- BTN_COLOR=RGB_GREEN
- e32.ao_yield() # bottom of _running_loop_
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement