Advertisement
here2share

# touch_draw_demo.py

Dec 24th, 2014
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # touch_drawing.py
  2.  
  3. import appuifw, e32, graphics, key_codes, time
  4.  
  5. def cv(): pass
  6.  
  7. cv.x=0
  8. cv.y=0
  9. cv.color=(255,0,0)
  10. thickness=5
  11. cv.jot=-10,-10,-10,-10
  12. cv.t=0
  13.  
  14. if not appuifw.touch_enabled():
  15.     appuifw.note(u"This application only works on devices that support touch input")
  16.  
  17. def e_callback(event):
  18.     x=event['pos'][0]
  19.     y=event['pos'][1]
  20.     if not event['type'] in [key_codes.EButton1Up, key_codes.EButton1Down, key_codes.EDrag]:
  21.         return
  22.     if event['type'] == key_codes.EButton1Down:
  23.         cv.x=x
  24.         cv.y=y
  25.     elif event['type'] == key_codes.EDrag:
  26.         if cv.t < time.time():
  27.             cv.t=time.time()+0.04
  28.             cv.jot=(x, y, cv.x, cv.y)
  29.             cv.x=x
  30.             cv.y=y
  31.             draw(())
  32.  
  33. def draw(rect):
  34.     canvas.line(cv.jot, outline=cv.color, width=thickness, fill=cv.color)
  35.    
  36.    
  37. def quit():
  38.     script_lock.signal()
  39.  
  40. canvas=appuifw.Canvas(event_callback=e_callback, redraw_callback=draw)
  41. appuifw.app.directional_pad=False
  42. appuifw.app.orientation='portrait'
  43. appuifw.app.screen='large'
  44. appuifw.app.body=canvas
  45. w,h=canvas.size
  46. img=graphics.Image.new((w,h))
  47.  
  48. canvas.clear()
  49. draw(())
  50.  
  51. print 12345
  52. appuifw.app.exit_key_handler=quit
  53. script_lock=e32.Ao_lock()
  54. script_lock.wait()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement