def background_color(self, color): """ Sets the background color of this layer :param color: Desired background color """ self._bg_color = to_color(color)
def _observer(self, change): if self._refreshing or change.old == change.new: return self._logger.debug("LED settings changed: %s", change) if change.name == 'color': self._set(LED.Command.SET_LED_COLOR, to_color(change.new)) elif change.name == 'mode': self._set(LED.Command.SET_LED_MODE, change.new) elif change.name == 'brightness': self._set(LED.Command.SET_LED_BRIGHTNESS, scale_brightness(change.new)) if change.old == 0 and change.new > 0: self._set(LED.Command.SET_LED_STATE, 1) elif change.old > 0 and change.new == 0: self._set(LED.Command.SET_LED_STATE, 0) else: raise ValueError("Unknown LED property: %s" % change.new) if not self._restoring: self._refresh() if self.led_type != LEDType.BACKLIGHT: self._update_prefs()
def validate(self, obj, value): try: if value is not None: value = to_color(value) except: self.error(obj, value) return value
def color_block(*values): output = Colr('') for value in values: col = to_color(value) output = output.center(9, text=col.html, fore=ColorUtils.inverse(col).intTuple, back=col.intTuple) return str(output)
def get(self, row: int, col: int) -> Color: """ Get the color of an individual pixel :param row: Y coordinate of the pixel :param col: X coordinate of the pixel :return: Color of the pixel """ return to_color(tuple(self.matrix[row][col]))
def _get_rgb(self) -> list: with self.device_open(): bits = self._get_led_mode() if bits.color_count == 0: return None value = self.run_with_result(self._cmd_get_rgb[bits.color_count - 1]) if value is None: return None it = iter(value) values = list(iter(zip(it, it, it, it))) return [to_color(x) for x in values]
def _set_rgb(self, *colors, brightness: float = None) -> bool: if colors is None or len(colors) == 0: self.logger.error('RGB group out of range') return False # only allow what the hardware permits colors = colors[0:len(self._cmd_set_rgb)] with self.device_open(): if brightness is None: brightness = self._get_brightness() if brightness == 0.0: brightness = 80.0 brightness = scale_brightness(brightness) args = [] for color in colors: args.append(to_color(color)) args.append(brightness) return self.run_command(self._cmd_set_rgb[len(colors) - 1], *args)