-
Notifications
You must be signed in to change notification settings - Fork 4
/
show.py
77 lines (55 loc) · 1.54 KB
/
show.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import string
from talon.voice import Context
from talon import canvas
from talon import ui
from talon.skia import Rect
ctx = Context('show')
alphabet_context = Context('alphabet_context')
# font size of the overlay
font_size = 18
# left padding of the font in the overlay
padding_left = 20
def draw_alphabet(canvas):
paint = canvas.paint
paint.textsize = font_size
paint.color = '333'
paint.style = paint.Style.FILL
canvas.draw_rect(Rect(canvas.x, canvas.y, canvas.width, canvas.height))
line_height = paint.get_fontmetrics(1.5)[0]
paint.color = 'dedede'
try:
from user import std
alnum = std.alpha_alt
except:
# TODO log an error
alnum = []
num = 1
for k, v in zip(alnum, string.ascii_lowercase):
canvas.draw_text('%s - %s' % (k, v), canvas.x + padding_left, canvas.y + (num * line_height))
num += 1
# initialize the overlay
screen = ui.main_screen()
w, h = screen.width, screen.height
x_position = w / 3
y_position = h / 4
x_dimension = w / 6
y_dimension = h / 1.5
panel = canvas.Canvas(x_position, y_position, x_dimension, y_dimension)
panel.register('draw', draw_alphabet)
panel.hide()
def show_alphabet(_):
global alphabet_context
panel.show()
panel.freeze()
keymap = {
'(0 | exit | escape)': lambda x: close_alphabet(),
}
alphabet_context.keymap(keymap)
alphabet_context.load()
def close_alphabet():
panel.hide()
alphabet_context.unload()
keymap = {
'show alphabet': show_alphabet,
}
ctx.keymap(keymap)