aboutsummaryrefslogtreecommitdiff
path: root/lib/python/kle2xy.py
diff options
context:
space:
mode:
authorKeenan Brock <keenan@thebrocks.net>2020-05-15 15:09:22 -0400
committerGitHub <noreply@github.com>2020-05-15 12:09:22 -0700
commitc3aaed8dfb988adaf667f0b821c8cc0389ccac4c (patch)
treedcb19d4579a8bdf69737aafbe3d5486dc47edb78 /lib/python/kle2xy.py
parentebc274209e22bbe4e74fc750cf3eb6492283678e (diff)
downloadqmk_firmware-c3aaed8dfb988adaf667f0b821c8cc0389ccac4c.tar.gz
qmk_firmware-c3aaed8dfb988adaf667f0b821c8cc0389ccac4c.zip
[kle2info] Trim the code in `kle2xy` (#8955)
* [kle2jinfo] use min/max instead of if This is a slight change. Before, the key_skel would keep the invalid value for future keys. I think this is what was actually intended. * [kle2info] calculate x x is the current_x * key_size + (key_size/2) y is the current_y * key_size + (key_size/2) no reason to track both
Diffstat (limited to 'lib/python/kle2xy.py')
-rw-r--r--lib/python/kle2xy.py36
1 files changed, 8 insertions, 28 deletions
diff --git a/lib/python/kle2xy.py b/lib/python/kle2xy.py
index 003476f92..608d1b980 100644
--- a/lib/python/kle2xy.py
+++ b/lib/python/kle2xy.py
@@ -14,7 +14,7 @@ class KLE2xy(list):
14 self.name = name 14 self.name = name
15 self.invert_y = invert_y 15 self.invert_y = invert_y
16 self.key_width = Decimal('19.05') 16 self.key_width = Decimal('19.05')
17 self.key_skel = {'decal': False, 'border_color': 'none', 'keycap_profile': '', 'keycap_color': 'grey', 'label_color': 'black', 'label_size': 3, 'label_style': 4, 'width': Decimal('1'), 'height': Decimal('1'), 'x': Decimal('0'), 'y': Decimal('0')} 17 self.key_skel = {'decal': False, 'border_color': 'none', 'keycap_profile': '', 'keycap_color': 'grey', 'label_color': 'black', 'label_size': 3, 'label_style': 4, 'width': Decimal('1'), 'height': Decimal('1')}
18 self.rows = Decimal(0) 18 self.rows = Decimal(0)
19 self.columns = Decimal(0) 19 self.columns = Decimal(0)
20 20
@@ -55,8 +55,6 @@ class KLE2xy(list):
55 current_key = self.key_skel.copy() 55 current_key = self.key_skel.copy()
56 current_row = Decimal(0) 56 current_row = Decimal(0)
57 current_col = Decimal(0) 57 current_col = Decimal(0)
58 current_x = 0
59 current_y = self.key_width / 2
60 58
61 if isinstance(layout[0], dict): 59 if isinstance(layout[0], dict):
62 self.attrs(layout[0]) 60 self.attrs(layout[0])
@@ -76,18 +74,9 @@ class KLE2xy(list):
76 if 'h' in key and key['h'] != Decimal(1): 74 if 'h' in key and key['h'] != Decimal(1):
77 current_key['height'] = Decimal(key['h']) 75 current_key['height'] = Decimal(key['h'])
78 if 'a' in key: 76 if 'a' in key:
79 current_key['label_style'] = self.key_skel['label_style'] = int(key['a']) 77 current_key['label_style'] = self.key_skel['label_style'] = max(min(int(key['a']), 9), 0)
80 if current_key['label_style'] < 0:
81 current_key['label_style'] = 0
82 elif current_key['label_style'] > 9:
83 current_key['label_style'] = 9
84 if 'f' in key: 78 if 'f' in key:
85 font_size = int(key['f']) 79 current_key['label_size'] = self.key_skel['label_size'] = max(min(int(key['f']), 9), 1)
86 if font_size > 9:
87 font_size = 9
88 elif font_size < 1:
89 font_size = 1
90 current_key['label_size'] = self.key_skel['label_size'] = font_size
91 if 'p' in key: 80 if 'p' in key:
92 current_key['keycap_profile'] = self.key_skel['keycap_profile'] = key['p'] 81 current_key['keycap_profile'] = self.key_skel['keycap_profile'] = key['p']
93 if 'c' in key: 82 if 'c' in key:
@@ -101,10 +90,8 @@ class KLE2xy(list):
101 current_key['label_color'] = self.key_skel['label_color'] = key['t'] 90 current_key['label_color'] = self.key_skel['label_color'] = key['t']
102 if 'x' in key: 91 if 'x' in key:
103 current_col += Decimal(key['x']) 92 current_col += Decimal(key['x'])
104 current_x += Decimal(key['x']) * self.key_width
105 if 'y' in key: 93 if 'y' in key:
106 current_row += Decimal(key['y']) 94 current_row += Decimal(key['y'])
107 current_y += Decimal(key['y']) * self.key_width
108 if 'd' in key: 95 if 'd' in key:
109 current_key['decal'] = True 96 current_key['decal'] = True
110 97
@@ -113,16 +100,11 @@ class KLE2xy(list):
113 current_key['row'] = round(current_row, 2) 100 current_key['row'] = round(current_row, 2)
114 current_key['column'] = round(current_col, 2) 101 current_key['column'] = round(current_col, 2)
115 102
116 # Determine the X center 103 # x,y (units mm) is the center of the key
117 x_center = (current_key['width'] * self.key_width) / 2 104 x_center = current_col + current_key['width'] / 2
118 current_x += x_center 105 y_center = current_row + current_key['height'] / 2
119 current_key['x'] = current_x 106 current_key['x'] = x_center * self.key_width
120 current_x += x_center 107 current_key['y'] = y_center * self.key_width
121
122 # Determine the Y center
123 y_center = (current_key['height'] * self.key_width) / 2
124 y_offset = y_center - (self.key_width / 2)
125 current_key['y'] = (current_y + y_offset)
126 108
127 # Tend to our row/col count 109 # Tend to our row/col count
128 current_col += current_key['width'] 110 current_col += current_key['width']
@@ -138,8 +120,6 @@ class KLE2xy(list):
138 current_key = self.key_skel.copy() 120 current_key = self.key_skel.copy()
139 121
140 # Move to the next row 122 # Move to the next row
141 current_x = 0
142 current_y += self.key_width
143 current_col = Decimal(0) 123 current_col = Decimal(0)
144 current_row += Decimal(1) 124 current_row += Decimal(1)
145 if current_row > self.rows: 125 if current_row > self.rows: