Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 4x6_full_buttonlayout_demo.py
- from appuifw import *
- import e32,audio,os,sys,key_codes,time,math,random,graphics,sensor
- RGB_GREEN = (000,255,000)
- RGB_RED = (255,000,000)
- RGB_BLACK = (000,000,000)
- RGB_WHITE = (255,255,255)
- def draw(rect):
- try: canvas.blit(img)
- except: pass
- app.directional_pad = False
- app.orientation='portrait'
- app.screen='large'
- app.body=canvas=Canvas(redraw_callback=draw)
- img=graphics.Image.new(canvas.size)
- Total_x, Total_y = canvas.size
- x=y=90
- yy = Total_y-(y*6) # for bottom layout
- def cv(): pass
- keyb={}
- keyb['num']='''
- 123+
- 456-
- 789*
- .0=/
- $,:%
- ()<>
- '''
- def layout(v):
- z=keyb[v].strip().splitlines()
- for y in range(len(z)):
- for x in range(len(z[y])):
- keyb[(v,x,y)]=z[y][x]
- s=list(keyb)
- for z in s: layout(z)
- def btn_pad(_x,_y,z,c):
- img.text((_x+15,_y+20+y), unicode(z), fill=c,font=(u'Nokia Hindi S60',80,STYLE_BOLD))
- xy = {}
- for _y in range(6):
- for _x in range(4):
- xy[(_x,_y)] = x*_x, y*_y
- for x2,y2 in xy:
- btn_pad(x2*90,y2*90,(keyb[('num',x2,y2)]),RGB_BLACK)
- draw(())
- timer = e32.Ao_timer()
- timer.after(0.2) # delay might be req'd for capture
- num_pad = graphics.screenshot()
- #
- def up_event(event):
- img.blit(num_pad, target=(0,0))
- rbtn(RGB_RED)
- draw(())
- def dn_event(event):
- global prev_xy
- prev_xy=time.time()
- mv_event(event)
- def mv_event(event):
- global Xp,Yp
- x,y=event
- if y > yy: Xp,Yp=x/90,(y-yy)/90
- #
- canvas.bind(key_codes.EButton1Up, up_event, ((x*0,y*0), (Total_x,Total_y)))
- canvas.bind(key_codes.EButton1Down, dn_event, ((x*0,y*0), (Total_x,Total_y)))
- canvas.bind(key_codes.EDrag, mv_event, ((x*0,y*0), (Total_x,Total_y)))
- def exit():
- global process
- process = 0
- #
- app.exit_key_handler=exit
- app_lock=e32.Ao_lock()
- Xp=Yp=None
- prev_xy=None
- def btxt(txt):
- img.text((10,Total_y-15),unicode(txt),font=('normal',20),fill=0)
- def rbtn(c):
- x2,y2=xy[(Xp,Yp)]
- img.rectangle((x2,y2+yy,x2+x,y2+y+yy), fill=c)
- img.text((10,25),unicode((Xp,Yp)),font=('normal',20),fill=0)
- btn_pad(x2,y2,keyb[('num',Xp,Yp)],RGB_WHITE)
- process = 1
- delay = time.time()+0.02
- while process:
- if (Xp,Yp) in xy:
- if (Xp,Yp) <> prev_xy:
- prev_xy=Xp,Yp
- if time.time() > delay:
- #img.clear()
- img.blit(num_pad, target=(0,0))
- rbtn(RGB_GREEN)
- delay = time.time()+0.2
- draw(())
- e32.ao_yield() # bottom of _running_loop_
- """ """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement