Advertisement
gauravssnl

Canvas.py

Nov 26th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. #this script draws different shapes and text to canvas
  2. import appuifw
  3. from appuifw import*
  4. import e32
  5. #import graphics
  6. from graphics import*
  7.  
  8. #create an exit handler
  9. def quit():
  10.     global running
  11.     running =0
  12.     appuifw.app.set_exit()
  13.    
  14. #set the screen size to large
  15. appuifw.app.screen="large"
  16. #define an intial image(white)
  17. img=Image.new((176,208))
  18. #add different shapes and text to the Image
  19. #coord. Sequence x1,x2,y1,y2
  20. img.line((20,20,20,120),0xff00e)
  21. img.rectangle((40,60,50,80),0xff0000)
  22. img.point((50,150),0xff0000,width=40)
  23. img.ellipse((100,150,150,180),0x0000ff)
  24. img.text((100,80),u'Gaurav')
  25.  
  26. #define your redraw function (that redraws the picture on and on)
  27. #in this case we redraw the image named img using blit function
  28. def handle_redraw(rect):
  29.     canvas.blit(img)
  30.  
  31. running=1
  32.  
  33. #define canvas,include the redraw callback function
  34. canvas=appuifw.Canvas(event_callback=None,redraw_callback=handle_redraw)    
  35. #set the appbody to canvas
  36. appuifw.app.body=canvas
  37. appuifw.exit_handler=quit
  38.  
  39. while running:
  40.     #redraw the screen
  41.     handle_redraw()
  42.     #yield need to be here in order that key pressing can be noticed
  43.     e32.ao_yield()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement