Advertisement
here2share

# 4x4_ButtonLayout_demo.py

Nov 29th, 2014
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # 4x4_ButtonLayout_demo.py
  2.  
  3. import appuifw, graphics, e32, key_codes, time
  4.  
  5. RGB_GREEN        = (000,255,000)
  6. RGB_RED          = (255,000,000)
  7. RGB_BLACK        = (000,000,000)
  8.  
  9. appuifw.app.directional_pad = False
  10. appuifw.app.orientation='portrait'
  11. appuifw.app.screen='large'
  12.  
  13. def draw(rect):
  14.     try: canvas.blit(img)
  15.     except: pass
  16.  
  17. appuifw.app.body=canvas=appuifw.Canvas(redraw_callback=draw)
  18. img=graphics.Image.new(canvas.size)
  19.  
  20. Total_x, Total_y = canvas.size
  21. x=y=90
  22. yy = 220 # for bottom layout
  23.  
  24. xy_01 = ((x*0,y*0+yy), (x*1,y*1+yy))
  25. xy_02 = ((x*1,y*0+yy), (x*2,y*1+yy))
  26. xy_03 = ((x*2,y*0+yy), (x*3,y*1+yy))
  27. xy_04 = ((x*3,y*0+yy), (x*4,y*1+yy))
  28. xy_05 = ((x*0,y*1+yy), (x*1,y*2+yy))
  29. xy_06 = ((x*1,y*1+yy), (x*2,y*2+yy))
  30. xy_07 = ((x*2,y*1+yy), (x*3,y*2+yy))
  31. xy_08 = ((x*3,y*1+yy), (x*4,y*2+yy))
  32. xy_09 = ((x*0,y*2+yy), (x*1,y*3+yy))
  33. xy_10 = ((x*1,y*2+yy), (x*2,y*3+yy))
  34. xy_11 = ((x*2,y*2+yy), (x*3,y*3+yy))
  35. xy_12 = ((x*3,y*2+yy), (x*4,y*3+yy))
  36. xy_13 = ((x*0,y*3+yy), (x*1,y*4+yy))
  37. xy_14 = ((x*1,y*3+yy), (x*2,y*4+yy))
  38. xy_15 = ((x*2,y*3+yy), (x*3,y*4+yy))
  39. xy_16 = ((x*3,y*3+yy), (x*4,y*4+yy))
  40.  
  41. def up_event(event):
  42.     global BTN_COLOR
  43.     BTN_COLOR=RGB_RED
  44. def dn_event(event):
  45.     global BTN_COLOR,prev_xy
  46.     BTN_COLOR=RGB_GREEN
  47.     prev_xy=time.time()
  48. canvas.bind(key_codes.EButton1Up, up_event, ((x*0,y*0), (Total_x,Total_y)))
  49. canvas.bind(key_codes.EButton1Down, dn_event, ((x*0,y*0), (Total_x,Total_y)))
  50.  
  51. def box_01(event):
  52.     global xy
  53.     xy=xy_01
  54. def box_02(event):
  55.     global xy
  56.     xy=xy_02
  57. def box_03(event):
  58.     global xy
  59.     xy=xy_03
  60. def box_04(event):
  61.     global xy
  62.     xy=xy_04
  63. def box_05(event):
  64.     global xy
  65.     xy=xy_05
  66. def box_06(event):
  67.     global xy
  68.     xy=xy_06
  69. def box_07(event):
  70.     global xy
  71.     xy=xy_07
  72. def box_08(event):
  73.     global xy
  74.     xy=xy_08
  75. def box_09(event):
  76.     global xy
  77.     xy=xy_09
  78. def box_10(event):
  79.     global xy
  80.     xy=xy_10
  81. def box_11(event):
  82.     global xy
  83.     xy=xy_11
  84. def box_12(event):
  85.     global xy
  86.     xy=xy_12
  87. def box_13(event):
  88.     global xy
  89.     xy=xy_13
  90. def box_14(event):
  91.     global xy
  92.     xy=xy_14
  93. def box_15(event):
  94.     global xy
  95.     xy=xy_15
  96. def box_16(event):
  97.     global xy
  98.     xy=xy_16
  99.  
  100. canvas.bind(key_codes.EDrag, box_01, ((xy_01)))
  101. canvas.bind(key_codes.EDrag, box_02, ((xy_02)))
  102. canvas.bind(key_codes.EDrag, box_03, ((xy_03)))
  103. canvas.bind(key_codes.EDrag, box_04, ((xy_04)))
  104. canvas.bind(key_codes.EDrag, box_05, ((xy_05)))
  105. canvas.bind(key_codes.EDrag, box_06, ((xy_06)))
  106. canvas.bind(key_codes.EDrag, box_07, ((xy_07)))
  107. canvas.bind(key_codes.EDrag, box_08, ((xy_08)))
  108. canvas.bind(key_codes.EDrag, box_09, ((xy_09)))
  109. canvas.bind(key_codes.EDrag, box_10, ((xy_10)))
  110. canvas.bind(key_codes.EDrag, box_11, ((xy_11)))
  111. canvas.bind(key_codes.EDrag, box_12, ((xy_12)))
  112. canvas.bind(key_codes.EDrag, box_13, ((xy_13)))
  113. canvas.bind(key_codes.EDrag, box_14, ((xy_14)))
  114. canvas.bind(key_codes.EDrag, box_15, ((xy_15)))
  115. canvas.bind(key_codes.EDrag, box_16, ((xy_16)))
  116.  
  117. def exit():
  118.     global process
  119.     process = 0
  120.  
  121. appuifw.app.exit_key_handler=exit
  122. app_lock=e32.Ao_lock()
  123. xy     =xy_16
  124. prev_xy=None
  125.  
  126. BTN_COLOR=RGB_RED
  127.  
  128. process = 1
  129. while process:
  130.  
  131.     if xy <> prev_xy or BTN_COLOR <> RGB_GREEN:
  132.         prev_xy=xy
  133.         img.clear()
  134.         img.rectangle(((xy)), fill=BTN_COLOR, width=5)
  135.         draw(())
  136.         BTN_COLOR=RGB_GREEN
  137.  
  138.     e32.ao_yield() # bottom of _running_loop_
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement