Advertisement
here2share

# pie_slicer_demo.py ZZZ

Apr 15th, 2016
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # pie_slicer_demo.py ZZZ
  2.  
  3. import appuifw, e32, graphics, key_codes, time
  4.  
  5. def draw(rect):
  6.     try: canvas.blit(img)
  7.     except: pass
  8.  
  9. canvas = appuifw.Canvas(redraw_callback=draw)
  10. appuifw.app.directional_pad=False
  11. appuifw.app.orientation='portrait'
  12. appuifw.app.screen='large'
  13. appuifw.app.body=canvas
  14. w,h = canvas.size
  15. img=graphics.Image.new((w,h))
  16.  
  17. #
  18. def up_event(event):
  19.     cv.up=-1
  20. def dn_event(event):
  21.     cv.up=0
  22. #
  23. def mv_event(event):
  24.     cv.x=event[0]
  25.     cv.y=event[1]
  26.     cv.xy=cv.x/360,cv.y/yy2
  27.     if time.time() > cv.up:
  28.         exec ('s.'+cv.val+'+='+str(incr[cv.xy[1]]))
  29.         cv.up=time.time()+0.5
  30.  
  31. x_scr=360
  32. def full_bind():
  33.     canvas.bind(key_codes.EButton1Up, up_event, ((0,0), (x_scr,720)))
  34.     canvas.bind(key_codes.EButton1Down, dn_event, ((0,0), (x_scr,720)))
  35.     canvas.bind(key_codes.EDrag, mv_event, ((0,0), (x_scr,720)))
  36. full_bind()
  37.  
  38. def radian(d):
  39.     return d*3.14/180.0
  40.  
  41. class sval:
  42.     x,y=20,60; rx,ry=90,180
  43.     x2=y2=300
  44.     xyt=rxy=0
  45.     xyz=0,0,0
  46.     up=-1
  47.     t=0
  48.     xy=0,0
  49.     val='rx'
  50. s=sval()
  51.  
  52. def gbr():
  53.     plots=(s.x, s.y, s.x+s.x2+s.xyt, s.y+s.y2+s.xyt)
  54.     img.pieslice(plots, radian(180-s.rx+s.rxy),radian(180-s.ry+s.rxy), outline=0xfff,fill=0x00ff00,width=10)
  55.     img.text((10,20),u''+str(plots),0xffffff)
  56.     img.text((10,40),u''+str((s.rx+s.rxy,+s.ry+s.rxy)),0xffffff)
  57. #
  58. def ruler():
  59.     yy=0
  60.     img.rectangle(((350-6,0), (358+2,640)), fill=(128,128,0))
  61.     img.rectangle(((350,0), (358,640)), fill=(0,0,0))
  62.     for ssVyy in xrange(0,9,2):
  63.         yy=yy2*ssVyy+2
  64.         img.rectangle(((350,yy), (358,yy+yy2)), fill=(255,255,255))
  65. #
  66. def z_tools():
  67.     index=appuifw.popup_menu(tools,u'*** Select Tool ***')
  68.     cv.val=tool_val[index]
  69. def clear_screen():
  70.      img.clear()
  71.      appuifw.note(u'Clear text on screen','info')
  72. #
  73. appuifw.app.menu=[(u'Select Tool',z_tools),(u'clear screen',clear_screen)]
  74. tools=[u'x move',u'y move',u'x scale',u'y scale',u'x+y scale',u'slice',u'rotate']
  75. tool_val=u'x y x2 y2 rx ry xyt rxy'.split()
  76. tools=tool_val
  77.  
  78. class cvs:
  79.     x=360
  80.     y=0
  81.     xy=0,4
  82.     up=-1
  83.     val='rx'
  84. cv=cvs()
  85.  
  86. lg_scr = 576
  87. sVy = 9.0/lg_scr
  88. incr=[30,10,5,1,0,-1,-5,-10,-30]
  89. yy2=lg_scr/9
  90.  
  91. run=1
  92. def quit():
  93.   global run
  94.   run=0
  95. appuifw.app.exit_key_handler=quit
  96.  
  97. while run:
  98.     if cv.x > 300:
  99.         img.clear(0x3b3b3b)
  100.         gbr()
  101.         ruler()
  102.         draw(())
  103.         cv.x=0
  104.     e32.ao_sleep(0.05)
  105. #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement