From f9ec857a0930bca961e5a8b7aa657480d0671d05 Mon Sep 17 00:00:00 2001 From: dfredell Date: Sat, 17 Nov 2018 11:10:56 -0600 Subject: [PATCH 1/3] Add a --steady command line arg so a config file isn't required for a simple setting. --- README.md | 4 ++++ msi_perkeyrgb/config.py | 21 ++++++++++++++++++++- msi_perkeyrgb/msi_perkeyrgb.py | 29 +++++++++++++++++++---------- 3 files changed, 43 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 3b787c9..1f470c0 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ Command-line options ``` usage: msi-perkeyrgb [-h] [-v] [-c FILEPATH] [-d] [--id VENDOR_ID:PRODUCT_ID] [--list-presets] [-p PRESET] [-m MODEL] [--list-models] + [-s HEXCOLOR] Tool to control per-key RGB keyboard backlighting on MSI laptops. https://github.com/Askannz/msi-perkeyrgb @@ -53,6 +54,9 @@ optional arguments: Set laptop model (see --list-models). If not specified, will use GE63 as default. --list-models List available laptop models. + -s HEXCOLOR, --steady HEXCOLOR + Set all of the keyboard to a steady html color, + ex. 00ff00 for green ``` Features diff --git a/msi_perkeyrgb/config.py b/msi_perkeyrgb/config.py index 970a00b..c77fa29 100644 --- a/msi_perkeyrgb/config.py +++ b/msi_perkeyrgb/config.py @@ -1,6 +1,7 @@ import re -ALIASES = {"all": "9-133,fn", +ALIAS_ALL = "all" +ALIASES = {ALIAS_ALL: "9-133,fn", "f_row": "67-76,95,96", "arrows": "111,113,114,116", "num_row": "10-21", @@ -48,6 +49,24 @@ def load_config(config_path, msi_keymap): return config_map +def load_steady(color, msi_keymap): + """Setup the key map to be all a steady color + """ + colors_map = {} + warnings = [] + + try: + keycodes = parse_keycodes(msi_keymap, ALIAS_ALL) + color = parse_color(color) + except LineParseError as e: + raise ConfigParseError("Color parse error %s" % str(e)) from e + pass + else: + colors_map = update_colors_map(colors_map, keycodes, color) + + return colors_map, warnings + + def parse_config(f, msi_keymap): colors_map = {} diff --git a/msi_perkeyrgb/msi_perkeyrgb.py b/msi_perkeyrgb/msi_perkeyrgb.py index 3d4dc10..655a89d 100755 --- a/msi_perkeyrgb/msi_perkeyrgb.py +++ b/msi_perkeyrgb/msi_perkeyrgb.py @@ -2,7 +2,7 @@ import sys import argparse -from msi_perkeyrgb.config import load_config, ConfigError +from msi_perkeyrgb.config import load_config, load_steady, ConfigError from msi_perkeyrgb.parsing import parse_model, parse_usb_id, parse_preset, UnknownModelError, UnknownIdError, UnknownPresetError from msi_perkeyrgb.msi_keyboard import MSI_Keyboard, AVAILABLE_MSI_KEYMAPS from msi_perkeyrgb.hidapi_wrapping import HIDLibraryError, HIDNotFoundError, HIDOpenError @@ -22,6 +22,7 @@ def main(): parser.add_argument('-p', '--preset', action='store', help='Use vendor preset (see --list-presets).') parser.add_argument('-m', '--model', action='store', help='Set laptop model (see --list-models). If not specified, will use %s as default.' % DEFAULT_MODEL) parser.add_argument('--list-models', action='store_true', help='List available laptop models.') + parser.add_argument('-s', '--steady', action='store', metavar='HEXCOLOR', help='Set all of the keyboard to a steady html color. ex. 00ff00 for green') args = parser.parse_args() @@ -50,15 +51,13 @@ def main(): # Parse USB vendor/product ID if not args.id: - id_str = DEFAULT_ID + usb_id = parse_usb_id(DEFAULT_ID) else: - id_str = args.id - - try: - usb_id = parse_usb_id(id_str) - except UnknownIdError: - print("Unknown vendor/product ID : %s" % usb_id) - sys.exit(1) + try: + usb_id = parse_usb_id(args.id) + except UnknownIdError: + print("Unknown vendor/product ID : %s" % args.id) + sys.exit(1) # Loading presets msi_presets = MSI_Keyboard.get_model_presets(msi_model) @@ -122,9 +121,19 @@ def main(): kb.set_colors(colors_map) kb.refresh() + # If user has requested to display a steady color + elif args.steady: + try: + colors_map, warnings = load_steady(args.steady, msi_keymap) + except ConfigError as e: + print("Error preparing steady color : %s" % str(e)) + sys.exit(1) + kb.set_colors(colors_map) + kb.refresh() + # If user has not requested anything else: - print("Nothing to do ! Please specify a preset or a config file.") + print("Nothing to do ! Please specify a preset, steady, or a config file.") if __name__ == '__main__': From 585ace58fd53a7880a3b39cf7c9dc69eb01ac9e6 Mon Sep 17 00:00:00 2001 From: dfredell Date: Sat, 17 Nov 2018 11:11:57 -0600 Subject: [PATCH 2/3] Rename msi_perkeyrgb.py to main.py so the file name isn't the same as the package which caused Python to get confused. --- msi_perkeyrgb/{msi_perkeyrgb.py => main.py} | 0 setup.py | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename msi_perkeyrgb/{msi_perkeyrgb.py => main.py} (100%) diff --git a/msi_perkeyrgb/msi_perkeyrgb.py b/msi_perkeyrgb/main.py similarity index 100% rename from msi_perkeyrgb/msi_perkeyrgb.py rename to msi_perkeyrgb/main.py diff --git a/setup.py b/setup.py index 43aae16..533e7af 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ packages=['msi_perkeyrgb'], entry_points={ 'console_scripts': [ - 'msi-perkeyrgb=msi_perkeyrgb.msi_perkeyrgb:main', + 'msi-perkeyrgb=msi_perkeyrgb.main:main', ], }, package_data={'msi_perkeyrgb': ['presets/*.json']}, From 95a010f4a79a6e4e58930385c7bb525377b6b979 Mon Sep 17 00:00:00 2001 From: dfredell Date: Sat, 17 Nov 2018 11:13:29 -0600 Subject: [PATCH 3/3] Add IntelliJ IDE's project folder to the gitignore file --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 894a44c..f92de09 100644 --- a/.gitignore +++ b/.gitignore @@ -102,3 +102,6 @@ venv.bak/ # mypy .mypy_cache/ + +# IntelliJ IDE project settings +.idea/