rgbgradient

The “rgbgradientv2” type handles RGB color gradients. Simple RGB color can also be used.

RGB gradient syntax example:

rgbgradient(duration=1000; colors=0%: #ff0000, 33%: #00ff00, 66%: #0000ff)
rgbgradient(colors=0%: red, 33%: lime, 66%: blue)

It supports both hexadecimal colors:

  • #FF0000

  • FF0000

  • #F00

  • F00

and named colors:

white

red

lime

blue

silver

maroon

green

navy

gray

yellow

aqua

fuchsia

black

olive

teal

purple


A Python dict can also be used (Python API only):

{
    "duration": 1000,  # ms
    "colors": [
        {"pos": 0, "color": "red"},
        {"pos": 33, "color": "#00FF00"},
        {"pos": 66, "color": (0, 0, 255)},
    ]
}

Note

A maximum of 14 color stops can be defined in a gradient.

Device Profile

Example of a rgbgradient value type in a device profile:

profile = {

    # ...

    "settings": {

        "logo_color": {
            "label": "Logo LED colors and effects",
            "description": "Set the colors and the effects of the logo LED",
            "cli": ["-c", "--logo-color"],
            "report_type": usbhid.HID_REPORT_TYPE_FEATURE,
            "command": [0x05, 0x00],
            "value_type": "rgbgradient",
            "rgbgradient_header": {
                "header_length": 28,       # Length of the header excuding command / LED ID
                "led_id_offsets": [0, 5],  # Offset of the "led_id" fields
                "duration_offset": 6,      # Offset of the "duration" field
                "duration_length": 2,      # Length of the "duration" field (in Bytes)
                "repeat_offset": 22,       # Offset of the "repeat" flag
                "triggers_offset": 23,     # Offset of the "triggers" field (buttons mask)
                "color_count_offset": 27,  # Offset of the "color_count" field
            },
            "led_id": 0x01,
            "default": "rgbgradient(duration=1000; colors=0%: #ff0000, 33%: #00ff00, 66%: #0000ff)",
        },

    },

    # ...

}

CLI

Example of CLI option generated with this handler:

-c LOGO_COLOR, --logo-color LOGO_COLOR
                      Set the colors and the effects of the logo LED (default:
                      rgbgradient(duration=1000; colors=0%: #ff0000, 33%: #00ff00, 66%: #0000ff))

Example of CLI usage:

rivalcfg --logo-color="rgbgradient(duration=1000; colors=0%: #ff0000, 33%: #00ff00, 66%: #0000ff)"
rivalcfg --logo-color=red
rivalcfg --logo-color=FF1800

Functions

class rivalcfg.handlers.rgbgradient.CheckGradientAction(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None, deprecated=False)

Validate colors gradient from CLI

rivalcfg.handlers.rgbgradient.add_cli_option(cli_parser, setting_name, setting_info)

Add the given “rgbgradient” type setting to the given CLI arguments parser.

Parameters:
  • cli_parser (ArgumentParser) – An ArgumentParser instance.

  • setting_name (str) – The name of the setting.

  • setting_info (dict) – The information dict of the setting from the device profile.

rivalcfg.handlers.rgbgradient.is_rgbgradient(string)

Check if the rgbradient expression is valid.

Parameters:

string (str) – The string to validate.

Return type:

(bool, str)

>>> is_rgbgradient("foo(colors=0:red)")
(False, "... It must looks like 'rgbgradient(<PARAMS>)'...")
>>> is_rgbgradient("rgbgradient(duration=1000)")
(False, "... You must provide at least one color: ...")
>>> is_rgbgradient("rgbgradient(colors=red)")
(False, "invalid color gradient...")
>>> is_rgbgradient("rgbgradient(colors=0:red; foo=bar)")
(False, "unknown parameter 'foo'...")
rivalcfg.handlers.rgbgradient.process_value(setting_info, colors)

Called by the rivalcfg.mouse.Mouse class when processing a “rgbgradient” type setting.

Parameters:
  • setting_info (dict) – The information dict of the setting from the device profile.

  • colors (str,tuple,list,dict) – The color(s).

Return type:

[int]