-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.py
42 lines (33 loc) · 1.7 KB
/
template.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
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def __repr__(self):
return '(' + str(self.x) + ', ' + str(self.y) + ')'
class Template(list):
def __init__(self, name, points):
self.name = name
super(Template, self).__init__(points)
#In Python 3, the super(Template, self) call is equivalent to the parameterless super() call.
#The first parameter refers to the subclass Template, while the second parameter refers to a Template object which, in this case, is self.
class WordTemplates:
def __init__(self, keys_info):
self.keys_info = keys_info
self.word_list = ['it', 'we', 'he', 'on',
'the', 'but', 'his', 'are',
'copy', 'redo', 'undo', 'save', # text editing commands
'people', 'before', 'during', 'number',
'problem', 'example', 'company', 'country',
'absolutely', 'dealership', 'noteworthy', 'surprising',
'information', 'development', 'outstanding', 'personality']
self.templates = []
def set_templates(self):
for w in self.word_list:
points = []
for c in w:
for k in self.keys_info:
if c.lower() == k.key_name.lower(): # uppercase and lowercase characters are equally treated
# the centre point of the key
points.append(Point(int(k.key_top_left_x+k.key_width/2), int(k.key_top_left_y+k.key_height/2)))
self.templates.append(Template(w, points))
return self.templates