forked from GabMus/razerCommander
-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom_kb_builder.py
82 lines (77 loc) · 2.68 KB
/
custom_kb_builder.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
78
79
80
81
82
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, Gio, Gdk
import custom_keyboard as CustomKb
import custom_profiles
KEYCAP_SIZE = 50
rkb = None
def build_key_box(key, color, signal_handler):
box = Gtk.EventBox()
if not key.isGhost:
box.get_style_context().add_class('keycap')
key.color=color
box.override_background_color(
Gtk.StateType.NORMAL,
color
)
label = Gtk.Label()
label.set_text(key.label)
box.add(label)
box.keyx=key.x
box.keyy=key.y
if key.label in ['tab', 'lctrl', 'lalt', 'ralt', 'rctrl', '\\']:
box.set_size_request(KEYCAP_SIZE * 1.5, KEYCAP_SIZE)
elif key.label == 'capslk':
box.set_size_request(KEYCAP_SIZE * 1.75, KEYCAP_SIZE)
elif key.label in ['lshift', 'ret']:
box.set_size_request(KEYCAP_SIZE * 2.25, KEYCAP_SIZE)
elif key.label == 'rshift':
box.set_size_request(KEYCAP_SIZE * 2.75, KEYCAP_SIZE)
elif key.label == 'bck\nspc':
box.set_size_request(KEYCAP_SIZE * 2, KEYCAP_SIZE)
elif key.label == 'spacebar':
box.set_size_request(KEYCAP_SIZE * 6, KEYCAP_SIZE)
elif key.label == CustomKb.kblayouts.INV_GHOST:
box.set_size_request(0, 0)
elif key.label == CustomKb.kblayouts.GHOST:
box.set_size_request(KEYCAP_SIZE-4, KEYCAP_SIZE-4)
else:
box.set_size_request(KEYCAP_SIZE, KEYCAP_SIZE)
box.connect('button-press-event', signal_handler)
return box
def build_keyrow_box(row, colors, signal_handler, prof_index):
box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
for key in row.keylist:
if not key.isGhost:
k_col=Gdk.RGBA(
colors[prof_index][0],
colors[prof_index][1],
colors[prof_index][2]
)
else:
k_col=Gdk.RGBA(0,0,0)
keybox = build_key_box(
key,
k_col,
signal_handler
)
if not key.isGhost:
prof_index+=1
box.pack_start(keybox, True, True, 0)
return {'row': box, 'prof_index': prof_index}
def build_keyboard_box(box, colors, signal_handler, nrkb):
global rkb
rkb = nrkb
# Empty keyboardBox
if len(box.get_children()) >= 2:
box.remove(box.get_children()[1])
prof_index = 0
kb_inner_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
for row in rkb.rows:
rowbox_res = build_keyrow_box(row, colors, signal_handler, prof_index)
rowbox = rowbox_res['row']
prof_index = rowbox_res['prof_index']
kb_inner_box.pack_start(rowbox, True, True, 0)
box.pack_end(kb_inner_box, True, True, 0)
kb_inner_box.show_all()
return box