-
Notifications
You must be signed in to change notification settings - Fork 19
/
emily-symbols.py
155 lines (132 loc) · 5.65 KB
/
emily-symbols.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# Emily's Symbol Dictionary
import re
# define your starters here
# standard custom
uniqueStarters = ["SKWH", "#SKWH"]
# define if attachment keys define where "space"s or "attachment"s lie
attachmentMethod = "space"
LONGEST_KEY = 1
# variant format = ['', 'E', 'U', 'EU']
# if no variants exist, then a single string can be used for the symbol and the variant specifier keys will be valid but ignored
symbols = {
uniqueStarters[0]: { # standard
# more computer function-y symbols
"FG" : ["{#Tab}", "{#Backspace}", "{#Delete}", "{#Escape}"],
"RPBG" : ["{#Up}", "{#Left}", "{#Right}", "{#Down}"],
"FRPBG" : ["{#Page_Up}", "{#Home}", "{#End}", "{#Page_Down}"],
"FRBG" : ["{#AudioPlay}", "{#AudioPrev}", "{#AudioNext}", "{#AudioStop}"],
"FRB" : ["{#AudioMute}", "{#AudioLowerVolume}", "{#AudioRaiseVolume}", "{#Eject}"],
"" : ["", "{*!}", "{*?}", "{#Space}"],
"FL" : ["{*-|}", "{*<}", "{<}", "{*>}"],
# typable symbols
"FR" : ["!", "¬", "↦", "¡"],
"FP" : ["\"", "“", "”", "„"],
"FRLG" : ["#", "©", "®", "™"],
"RPBL" : ["$", "¥", "€", "£"],
"FRPB" : ["%", "‰", "‱", "φ"],
"FBG" : ["&", "∩", "∧", "∈"],
"F" : ["'", "‘", "’", "‚"],
"FPL" : ["(", "[", "<", "\{"],
"RBG" : [")", "]", ">", "\}"],
"L" : ["*", "∏", "§", "×"],
"G" : ["+", "∑", "¶", "±"],
"B" : [",", "∪", "∨", "∉"],
"PL" : ["-", "−", "–", "—"],
"R" : [".", "•", "·", "…"],
"RP" : ["/", "⇒", "⇔", "÷"],
"LG" : [":", "∋", "∵", "∴"],
"RB" : [";", "∀", "∃", "∄"],
"PBLG" : ["=", "≡", "≈", "≠"],
"FPB" : ["?", "¿", "∝", "‽"],
"FRPBLG" : ["@", "⊕", "⊗", "∅"],
"FB" : ["\\", "Δ", "√", "∞"],
"RPG" : ["^", "«", "»", "°"],
"BG" : ["_", "≤", "≥", "µ"],
"P" : ["`", "⊂", "⊃", "π"],
"PB" : ["|", "⊤", "⊥", "¦"],
"FPBG" : ["~", "⊆", "⊇", "˜"],
"FPBL" : ["↑", "←", "→", "↓"]
},
uniqueStarters[1]: { # custom
# add your own strokes here (or above, or wherever else you like)!
"" : "test"
}
}
def lookup(chord):
# normalise stroke from embedded number, to preceding hash format
stroke = chord[0]
if any(k in stroke for k in "1234506789"): # if chord contains a number
stroke = list(stroke)
numbers = ["O", "S", "T", "P", "H", "A", "F", "P", "L", "T"]
for key in range(len(stroke)):
if stroke[key].isnumeric():
stroke[key] = numbers[int(stroke[key])] # set number key to letter
numberFlag = True
stroke = ["#"] + stroke
stroke = "".join(stroke)
# the regex decomposes a stroke into the following groups/variables:
# starter #STKPWHR
# attachments AO
# capitalisation */-
# variants EU
# pattern FRPBLG
# repetitions TS
# (unused: DZ)
match = re.fullmatch(r'([#STKPWHR]*)([AO]*)([*-]?)([EU]*)([FRPBLG]*)([TS]*)', stroke)
if match is None:
raise KeyError
(starter, attachments, capitalisation, variants, pattern, repetitions) = match.groups()
if starter not in uniqueStarters:
raise KeyError
if len(chord) != 1:
raise KeyError
assert len(chord) <= LONGEST_KEY
# calculate the attachment method, and remove attachment specifier keys
attach = [(attachmentMethod == "space") ^ ('A' in attachments),
(attachmentMethod == "space") ^ ('O' in attachments)]
# detect if capitalisation is required, and remove specifier key
capital = capitalisation == '*'
# calculate the variant number, and remove variant specifier keys
variant = 0
if 'E' in variants:
variant = variant + 1
if 'U' in variants:
variant = variant + 2
# calculate the repetition, and remove repetition specifier keys
repeat = 1
if 'S' in repetitions:
repeat = repeat + 1
if 'T' in repetitions:
repeat = repeat + 2
if pattern not in symbols[starter]:
raise KeyError
# extract symbol entry from the 'symbols' dictionary, with variant specification if available
selection = symbols[starter][pattern]
if type(selection) == list:
selection = selection[variant]
output = selection
# repeat the symbol the specified number of times
output = output * repeat
# attachment space to either end of the symbol string to avoid escapement,
# but prevent doing this for retrospective add/delete spaces, since it'll
# mess with these macros
if selection not in ["{*!}", "{*?}"]:
output = " " + output + " "
# add appropriate attachment as specified (again, prevent doing this
# for retrospective add/delete spaces)
if selection not in ["{*!}", "{*?}"]:
if attach[0]:
output = "{^}" + output
if attach[1]:
output = output + "{^}"
# cancel out some formatting when using space attachment
if attachmentMethod == "space":
if not attach[0]:
output = "{}" + output
if not attach[1]:
output = output + "{}"
# apply capitalisation
if capital:
output = output + "{-|}"
# all done :D
return output