import appuifw2
import graphics
import e32
import time
import keycapture
import fgimage
import envy
import appswitch
import ini
def ru(x): return x.decode('utf-8')
envy.set_app_system(1)
e32.ao_sleep(0,lambda:envy.set_app_hidden(1))
colors = [(255,255,255),
(0,0,128),
(105,105,105),
(0,191,255),
(0,255,0),
(255,255,0),
(255,165,0),
(255,0,0),
(255,20,147),
(0,255,0)]
keys = [8, 63586, 63570, 48, 42, 35]
try:
setting = ini.read('C:\data\Clocker.ini')
except:
setting = {'pos_x':0,'pos_y':0,'color':2, 'key':3}
try:
ini.write('C:\data\Clocker.ini', setting)
except:
pass
image = graphics.Image.new((66,18))
window = fgimage.FGImage()
running = None
screen=None
name = appswitch.application_list(1)[0]
def run():
global name, screen
while True:
if running:
date = unicode(time.strftime('%H:%M:%S'))
if name!=appswitch.application_list(1)[0]:
name = appswitch.application_list(1)[0]
window.unset()
screen = graphics.screenshot()
else:
pass
image.blit(screen,source=(setting['pos_x'], setting['pos_y']))
image.text((3,16), date, fill=colors[setting['color']], font=u'Acb14')
window.set(setting['pos_x'], setting['pos_y'],image._bitmapapi())
e32.ao_yield()
def hide():
global running
running = False
window.unset()
def show():
global running, screen, name
screen = graphics.screenshot()
name = appswitch.application_list(1)[0]
running = True
def turn():
if running:
hide()
else:
show()
def handle_event(scancode):
if scancode == keys[setting['key']]:
turn()
def hide_p():
appswitch.switch_to_bg(u'Clocker')
def exit():
if not appuifw2.query(ru('Are you sure ?'), 'query'):
return
appuifw2.app.set_exit()
keyboard = keycapture.KeyCapturer(handle_event)
keyboard.keys = keys #keyboard.keys = [keys[setting['key']]]
keyboard.forwarding = 1
keyboard.start()
form = appuifw2.Form(
[(ru('Indentation on the left window'), 'number', setting['pos_x']),
(ru('Top indent box'), 'number', setting['pos_y']),
(ru('Font color'), 'combo',
([ru('White'),
ru('Blue'),
ru('Brown'),
ru('Blue'),
ru('Salad'),
ru('Yellow'),
ru('Orange'),
ru('Red'),
ru('Pink'),
ru('Bright Green')],
setting['color'])), #setting['color']
(ru('Key'), 'combo',
([ru('Delete'),
ru('Green'),
ru('Menu'),
ru('Zero'),
ru('Asterisk'), #Phim [*]
ru('Grill')], #Phim [#]
setting['key']))], #setting['key']
appuifw2.FFormEditModeOnly|appuifw2.FFormDoubleSpaced)
def set_setting():
global setting
form.execute()
setting = {'pos_x': int(form[0][2]),
'pos_y': int(form[1][2]),
'color':int(form[2][2][1]),
'key':int(form[3][2][1])}
try:
ini.write('C:\data\Clocker.ini', setting)
except:
pass
appuifw2.app.exit_key_text = ru('Hide')
appuifw2.app.exit_key_handler = hide_p
appuifw2.app.menu_key_text = ru('Menu')
appuifw2.app.menu = [(ru('Setting'), set_setting),
(ru('Exit'),exit)]
run()