diff options
author | QMK Bot <hello@qmk.fm> | 2019-11-13 05:24:56 +0000 |
---|---|---|
committer | QMK Bot <hello@qmk.fm> | 2019-11-13 05:24:56 +0000 |
commit | a4c2a9b083d82d9e7d7fe3a68c0d51ae2280495f (patch) | |
tree | a1b6edbeb75442ab50b68283bea5af72b09ceccf /lib/python | |
parent | 7329c2d02d38f40a23d38f789de34057fd2acd42 (diff) | |
download | qmk_firmware-a4c2a9b083d82d9e7d7fe3a68c0d51ae2280495f.tar.gz qmk_firmware-a4c2a9b083d82d9e7d7fe3a68c0d51ae2280495f.zip |
format code according to conventions [skip ci]
Diffstat (limited to 'lib/python')
-rw-r--r-- | lib/python/kle2xy.py | 17 | ||||
-rwxr-xr-x | lib/python/qmk/cli/kle2json.py | 10 | ||||
-rw-r--r-- | lib/python/qmk/tests/test_cli_commands.py | 2 |
3 files changed, 10 insertions, 19 deletions
diff --git a/lib/python/kle2xy.py b/lib/python/kle2xy.py index ea16a4b5e..929144319 100644 --- a/lib/python/kle2xy.py +++ b/lib/python/kle2xy.py | |||
@@ -4,6 +4,7 @@ | |||
4 | import hjson | 4 | import hjson |
5 | from decimal import Decimal | 5 | from decimal import Decimal |
6 | 6 | ||
7 | |||
7 | class KLE2xy(list): | 8 | class KLE2xy(list): |
8 | """Abstract interface for interacting with a KLE layout. | 9 | """Abstract interface for interacting with a KLE layout. |
9 | """ | 10 | """ |
@@ -13,17 +14,7 @@ class KLE2xy(list): | |||
13 | self.name = name | 14 | self.name = name |
14 | self.invert_y = invert_y | 15 | self.invert_y = invert_y |
15 | self.key_width = Decimal('19.05') | 16 | self.key_width = Decimal('19.05') |
16 | self.key_skel = { | 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 | 'decal': False, | ||
18 | 'border_color': 'none', | ||
19 | 'keycap_profile': '', | ||
20 | 'keycap_color': 'grey', | ||
21 | 'label_color': 'black', | ||
22 | 'label_size': 3, | ||
23 | 'label_style': 4, | ||
24 | 'width': Decimal('1'), 'height': Decimal('1'), | ||
25 | 'x': Decimal('0'), 'y': Decimal('0') | ||
26 | } | ||
27 | self.rows = Decimal(0) | 18 | self.rows = Decimal(0) |
28 | self.columns = Decimal(0) | 19 | self.columns = Decimal(0) |
29 | 20 | ||
@@ -34,13 +25,13 @@ class KLE2xy(list): | |||
34 | def width(self): | 25 | def width(self): |
35 | """Returns the width of the keyboard plate. | 26 | """Returns the width of the keyboard plate. |
36 | """ | 27 | """ |
37 | return (Decimal(self.columns) * self.key_width) + self.key_width/2 | 28 | return (Decimal(self.columns) * self.key_width) + self.key_width / 2 |
38 | 29 | ||
39 | @property | 30 | @property |
40 | def height(self): | 31 | def height(self): |
41 | """Returns the height of the keyboard plate. | 32 | """Returns the height of the keyboard plate. |
42 | """ | 33 | """ |
43 | return (self.rows * self.key_width) + self.key_width/2 | 34 | return (self.rows * self.key_width) + self.key_width / 2 |
44 | 35 | ||
45 | @property | 36 | @property |
46 | def size(self): | 37 | def size(self): |
diff --git a/lib/python/qmk/cli/kle2json.py b/lib/python/qmk/cli/kle2json.py index 22eb515df..5a4e97e3a 100755 --- a/lib/python/qmk/cli/kle2json.py +++ b/lib/python/qmk/cli/kle2json.py | |||
@@ -31,7 +31,7 @@ class CustomJSONEncoder(json.JSONEncoder): | |||
31 | @cli.subcommand('Convert a KLE layout to a Configurator JSON') | 31 | @cli.subcommand('Convert a KLE layout to a Configurator JSON') |
32 | def kle2json(cli): | 32 | def kle2json(cli): |
33 | """Convert a KLE layout to QMK's layout format. | 33 | """Convert a KLE layout to QMK's layout format. |
34 | """ # If filename is a path | 34 | """ # If filename is a path |
35 | if cli.args.filename.startswith("/") or cli.args.filename.startswith("./"): | 35 | if cli.args.filename.startswith("/") or cli.args.filename.startswith("./"): |
36 | file_path = Path(cli.args.filename) | 36 | file_path = Path(cli.args.filename) |
37 | # Otherwise assume it is a file name | 37 | # Otherwise assume it is a file name |
@@ -45,7 +45,7 @@ def kle2json(cli): | |||
45 | # Check if info.json exists, allow overwrite with force | 45 | # Check if info.json exists, allow overwrite with force |
46 | if Path(out_path, "info.json").exists() and not cli.args.force: | 46 | if Path(out_path, "info.json").exists() and not cli.args.force: |
47 | cli.log.error('File {fg_cyan}%s/info.json{style_reset_all} already exists, use -f or --force to overwrite.', str(out_path)) | 47 | cli.log.error('File {fg_cyan}%s/info.json{style_reset_all} already exists, use -f or --force to overwrite.', str(out_path)) |
48 | return False; | 48 | return False |
49 | try: | 49 | try: |
50 | # Convert KLE raw to x/y coordinates (using kle2xy package from skullydazed) | 50 | # Convert KLE raw to x/y coordinates (using kle2xy package from skullydazed) |
51 | kle = KLE2xy(raw_code) | 51 | kle = KLE2xy(raw_code) |
@@ -65,11 +65,9 @@ def kle2json(cli): | |||
65 | }}, | 65 | }}, |
66 | ) | 66 | ) |
67 | # Initialize keyboard with json encoded from ordered dict | 67 | # Initialize keyboard with json encoded from ordered dict |
68 | keyboard = json.dumps(keyboard, indent=4, separators=( | 68 | keyboard = json.dumps(keyboard, indent=4, separators=(', ', ': '), sort_keys=False, cls=CustomJSONEncoder) |
69 | ', ', ': '), sort_keys=False, cls=CustomJSONEncoder) | ||
70 | # Initialize layout with kle2qmk from converter module | 69 | # Initialize layout with kle2qmk from converter module |
71 | layout = json.dumps(kle2qmk(kle), separators=( | 70 | layout = json.dumps(kle2qmk(kle), separators=(', ', ':'), cls=CustomJSONEncoder) |
72 | ', ', ':'), cls=CustomJSONEncoder) | ||
73 | # Replace layout in keyboard json | 71 | # Replace layout in keyboard json |
74 | keyboard = keyboard.replace('"LAYOUT_JSON_HERE"', layout) | 72 | keyboard = keyboard.replace('"LAYOUT_JSON_HERE"', layout) |
75 | # Write our info.json | 73 | # Write our info.json |
diff --git a/lib/python/qmk/tests/test_cli_commands.py b/lib/python/qmk/tests/test_cli_commands.py index d91af992a..85d4d91af 100644 --- a/lib/python/qmk/tests/test_cli_commands.py +++ b/lib/python/qmk/tests/test_cli_commands.py | |||
@@ -19,9 +19,11 @@ def test_config(): | |||
19 | assert result.returncode == 0 | 19 | assert result.returncode == 0 |
20 | assert 'general.color' in result.stdout | 20 | assert 'general.color' in result.stdout |
21 | 21 | ||
22 | |||
22 | def test_kle2json(): | 23 | def test_kle2json(): |
23 | assert check_subcommand('kle2json', 'kle.txt', '-f').returncode == 0 | 24 | assert check_subcommand('kle2json', 'kle.txt', '-f').returncode == 0 |
24 | 25 | ||
26 | |||
25 | def test_doctor(): | 27 | def test_doctor(): |
26 | result = check_subcommand('doctor') | 28 | result = check_subcommand('doctor') |
27 | assert result.returncode == 0 | 29 | assert result.returncode == 0 |