summaryrefslogtreecommitdiff
path: root/lib/python/kle2xy.py
diff options
context:
space:
mode:
authorKeenan Brock <keenan@thebrocks.net>2020-05-15 15:09:22 -0400
committerFlorian Didron <fdidron@users.noreply.github.com>2020-06-12 17:00:27 +0900
commitd4dd4d4864a5636e31e512304564440dce1a9764 (patch)
tree757fa329a61f1fb7a5d1e26ff4c61480f0d411e9 /lib/python/kle2xy.py
parent375e2d7ec85eb0b16eba10bcbab447081b4633a4 (diff)
[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 003476f92e..608d1b9809 100644
--- a/lib/python/kle2xy.py
+++ b/lib/python/kle2xy.py
@@ -14,7 +14,7 @@ class KLE2xy(list):
self.name = name
self.invert_y = invert_y
self.key_width = Decimal('19.05')
- 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')}
+ 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')}
self.rows = Decimal(0)
self.columns = Decimal(0)
@@ -55,8 +55,6 @@ class KLE2xy(list):
current_key = self.key_skel.copy()
current_row = Decimal(0)
current_col = Decimal(0)
- current_x = 0
- current_y = self.key_width / 2
if isinstance(layout[0], dict):
self.attrs(layout[0])
@@ -76,18 +74,9 @@ class KLE2xy(list):
if 'h' in key and key['h'] != Decimal(1):
current_key['height'] = Decimal(key['h'])
if 'a' in key:
- current_key['label_style'] = self.key_skel['label_style'] = int(key['a'])
- if current_key['label_style'] < 0:
- current_key['label_style'] = 0
- elif current_key['label_style'] > 9:
- current_key['label_style'] = 9
+ current_key['label_style'] = self.key_skel['label_style'] = max(min(int(key['a']), 9), 0)
if 'f' in key:
- font_size = int(key['f'])
- if font_size > 9:
- font_size = 9
- elif font_size < 1:
- font_size = 1
- current_key['label_size'] = self.key_skel['label_size'] = font_size
+ current_key['label_size'] = self.key_skel['label_size'] = max(min(int(key['f']), 9), 1)
if 'p' in key:
current_key['keycap_profile'] = self.key_skel['keycap_profile'] = key['p']
if 'c' in key:
@@ -101,10 +90,8 @@ class KLE2xy(list):
current_key['label_color'] = self.key_skel['label_color'] = key['t']
if 'x' in key:
current_col += Decimal(key['x'])
- current_x += Decimal(key['x']) * self.key_width
if 'y' in key:
current_row += Decimal(key['y'])
- current_y += Decimal(key['y']) * self.key_width
if 'd' in key:
current_key['decal'] = True
@@ -113,16 +100,11 @@ class KLE2xy(list):
current_key['row'] = round(current_row, 2)
current_key['column'] = round(current_col, 2)
- # Determine the X center
- x_center = (current_key['width'] * self.key_width) / 2
- current_x += x_center
- current_key['x'] = current_x
- current_x += x_center
-
- # Determine the Y center
- y_center = (current_key['height'] * self.key_width) / 2
- y_offset = y_center - (self.key_width / 2)
- current_key['y'] = (current_y + y_offset)
+ # x,y (units mm) is the center of the key
+ x_center = current_col + current_key['width'] / 2
+ y_center = current_row + current_key['height'] / 2
+ current_key['x'] = x_center * self.key_width
+ current_key['y'] = y_center * self.key_width
# Tend to our row/col count
current_col += current_key['width']
@@ -138,8 +120,6 @@ class KLE2xy(list):
current_key = self.key_skel.copy()
# Move to the next row
- current_x = 0
- current_y += self.key_width
current_col = Decimal(0)
current_row += Decimal(1)
if current_row > self.rows: