Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # incr_slider_demo.py
- from appuifw import *
- import e32,audio,appuifw,os,sys,key_codes,time,math,random,graphics,sensor,copy
- from graphics import *
- # define colour constants
- RGB_RED = (255, 0, 0)
- RGB_GREEN = (0, 255, 0)
- RGB_BLUE = (0, 0, 255)
- RGB_BLACK = (0,0,0)
- RGB_WHITE = (255,255,255)
- RGB_GREY = (128,128,128)
- def draw(rect):
- if img:
- canvas.blit(img)
- rainbow=[]
- def z(r,g,b):
- rainbow.append((r,g,b))
- r,g,b=255,0,0
- for g in range(256):
- z(r,g,b)
- for r in range(254, -1, -1):
- z(r,g,b)
- for b in range(256):
- z(r,g,b)
- for g in range(254, -1, -1):
- z(r,g,b)
- for r in range(256):
- z(r,g,b)
- for b in range(254, -1, -1):
- z(r,g,b)
- max_rgb=len(rainbow)-1
- running = 1
- def quit():
- global running
- timer.cancel()
- running = 0
- app.exit_key_handler = quit
- def e_callback(event):
- global pixel,timer,ss,yo,t
- try:
- pixel = event['pos']
- except : print 'err'
- try: timer.cancel()
- except: pass
- timer.after(1,zero)
- try:
- if t < time.time():
- yo=increment[int(pixel[1]*sVy)]
- ss+=yo
- except:
- yo=increment[int(pixel[1]*sVy)]
- ss+=yo
- img=None
- app.screen = 'large'
- app.orientation = 'portrait'
- app.directional_pad = False
- app.body = canvas = Canvas(redraw_callback=draw, event_callback=e_callback) #
- buf = Image.new(canvas.size)
- res_x, res_y = canvas.size
- timer = e32.Ao_timer()
- #obtaining canvas size (Total_x and Total_y)
- res_x, res_y = 360,576
- sVy = 9.0/res_y
- increment=[100,50,10,1,0,-1,-10,-50,-100]
- buf.clear(RGB_GREY)
- BorW=[RGB_WHITE,RGB_BLACK]
- yy2=res_y/9
- for ssVyy in xrange(0,9):
- yy=yy2*ssVyy+2
- WvB=BorW[0]
- BorW[0],BorW[1]=BorW[1],BorW[0]
- buf.rectangle(((350,yy), (358,yy+yy2)), fill=WvB)
- img=copy.copy(buf)
- draw(())
- #
- buf.text((10,44), u"Color:", fill = RGB_BLACK,font=(u'Nokia Hindi S60',40,STYLE_BOLD))
- ss=max_rgb
- pixel=None
- yo=0
- prev_ss=None
- tt=''
- def zero():
- global yo
- yo=0
- def layout():
- global yo
- yo=0
- while running:
- if ss < 0: ss += max_rgb
- if ss > max_rgb: ss -= max_rgb
- if yo <> None:
- buf.text((10,90), unicode(tt), fill = RGB_GREY,font=(u'Nokia Hindi S60',30,STYLE_BOLD))
- tt=str(rainbow[ss])+' : '+str(yo)
- buf.rectangle(((120,2), (348,50)), fill=rainbow[ss])
- buf.text((10,90), unicode(tt), fill = RGB_BLACK,font=(u'Nokia Hindi S60',30,STYLE_BOLD))
- img=copy.copy(buf)
- if yo <> 0:
- t=time.time()+0.3
- draw(())
- yo=None
- e32.ao_yield()
- #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement