Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # buttonlayout_demo.py
- RGB_GREEN = (000,255,000)
- RGB_RED = (255,000,000)
- RGB_BLACK = (000,000,000)
- RGB_WHITE = (255,255,255)
- RGB_GRAY = (128,128,128)
- from appuifw import *
- from graphics import *
- import e32,audio,appuifw,os,sys,key_codes,time,math,random,graphics,sensor
- running=1
- def quit():
- global running
- running=0
- app.exit_key_handler=quit
- def draw(rect):
- try: canvas.blit(img)
- except: pass
- img=None
- app.screen='large'
- app.orientation='portrait'
- app.directional_pad=False
- app.body=canvas=Canvas(redraw_callback=draw)
- img=Image.new(canvas.size)
- Total_x, Total_y=canvas.size
- def cv(): pass
- cv.t=0
- x=y=90
- cv.xy=((x*0,y*0,x*1,y*1))
- cv.padx,cv.pady=5,75
- def up_event(event):
- btn_rpl(cv.xy,cv.btn99,RGB_RED,RGB_WHITE)
- draw(())
- def dn_event(event):
- pass
- canvas.bind(key_codes.EButton1Up, up_event, ((0,0), (Total_x,Total_y)))
- canvas.bind(key_codes.EButton1Down, dn_event, ((0,0), (Total_x,Total_y)))
- xx=yy=0
- scr_yy=38 # set for lg
- def mv_event(event):
- jx=abs(event[0])/90
- jy=abs(event[1])/90
- cv.btn99=jx+(jy*4)+1
- cv.xy=((x*jx,y*jy,x*(jx+1),y*(jy+1)))
- canvas.bind(key_codes.EDrag, mv_event, ((0,0), (Total_x,Total_y)))
- def btn_pad(xx=4,yy=7):
- for y2 in range(yy):
- for x2 in range(xx):
- img.text((x2*x+cv.padx,y2*y+cv.pady+scr_yy), unicode(x2+(y2*4)+1), fill=RGB_GRAY,font=(u'Nokia Hindi S60',80,STYLE_BOLD))
- def btn_rpl(target,btn_99,sq=RGB_WHITE,btn_label=RGB_GRAY):
- inbtn=target[0]+cv.padx,target[1]+cv.pady+scr_yy
- a,b,c,d=target
- img.rectangle((a,b+scr_yy,c,d+scr_yy), fill=sq, width=5)
- img.text((inbtn), unicode(btn_99), fill=btn_label,font=(u'Nokia Hindi S60',80,STYLE_BOLD))
- #
- def exit():
- global process
- process=0
- app_lock.signal()
- app.exit_key_handler=exit
- app_lock=e32.Ao_lock()
- img.clear()
- btn_pad()
- btn_rpl((0,0,x,y),1,RGB_RED,RGB_WHITE)
- draw(())
- prev_xy=cv.xy
- prev_btn99=1
- process=1
- while process:
- if cv.xy <> prev_xy:
- btn_rpl(prev_xy,prev_btn99)
- btn_rpl(cv.xy,cv.btn99,RGB_GREEN,RGB_BLACK)
- prev_xy=cv.xy
- prev_btn99=cv.btn99
- draw(())
- e32.ao_yield() # bottom of _running_loop_'''
- app_lock.wait()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement