def colors(self): if self._colors is None: if "colors" in self.attributes: col1, col2, black = self.attributes["colors"] self._colors = (hex_to_color(col1), hex_to_color(col2), black) else: self._colors = ((0, 0, 255), (255, 255, 0), False) return self._colors
def colors(self): if self._colors is None: try: col1, col2, black = self.attributes["colors"] self._colors = (hex_to_color(col1), hex_to_color(col2), black) except (KeyError, ValueError): # Stored colors were not available or invalid, use defaults self._colors = ((0, 0, 255), (255, 255, 0), False) return self._colors
def colors(self): if self._colors is not None: return self._colors try: col1, col2, black = self.attributes["colors"] return (hex_to_color(col1), hex_to_color(col2), black) except (KeyError, ValueError): # User-provided colors were not available or invalid return ((0, 0, 255), (255, 255, 0), False)
def from_dict(cls, var, data): def _check_dict_str_str(d): if not isinstance(d, dict) or \ not all(isinstance(val, str) for val in chain(d, d.values())): raise InvalidFileFormat obj, warnings = super().from_dict(var, data) val_map = data.get("renamed_values") if val_map is not None: _check_dict_str_str(val_map) mapped_values = [val_map.get(value, value) for value in var.values] if len(set(mapped_values)) != len(mapped_values): warnings.append( f"{var.name}: " "renaming of values ignored due to duplicate names") else: obj.new_values = mapped_values new_colors = data.get("colors") if new_colors is not None: _check_dict_str_str(new_colors) colors = [] for value, def_color in zip(var.values, var.palette.palette): if value in new_colors: try: color = hex_to_color(new_colors[value]) except ValueError as exc: raise InvalidFileFormat from exc colors.append(color) else: colors.append(def_color) obj.new_colors = colors return obj, warnings
def colors(self): if self._colors is None: from Orange.widgets.utils.colorpalette import ColorPaletteGenerator self._colors = ColorPaletteGenerator.palette(self) colors = self.attributes.get('colors') if colors: self._colors[:len(colors)] = [hex_to_color(color) for color in colors] self._colors.flags.writeable = False return self._colors
def colors(self): if self._colors is None: if "colors" in self.attributes: self._colors = np.array([hex_to_color(col) for col in self.attributes["colors"]], dtype=np.uint8) else: from Orange.widgets.utils.colorpalette import ColorPaletteGenerator self._colors = ColorPaletteGenerator.palette(self) self._colors.flags.writeable = False return self._colors
def colors(self): if self._colors is None: if "colors" in self.attributes: self._colors = np.array( [hex_to_color(col) for col in self.attributes["colors"]], dtype=np.uint8) else: from Orange.widgets.utils.colorpalette import \ ColorPaletteGenerator self._colors = ColorPaletteGenerator.palette(self) self._colors.flags.writeable = False return self._colors
def colors(self): if self._colors is not None: colors = np.array(self._colors) elif not self.values: colors = np.zeros((0, 3)) # to match additional colors in vstacks else: from Orange.widgets.utils.colorpalette import ColorPaletteGenerator default = tuple(ColorPaletteGenerator.palette(self)) colors = self.attributes.get('colors', ()) colors = tuple(hex_to_color(color) for color in colors) \ + default[len(colors):] colors = np.array(colors) colors.flags.writeable = False return colors