Skip to content

Commit

Permalink
Merge pull request #23 from LoLei/brightness
Browse files Browse the repository at this point in the history
Brightness
  • Loading branch information
LoLei authored Apr 9, 2020
2 parents b921b91 + aedbfee commit bad33b4
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 11 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ this tool will set your Razer colors to Pywal's colors. See below for more
information.

## Installation
```bash
pip install razer-cli
```
[`pip install razer-cli`](https://pypi.org/project/razer-cli/)

## Usage
```bash
```
$ razer-cli -h
usage: razer-cli [-h] [-e EFFECT] [-v] [-c COLOR [COLOR ...]] [-l] [-ll] [-a]
[-d DEVICE [DEVICE ...]] [--dpi DPI]
[-d DEVICE [DEVICE ...]] [--dpi DPI] [-b BRIGHTNESS]
optional arguments:
-h, --help show this help message and exit
Expand All @@ -40,6 +38,8 @@ optional arguments:
-d DEVICE [DEVICE ...], --device DEVICE [DEVICE ...]
only affect these devices, same name as output of -l
--dpi DPI set DPI of device
-b BRIGHTNESS, --brightness BRIGHTNESS
set brightness of device
```
<sup>This might be out of date, just run it with `-h` yourself to see the newest
options.</sup>
Expand Down Expand Up @@ -95,4 +95,4 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
49 changes: 46 additions & 3 deletions razer_cli/razer_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""

__author__ = "Lorenz Leitner"
__version__ = "1.1"
__version__ = "1.2"
__license__ = "GPL-3.0"

# Libraries
Expand Down Expand Up @@ -97,6 +97,8 @@ def list_devices(device_manager):
if (device.type == "mouse"):
print(" DPI: {}".format(device.dpi))
print(" max DPI: {}".format(device.max_dpi))
if device.capabilities['brightness']:
print(" brightness: {}".format(device.brightness))
print(" serial: {}".format(device.serial))
print(" firmware version: {}".format(device.firmware_version))
print(" driver version: {}".format(device.driver_version))
Expand All @@ -108,6 +110,7 @@ def list_devices(device_manager):
print(" capabilities: {}".format(device.capabilities))
print()


def set_dpi(device_manager):
# Iterate over each device and set DPI
for device in device_manager.devices:
Expand All @@ -128,6 +131,38 @@ def set_dpi(device_manager):
dpi_to_use = int(args.dpi)
device.dpi = (dpi_to_use, dpi_to_use)


def set_brightness(device_manager):
# Iterate over each device and set DPI
for device in device_manager.devices:
# If -d argument is set, only set those devices
if (args.device and device.name in args.device) or (not args.device):
if args.verbose:
print("Setting brightness of device {} to {}".
format(device.name, args.brightness))

# Save used settings for this device to a file
util.write_settings_to_file(device, brightness=args.brightness)

# Don't store it initially as int with type=int in argparse
# because then the if arg.brightness will fail if it is 0
brightness = int(args.brightness)

# Actually set brightness
if device.capabilities['brightness']:
device.brightness = brightness

# Mouse most likely doesn't have overall brightness
if device.capabilities['lighting_logo_brightness']:
device.fx.misc.logo.brightness = brightness
if device.capabilities['lighting_scroll_brightness']:
device.fx.misc.scroll_wheel.brightness = brightness
if device.capabilities['lighting_left_brightness']:
device.fx.misc.left.brightness = brightness
if device.capabilities['lighting_right_brightness']:
device.fx.misc.right.brightness = brightness


def reset_device_effect(device):
# Set the effect to static, requires colors in 0-255 range
try:
Expand Down Expand Up @@ -228,7 +263,7 @@ def read_args():
help="increase output verbosity",
action="store_true")

parser.add_argument("-c","--color", nargs="+",
parser.add_argument("-c", "--color", nargs="+",
help="choose color (default: X color1), use one argument "
"for hex, or three for base10 rgb")

Expand All @@ -253,6 +288,11 @@ def read_args():
help="set DPI of device",
action="store")

parser.add_argument("-b", "--brightness",
help="set brightness of device",
dest='brightness',
action="store")

global args
args = parser.parse_args()

Expand Down Expand Up @@ -289,10 +329,13 @@ def main():
# Do below only if dry run is not specified
if args.automatic or args.effect or args.color:
set_effect_to_all_devices(device_manager, args.effect, color)

if args.dpi:
set_dpi(device_manager)

if args.brightness:
set_brightness(device_manager)


if __name__ == "__main__":
""" This is executed when run from the command line - obsolete """
Expand Down
6 changes: 5 additions & 1 deletion razer_cli/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def hex_to_decimal(hex_color):

return r, g, b

def write_settings_to_file(device, effect="", color="", dpi=""):
def write_settings_to_file(device, effect="", color="", dpi="", brightness=""):
""" Save settings to a file for possible later retrieval """

home_dir = os.path.expanduser("~")
Expand Down Expand Up @@ -38,6 +38,8 @@ def write_settings_to_file(device, effect="", color="", dpi=""):
item['effect'] = effect
if (dpi != ""):
item['dpi'] = dpi
if (brightness != ""):
item['brightness'] = brightness

# Update existing entry
if found_existing_settings:
Expand All @@ -54,6 +56,8 @@ def write_settings_to_file(device, effect="", color="", dpi=""):
used_settings['effect'] = effect
if (dpi != ""):
used_settings['dpi'] = dpi
if (brightness != ""):
used_settings['brightness'] = brightness
with open(path_and_file, mode='w') as file:
json_data.append(used_settings)
json.dump(json_data, file, indent=2)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="razer-cli",
version="1.1",
version="1.2",
author="Lorenz Leitner",
author_email="[email protected]",
description="Control Razer devices from the command line",
Expand Down

0 comments on commit bad33b4

Please sign in to comment.