[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
This commit is contained in:
Keenan Brock 2020-05-15 15:09:22 -04:00 committed by GitHub
parent ebc274209e
commit c3aaed8dfb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,7 +14,7 @@ class KLE2xy(list):
self.name = name self.name = name
self.invert_y = invert_y self.invert_y = invert_y
self.key_width = Decimal('19.05') 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.rows = Decimal(0)
self.columns = Decimal(0) self.columns = Decimal(0)
@ -55,8 +55,6 @@ class KLE2xy(list):
current_key = self.key_skel.copy() current_key = self.key_skel.copy()
current_row = Decimal(0) current_row = Decimal(0)
current_col = Decimal(0) current_col = Decimal(0)
current_x = 0
current_y = self.key_width / 2
if isinstance(layout[0], dict): if isinstance(layout[0], dict):
self.attrs(layout[0]) self.attrs(layout[0])
@ -76,18 +74,9 @@ class KLE2xy(list):
if 'h' in key and key['h'] != Decimal(1): if 'h' in key and key['h'] != Decimal(1):
current_key['height'] = Decimal(key['h']) current_key['height'] = Decimal(key['h'])
if 'a' in key: if 'a' in key:
current_key['label_style'] = self.key_skel['label_style'] = int(key['a']) current_key['label_style'] = self.key_skel['label_style'] = max(min(int(key['a']), 9), 0)
if current_key['label_style'] < 0:
current_key['label_style'] = 0
elif current_key['label_style'] > 9:
current_key['label_style'] = 9
if 'f' in key: if 'f' in key:
font_size = int(key['f']) current_key['label_size'] = self.key_skel['label_size'] = max(min(int(key['f']), 9), 1)
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
if 'p' in key: if 'p' in key:
current_key['keycap_profile'] = self.key_skel['keycap_profile'] = key['p'] current_key['keycap_profile'] = self.key_skel['keycap_profile'] = key['p']
if 'c' in key: if 'c' in key:
@ -101,10 +90,8 @@ class KLE2xy(list):
current_key['label_color'] = self.key_skel['label_color'] = key['t'] current_key['label_color'] = self.key_skel['label_color'] = key['t']
if 'x' in key: if 'x' in key:
current_col += Decimal(key['x']) current_col += Decimal(key['x'])
current_x += Decimal(key['x']) * self.key_width
if 'y' in key: if 'y' in key:
current_row += Decimal(key['y']) current_row += Decimal(key['y'])
current_y += Decimal(key['y']) * self.key_width
if 'd' in key: if 'd' in key:
current_key['decal'] = True current_key['decal'] = True
@ -113,16 +100,11 @@ class KLE2xy(list):
current_key['row'] = round(current_row, 2) current_key['row'] = round(current_row, 2)
current_key['column'] = round(current_col, 2) current_key['column'] = round(current_col, 2)
# Determine the X center # x,y (units mm) is the center of the key
x_center = (current_key['width'] * self.key_width) / 2 x_center = current_col + current_key['width'] / 2
current_x += x_center y_center = current_row + current_key['height'] / 2
current_key['x'] = current_x current_key['x'] = x_center * self.key_width
current_x += x_center current_key['y'] = y_center * self.key_width
# 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)
# Tend to our row/col count # Tend to our row/col count
current_col += current_key['width'] current_col += current_key['width']
@ -138,8 +120,6 @@ class KLE2xy(list):
current_key = self.key_skel.copy() current_key = self.key_skel.copy()
# Move to the next row # Move to the next row
current_x = 0
current_y += self.key_width
current_col = Decimal(0) current_col = Decimal(0)
current_row += Decimal(1) current_row += Decimal(1)
if current_row > self.rows: if current_row > self.rows: