(setting_info, colors)
return merge_bytes(header, body)
Called by the :class:`rivalcfg.mouse.Mouse` class when processing a
    "rgbgradient" type setting.

    :param dict setting_info: The information dict of the setting from the
                              device profile.
    :param str,tuple,list,dict colors: The color(s).
    :rtype: [int]
Called by the :class:`rivalcfg.mouse.Mouse` class when processing a
    "rgbgradient" type setting.
Called by the : class : rivalcfg . mouse . Mouse class when processing a rgbgradient type setting .
def process_value(setting_info, colors):
    """Called by the :class:`rivalcfg.mouse.Mouse` class when processing a
    "rgbgradient" type setting.

    :param dict setting_info: The information dict of the setting from the
                              device profile.
    :param str,tuple,list,dict colors: The color(s).
    :rtype: [int]
    """
    header_length = setting_info["rgbgradient_header"]["header_length"]
    led_id_offsets = setting_info["rgbgradient_header"]["led_id_offsets"]
    duration_offset = setting_info["rgbgradient_header"]["duration_offset"]
    duration_length = setting_info["rgbgradient_header"]["duration_length"]
    repeat_offset = setting_info["rgbgradient_header"]["repeat_offset"]
    triggers_offset = setting_info["rgbgradient_header"]["triggers_offset"]
    color_count_offset = setting_info["rgbgradient_header"]["color_count_offset"]

    is_gradient = False
    duration = _default_duration
    repeat = 0x00
    triggers = 0x00
    led_id = setting_info["led_id"]
    gradient = []

    # Color tuple
    if type(colors) in (tuple, list):
        is_gradient = False
        gradient = _handle_color_tuple(colors)

    # Simple color string
    elif type(colors) in [str, _unicode_type] and is_color(colors):
        is_gradient = False
        gradient = _handle_color_string(colors)

    # Color gradient as dict
    elif type(colors) is dict:
        is_gradient = True
        duration, gradient = _handle_rgbgradient_dict(colors)

    # Color gradient as string
    elif is_rgbgradient(colors)[0]:
        is_gradient = True
        duration, gradient = _handle_rgbgradient_string(colors)
    else:
        raise ValueError("Not a valid color or rgbgradient %s" % str(colors))

    # -- handle repeat flag

    if not is_gradient or triggers != 0x00:
        repeat = 0x01

    # -- Check

    if len(gradient) == 0:
        raise ValueError("no color: %s" % str(colors))

    if len(gradient) > 14:
        raise ValueError("a maximum of 14 color stops are allowed")

    # TODO check pos orders

    # -- Generate header

    header = [0x00] * header_length
    header[repeat_offset] = repeat
    header[triggers_offset] = triggers
    header[color_count_offset] = len(gradient)

    for led_id_offset in led_id_offsets:
        header[led_id_offset] = led_id

    offset = 0
    for b in uint_to_little_endian_bytearray(duration, duration_length):
        header[duration_offset + offset] = b
        offset += 1

    # -- Generate body

    body = list(gradient[0]["color"])

    last_real_pos = 0
    for pos, color in [(item["pos"], item["color"]) for item in gradient]:
        real_pos = int(pos * 255 / 100)
        body = merge_bytes(body, color, real_pos - last_real_pos)
        last_real_pos = real_pos

    # --

    return merge_bytes(header, body)
def process_value ( setting_info , colors ) : header_length = setting_info [ "rgbgradient_header" ] [ "header_length" ] led_id_offsets = setting_info [ "rgbgradient_header" ] [ "led_id_offsets" ] duration_offset = setting_info [ "rgbgradient_header" ] [ "duration_offset" ] duration_length = setting_info [ "rgbgradient_header" ] [ "duration_length" ] repeat_offset = setting_info [ "rgbgradient_header" ] [ "repeat_offset" ] triggers_offset = setting_info [ "rgbgradient_header" ] [ "triggers_offset" ] color_count_offset = setting_info [ "rgbgradient_header" ] [ "color_count_offset" ] is_gradient = False duration = _default_duration repeat = 0x00 triggers = 0x00 led_id = setting_info [ "led_id" ] gradient = [ ] # Color tuple if type ( colors ) in ( tuple , list ) : is_gradient = False gradient = _handle_color_tuple ( colors ) # Simple color string elif type ( colors ) in [ str , _unicode_type ] and is_color ( colors ) : is_gradient = False gradient = _handle_color_string ( colors ) # Color gradient as dict elif type ( colors ) is dict : is_gradient = True duration , gradient = _handle_rgbgradient_dict ( colors ) # Color gradient as string elif is_rgbgradient ( colors ) [ 0 ] : is_gradient = True duration , gradient = _handle_rgbgradient_string ( colors ) else : raise ValueError ( "Not a valid color or rgbgradient %s" % str ( colors ) ) # -- handle repeat flag if not is_gradient or triggers != 0x00 : repeat = 0x01 # -- Check if len ( gradient ) == 0 : raise ValueError ( "no color: %s" % str ( colors ) ) if len ( gradient ) > 14 : raise ValueError ( "a maximum of 14 color stops are allowed" ) # TODO check pos orders # -- Generate header header = [ 0x00 ] * header_length header [ repeat_offset ] = repeat header [ triggers_offset ] = triggers header [ color_count_offset ] = len ( gradient ) for led_id_offset in led_id_offsets : header [ led_id_offset ] = led_id offset = 0 for b in uint_to_little_endian_bytearray ( duration , duration_length ) : header [ duration_offset + offset ] = b offset += 1 # -- Generate body body = list ( gradient [ 0 ] [ "color" ] ) last_real_pos = 0 for pos , color in [ ( item [ "pos" ] , item [ "color" ] ) for item in gradient ] : real_pos = int ( pos * 255 / 100 ) body = merge_bytes ( body , color , real_pos - last_real_pos ) last_real_pos = real_pos # -- return merge_bytes ( header , body )