Advertisement
here2share

# full_buttonlayout_demo.py

Feb 29th, 2016
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # buttonlayout_demo.py
  2.  
  3. RGB_GREEN       = (000,255,000)
  4. RGB_RED         = (255,000,000)
  5. RGB_BLACK       = (000,000,000)
  6. RGB_WHITE       = (255,255,255)
  7. RGB_GRAY        = (128,128,128)
  8.  
  9. from appuifw import *
  10. from graphics import *
  11. import e32,audio,appuifw,os,sys,key_codes,time,math,random,graphics,sensor
  12.  
  13. running=1
  14. def quit():
  15.     global running
  16.     running=0
  17. app.exit_key_handler=quit
  18.  
  19. def draw(rect):
  20.     try: canvas.blit(img)
  21.     except: pass
  22.  
  23. img=None
  24. app.screen='large'
  25. app.orientation='portrait'
  26. app.directional_pad=False
  27. app.body=canvas=Canvas(redraw_callback=draw)
  28. img=Image.new(canvas.size)
  29.  
  30. Total_x, Total_y=canvas.size
  31.  
  32. def cv(): pass
  33. cv.t=0
  34. x=y=90
  35. cv.xy=((x*0,y*0,x*1,y*1))
  36. cv.padx,cv.pady=5,75
  37.  
  38. def up_event(event):
  39.     btn_rpl(cv.xy,cv.btn99,RGB_RED,RGB_WHITE)
  40.     draw(())
  41. def dn_event(event):
  42.     pass
  43. canvas.bind(key_codes.EButton1Up, up_event, ((0,0), (Total_x,Total_y)))
  44. canvas.bind(key_codes.EButton1Down, dn_event, ((0,0), (Total_x,Total_y)))
  45.  
  46. xx=yy=0
  47. scr_yy=38 # set for lg
  48.  
  49. def mv_event(event):
  50.     jx=abs(event[0])/90
  51.     jy=abs(event[1])/90
  52.     cv.btn99=jx+(jy*4)+1
  53.     cv.xy=((x*jx,y*jy,x*(jx+1),y*(jy+1)))
  54. canvas.bind(key_codes.EDrag, mv_event, ((0,0), (Total_x,Total_y)))
  55.  
  56. def btn_pad(xx=4,yy=7):
  57.     for y2 in range(yy):
  58.         for x2 in range(xx):
  59.             img.text((x2*x+cv.padx,y2*y+cv.pady+scr_yy), unicode(x2+(y2*4)+1), fill=RGB_GRAY,font=(u'Nokia Hindi S60',80,STYLE_BOLD))
  60. def btn_rpl(target,btn_99,sq=RGB_WHITE,btn_label=RGB_GRAY):
  61.     inbtn=target[0]+cv.padx,target[1]+cv.pady+scr_yy
  62.     a,b,c,d=target
  63.     img.rectangle((a,b+scr_yy,c,d+scr_yy), fill=sq, width=5)
  64.     img.text((inbtn), unicode(btn_99), fill=btn_label,font=(u'Nokia Hindi S60',80,STYLE_BOLD))
  65. #
  66. def exit():
  67.     global process
  68.     process=0
  69.     app_lock.signal()
  70. app.exit_key_handler=exit
  71. app_lock=e32.Ao_lock()
  72.  
  73. img.clear()
  74. btn_pad()
  75. btn_rpl((0,0,x,y),1,RGB_RED,RGB_WHITE)
  76. draw(())
  77.  
  78. prev_xy=cv.xy
  79. prev_btn99=1
  80.  
  81. process=1
  82. while process:
  83.     if cv.xy <> prev_xy:
  84.         btn_rpl(prev_xy,prev_btn99)
  85.         btn_rpl(cv.xy,cv.btn99,RGB_GREEN,RGB_BLACK)
  86.         prev_xy=cv.xy
  87.         prev_btn99=cv.btn99
  88.         draw(())
  89.     e32.ao_yield() # bottom of _running_loop_'''
  90.  
  91. app_lock.wait()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement