~ruther/qmk_firmware

c3aaed8dfb988adaf667f0b821c8cc0389ccac4c — Keenan Brock 5 years ago ebc2742
[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
1 files changed, 8 insertions(+), 28 deletions(-)

M lib/python/kle2xy.py
M lib/python/kle2xy.py => lib/python/kle2xy.py +8 -28
@@ 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: