Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Hex Color Viewer
- # Joe, 29/07/2015
- import appuifw as A
- import graphics as G
- sc=G.sysinfo.display_pixels()
- img=G.Image.new(sc)
- def _tsize(text,font):
- if not isinstance(text, unicode):
- text=unicode(text)
- (a,b,c)=img.measure_text(text, font=font)
- w,h=(a[2]-a[0],a[3]-a[1])
- return (w,h)
- class Color:
- def __init__(self):
- self.run=0
- self.val=[48]*6
- self.hval=[48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 97, 98, 99, 100, 101, 102]
- self.curx=0
- self.yy=[0]*len(self.hval)
- A.app.screen='full'
- self.can=A.Canvas(redraw_callback=self._redraw,event_callback=self._event)
- A.app.body=self.can
- A.app.menu=[]
- A.app.exit_key_handler=self.exit
- def _redraw(self,x):
- if img:self.can.blit(img)
- def _event(self,sc):
- k=sc['scancode']
- if sc['type'] is not A.EEventKey:return
- elif k==0xe: #kiri
- self.curx-=1
- if self.curx<0:
- self.curx=len(self.val)-1
- elif k==0xf: #kanan
- self.curx+=1
- if self.curx>len(self.val)-1:
- self.curx=0
- elif k==0x10: #atas
- self.yy[self.curx]+=1
- if self.yy[self.curx]>len(self.hval)-1:
- self.yy[self.curx]=0
- self.val[self.curx] = self.hval[self.yy[self.curx]]
- elif k==0x11: #bawah
- self.yy[self.curx]-=1
- if self.yy[self.curx]<0:
- self.yy[self.curx]=len(self.hval)-1
- self.val[self.curx] = self.hval[self.yy[self.curx]]
- def exit(self):
- self.run=0
- def _drawbox(self,rw,rh):
- txt,fnt='HEX COLOR VIEWER','legend'
- color=eval('0x'+''.join([chr(i) for i in self.val]))
- x,y=sc[0]/2,sc[1]/2-40
- yy=y+rh+20
- img.rectangle((x-rw,y-rh,x+rw,y+rh),0xffffff,color)
- img.text(((x-_tsize(txt,fnt)[0]/2),yy),u'%s' %txt,0xffffff,fnt)
- def _drawval(self):
- vlen=len(self.val)
- x,y,n=sc[0]/2,sc[1]-14,14
- xx=x-(((vlen-1)*14)/2)
- yy=y+8
- for i in range(vlen):
- img.text((xx+(i*n)-2,y),u'%s' %chr(self.val[i]),0xffffff,'legend')
- img.point((xx+(self.curx*n),yy),0xdd0000,width=4)
- def main(self):
- self.run=1
- while self.run:
- img.clear(0)
- self._drawbox(80,40)
- self._drawval()
- self._redraw(0)
- A.e32.ao_sleep(1e-04)
- col=Color()
- col.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement