Advertisement
here2share

# incr_slider_demo.py

Jan 3rd, 2015
397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # incr_slider_demo.py
  2.  
  3. from appuifw import *
  4. import e32,audio,appuifw,os,sys,key_codes,time,math,random,graphics,sensor,copy
  5. from graphics import *
  6.  
  7. # define colour constants
  8. RGB_RED = (255, 0, 0)
  9. RGB_GREEN = (0, 255, 0)
  10. RGB_BLUE = (0, 0, 255)
  11. RGB_BLACK = (0,0,0)
  12. RGB_WHITE = (255,255,255)
  13. RGB_GREY = (128,128,128)
  14.  
  15. def draw(rect):
  16.     if img:
  17.         canvas.blit(img)
  18.  
  19. rainbow=[]
  20. def z(r,g,b):
  21.     rainbow.append((r,g,b))
  22. r,g,b=255,0,0
  23. for g in range(256):
  24.     z(r,g,b)
  25. for r in range(254, -1, -1):
  26.     z(r,g,b)
  27. for b in range(256):
  28.     z(r,g,b)
  29. for g in range(254, -1, -1):
  30.     z(r,g,b)
  31. for r in range(256):
  32.     z(r,g,b)
  33. for b in range(254, -1, -1):
  34.     z(r,g,b)
  35. max_rgb=len(rainbow)-1
  36.  
  37. running = 1
  38. def quit():
  39.     global running
  40.     timer.cancel()
  41.     running = 0
  42. app.exit_key_handler = quit
  43.  
  44.  
  45. def e_callback(event):
  46.     global pixel,timer,ss,yo,t
  47.     try:
  48.         pixel = event['pos']
  49.     except : print 'err'
  50.     try: timer.cancel()
  51.     except: pass
  52.     timer.after(1,zero)
  53.     try:
  54.         if t < time.time():
  55.             yo=increment[int(pixel[1]*sVy)]
  56.             ss+=yo
  57.     except:
  58.         yo=increment[int(pixel[1]*sVy)]
  59.         ss+=yo
  60.  
  61. img=None
  62. app.screen = 'large'
  63. app.orientation = 'portrait'
  64. app.directional_pad = False
  65. app.body = canvas = Canvas(redraw_callback=draw, event_callback=e_callback) #
  66. buf = Image.new(canvas.size)
  67. res_x, res_y = canvas.size
  68.  
  69. timer = e32.Ao_timer()
  70.  
  71. #obtaining canvas size (Total_x and Total_y)
  72. res_x, res_y = 360,576
  73. sVy = 9.0/res_y
  74.  
  75. increment=[100,50,10,1,0,-1,-10,-50,-100]
  76.  
  77. buf.clear(RGB_GREY)
  78. BorW=[RGB_WHITE,RGB_BLACK]
  79. yy2=res_y/9
  80. for ssVyy in xrange(0,9):
  81.     yy=yy2*ssVyy+2
  82.     WvB=BorW[0]
  83.     BorW[0],BorW[1]=BorW[1],BorW[0]
  84.     buf.rectangle(((350,yy), (358,yy+yy2)), fill=WvB)
  85.     img=copy.copy(buf)
  86.     draw(())
  87. #
  88.  
  89. buf.text((10,44), u"Color:", fill = RGB_BLACK,font=(u'Nokia Hindi S60',40,STYLE_BOLD))  
  90. ss=max_rgb
  91. pixel=None
  92. yo=0
  93. prev_ss=None
  94. tt=''
  95.  
  96. def zero():
  97.     global yo
  98.     yo=0
  99.  
  100. def layout():
  101.     global yo
  102.     yo=0
  103.  
  104. while running:
  105.     if ss < 0: ss += max_rgb
  106.     if ss > max_rgb: ss -= max_rgb
  107.     if yo <> None:
  108.         buf.text((10,90), unicode(tt), fill = RGB_GREY,font=(u'Nokia Hindi S60',30,STYLE_BOLD))
  109.         tt=str(rainbow[ss])+' : '+str(yo)
  110.         buf.rectangle(((120,2), (348,50)), fill=rainbow[ss])
  111.         buf.text((10,90), unicode(tt), fill = RGB_BLACK,font=(u'Nokia Hindi S60',30,STYLE_BOLD))
  112.         img=copy.copy(buf)
  113.         if yo <> 0:
  114.             t=time.time()+0.3
  115.         draw(())
  116.     yo=None
  117.     e32.ao_yield()
  118. #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement