Skip to content

Commit

Permalink
Merge pull request #10 from dfredell/master
Browse files Browse the repository at this point in the history
Add a --steady command line arg
  • Loading branch information
Askannz authored Nov 18, 2018
2 parents 2e6b6bf + 95a010f commit 9c9ca11
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,6 @@ venv.bak/

# mypy
.mypy_cache/

# IntelliJ IDE project settings
.idea/
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
21 changes: 20 additions & 1 deletion msi_perkeyrgb/config.py
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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 = {}
Expand Down
29 changes: 19 additions & 10 deletions msi_perkeyrgb/msi_perkeyrgb.py → msi_perkeyrgb/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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__':
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']},
Expand Down

0 comments on commit 9c9ca11

Please sign in to comment.