-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
keyboard_generator.py
86 lines (70 loc) · 1.97 KB
/
keyboard_generator.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
83
84
85
86
import sys
TOP_ROW = [
"<AD01>",
"<AD02>",
"<AD03>",
"<AD04>",
"<AD05>",
"<AD06>",
"<AD07>",
"<AD08>",
"<AD09>",
"<AD10>",
]
HOME_ROW = [
"<AC01>",
"<AC02>",
"<AC03>",
"<AC04>",
"<AC05>",
"<AC06>",
"<AC07>",
"<AC08>",
"<AC09>",
"<AC10>",
]
BOTTOM_ROW = [
"<AB01>",
"<AB02>",
"<AB03>",
"<AB04>",
"<AB05>",
"<AB06>",
"<AB07>",
"<AB08>",
"<AB09>",
"<AB10>",
]
KEYBOARD = [TOP_ROW, HOME_ROW, BOTTOM_ROW]
custom_keyboard = [[], [], []]
file_name = sys.argv[1]
with open(file_name) as keyboard_file:
for row_num, row in enumerate(keyboard_file):
full_row = row.split("|")
cleaned_row = full_row[1:-1]
for key_num, string in enumerate(cleaned_row):
keyboard_keys = []
for character in string:
temp_unicode = hex(ord(character))
unicode = "U" + temp_unicode.upper()[2:]
keyboard_keys.append(unicode)
custom_keyboard[row_num].append([KEYBOARD[row_num][key_num], keyboard_keys])
def format_custom_keyboard_for_config_file(custom_keyboard):
config_string = """\n // CUSTOM CONFIGURATION\n\n"""
for row in custom_keyboard:
for key_config in row:
key_name = key_config[0]
key_bindings = key_config[1]
config_string += f" key {key_name} {{ {key_bindings} }};\n"
config_string_cleaned = config_string.replace("'", "")
config_string_cleaned += """\n include "level3(ralt_switch)"\n"""
config_string_cleaned += """\n // END CUSTOM CONFIGURATION\n"""
return config_string_cleaned
print(format_custom_keyboard_for_config_file(custom_keyboard))
with open("us_copy", "r") as f:
contents = f.readlines()
index = 56
contents.insert(index, format_custom_keyboard_for_config_file(custom_keyboard))
with open("custom_layout", "w") as f:
contents = "".join(contents)
f.write(contents)