Skip to content

Commit

Permalink
v1.3
Browse files Browse the repository at this point in the history
update friendly name
make time format and log customizable
  • Loading branch information
xmcp committed Jan 31, 2017
1 parent 9284b9e commit 957b5ad
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
8 changes: 5 additions & 3 deletions const.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#coding=utf-8
friendly_name={
'Up': '↑', 'Down': '↓', 'Left': '←', 'Right': '→',
'Return': 'Enter', 'Cancel': 'Break', 'Back': 'Backspace',
'Capital': 'CapsLock', 'Scroll': 'ScrollLock', 'Apps': 'Menu',
'Return': 'Enter', 'Space': '⎵', 'Cancel': 'Break', 'Back': '⌫', 'Delete': 'Del',
'Capital': 'CapsLk', 'Scroll': 'ScrLk', 'Apps': 'Menu',
'Escape': 'Esc', 'Snapshot': 'PrtSc', 'Prior': 'PgUp', 'Next': 'PgDn',
'Lcontrol': 'Ctrl', 'Lmenu': 'Alt', 'Lwin': 'Win', 'Lshift': 'Shift',
'Rcontrol': 'Ctrl(R)', 'Rmenu': 'Alt(R)', 'Rwin': 'Win(R)', 'Rshift': 'Shift(R)',
'Oem_Minus': '-', 'Oem_Plus': '=', 'Oem_Comma': ',', 'Oem_Period': '.',
'Oem_5': '\\', 'Oem_3': '`', 'Oem_2': '/', 'Oem_1': ';', 'Oem_7': "'", 'Oem_4': '[', 'Oem_6': ']',
'Volume_Mute': 'Mute', 'Volume_Up': 'Vol+', 'Volume_Down': 'Vol-',
}
for n in range(10):
friendly_name['Numpad%d'%n]='Num %d'%n
Expand All @@ -20,4 +21,5 @@
'mouse right down': [True,2],
'mouse right up': [False,2],
}
tip_format='{time} '
tip_format='%H:%M:%S '
print_log=False
31 changes: 17 additions & 14 deletions misaki.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#! python2
#coding=utf-8
from __future__ import print_function

import hooker
import const
Expand All @@ -12,6 +13,9 @@
from Tkinter import *
from ttk import *

if not const.print_log:
print=lambda *__,**_:None

if __name__=='__main__':
multiprocessing.freeze_support()
keyqueue=multiprocessing.Queue()
Expand All @@ -24,7 +28,7 @@
tk.attributes('-topmost',True)
tk.resizable(True,False)
tk.configure(background='black')
tk.geometry('600x27')
tk.geometry('800x27')
s=Style(tk)
s.configure('BtnOn.TLabel',background='yellow',foreground='black',font='Consolas -20')
s.configure('BtnOff.TLabel',background='#666',foreground='white',font='Consolas -20')
Expand Down Expand Up @@ -66,45 +70,45 @@ def __init__(self):
def _clear(self):
if not self.labels:
return
print 'clear label',len(self.labels)
print('clear label',len(self.labels))
def holy_after():
for item in self.labels.values():
item.grid_forget()
self.labels={}
self.clearlock.set()
print '-- clear ok'
print('-- clear ok')
self.lbindex=0
print '-- clear start'
print('-- clear start')
tk.after_idle(holy_after)
self.clearlock.wait()
self.clearlock.clear()

def push(self,key):
if not self.alive_keys: # clear history
self._clear()
print '-- clear continue'
print('-- clear continue')
self.alive_keys.add(key)

if key not in self.labels:
print 'key down',key
print('key down',key)
def holy_after():
self.labels[key]=Label(keyframe,text=key,style='BtnOn.TLabel')
self.labels[key].grid(row=0,column=self.lbindex)
self.lbindex+=1
#print 'key down-done',len(self.alive_keys)
#print('key down-done',len(self.alive_keys))
tk.after_idle(holy_after)
else:
print 'key revive',key
print('key revive',key)
self.labels[key]['style']='BtnOn.TLabel'

def pop(self,key):
self.alive_keys.discard(key)
def holy_after():
if key in self.labels:
self.labels[key]['style']='BtnOff.TLabel'
print 'key up',key,'/ alive keys =',len(self.alive_keys)
print('key up',key,'/ alive keys =',len(self.alive_keys))
else:
print 'key up-ignored',key
print('key up-ignored',key)
tk.after(50,holy_after)

def try_clear(self):
Expand All @@ -116,11 +120,11 @@ def __init__(self):
pass

def push(self,key):
print 'mouse down',key
print('mouse down',key)
mousebtn[key]['style']='BtnOn.TLabel'

def pop(self,key):
print 'mouse up',key
print('mouse up',key)
def holy_after():
mousebtn[key]['style']='BtnOff.TLabel'
register_after(50,'mouse %s'%key,holy_after)
Expand Down Expand Up @@ -157,7 +161,6 @@ def key_fetcher():
tk.after_idle(tk.attributes,'-alpha',alpha_flag)
tk.after_idle(tk.attributes,'-toolwindow',1-alpha_flag)
#tk.after_idle(tk.focus_force)
print alpha_flag
else: # keyup
mckey.pop(dispcode)

Expand All @@ -173,7 +176,7 @@ def mouse_fetcher():

def tipper():
while True:
tipvar.set(const.tip_format.replace('{time}',time.strftime('%H:%M:%S',time.localtime())))
tipvar.set(time.strftime(const.tip_format,time.localtime()))
time.sleep(1-time.time()%1+.1)

if __name__=='__main__':
Expand Down

0 comments on commit 957b5ad

Please sign in to comment.