def __init__(self, prefs, datapath): """Initialises with default colors and an empty adjuster list. :param prefs: Prefs dict for saving settings. :param datapath: Base path for saving palettes and masks. """ super(ColorManager, self).__init__() # Defaults self._color = None #: Currently edited color, a UIColor object self._hist = [] #: List of previous colors, most recent last self._palette = None #: Current working palette self._adjusters = weakref.WeakSet() #: The set of registered adjusters #: Cursor for pickers # FIXME: Use Gdk.Cursor.new_for_display() self._picker_cursor = Gdk.Cursor.new(Gdk.CursorType.CROSSHAIR) self._datapath = datapath #: Base path for saving palettes and masks self._hue_distorts = None #: Hue-remapping table for color wheels self._prefs = prefs #: Shared preferences dictionary # Build the history. Last item is most recent. hist_hex = list(prefs.get(PREFS_KEY_COLOR_HISTORY, [])) hist_hex = self._DEFAULT_HIST + hist_hex self._hist = [RGBColor.new_from_hex_str(s) for s in hist_hex] self._trim_hist() # Restore current color, or use the most recent color. col_hex = prefs.get(PREFS_KEY_CURRENT_COLOR, None) if col_hex is None: col_hex = hist_hex[-1] self._color = RGBColor.new_from_hex_str(col_hex) # Initialize angle distort table wheel_type = prefs.get(PREFS_KEY_WHEEL_TYPE, self._DEFAULT_WHEEL_TYPE) distorts_table = self._HUE_DISTORTION_TABLES[wheel_type] self._hue_distorts = distorts_table # Initialize working palette palette_dict = prefs.get(PREFS_PALETTE_DICT_KEY, None) if palette_dict is not None: palette = Palette.new_from_simple_dict(palette_dict) else: datapath = self.get_data_path() palettes_dir = os.path.join(datapath, DATAPATH_PALETTES_SUBDIR) default = os.path.join(palettes_dir, DEFAULT_PALETTE_FILE) palette = Palette(filename=default) self._palette = palette # Capture updates to the working palette palette.info_changed += self._palette_changed_cb palette.match_changed += self._palette_changed_cb palette.sequence_changed += self._palette_changed_cb palette.color_changed += self._palette_changed_cb
def __init__(self, prefs, datapath): """Initialises with default colors and an empty adjuster list. :param prefs: Prefs dict for saving settings. :param datapath: Base path for saving palettes and masks. """ super(ColorManager, self).__init__() # Defaults self._color = None #: Currently edited color, a UIColor object self._hist = [] #: List of previous colors, most recent last self._palette = None #: Current working palette self._adjusters = weakref.WeakSet() #: The set of registered adjusters #: Cursor for pickers # FIXME: Use Gdk.Cursor.new_for_display() self._picker_cursor = Gdk.Cursor.new(Gdk.CursorType.CROSSHAIR) self._datapath = datapath #: Base path for saving palettes and masks self._hue_distorts = None #: Hue-remapping table for color wheels self._prefs = prefs #: Shared preferences dictionary # Build the history. Last item is most recent. hist_hex = list(prefs.get(PREFS_KEY_COLOR_HISTORY, [])) hist_hex = self._DEFAULT_HIST + hist_hex self._hist = [RGBColor.new_from_hex_str(s) for s in hist_hex] self._trim_hist() # Restore current color, or use the most recent color. col_hex = prefs.get(PREFS_KEY_CURRENT_COLOR, None) if col_hex is None: col_hex = hist_hex[-1] self._color = RGBColor.new_from_hex_str(col_hex) # Initialize angle distort table wheel_type = prefs.get(PREFS_KEY_WHEEL_TYPE, self._DEFAULT_WHEEL_TYPE) distorts_table = self._HUE_DISTORTION_TABLES[wheel_type] self._hue_distorts = distorts_table # Initialize working palette palette_dict = prefs.get(PREFS_PALETTE_DICT_KEY, None) if palette_dict is not None: palette = Palette.new_from_simple_dict(palette_dict) else: datapath = self.get_data_path() palettes_dir = os.path.join(datapath, DATAPATH_PALETTES_SUBDIR) default = os.path.join(palettes_dir, DEFAULT_PALETTE_FILE) palette = Palette(filename=default) self._palette = palette # Capture updates to the working palette palette.info_changed += self._palette_changed_cb palette.match_changed += self._palette_changed_cb palette.sequence_changed += self._palette_changed_cb palette.color_changed += self._palette_changed_cb
def new_from_simple_dict(class_, simple): """Constructs and returns a palette from the simple dict form.""" pal = class_() pal.set_name(simple.get("name", None)) pal.set_columns(simple.get("columns", None)) for entry in simple.get("entries", []): if entry is None: pal.append(None) else: s, name = entry col = RGBColor.new_from_hex_str(s) pal.append(col, name) return pal
def new_from_simple_dict(cls, simple): """Constructs and returns a palette from the simple dict form.""" pal = cls() pal.set_name(simple.get("name", None)) pal.set_columns(simple.get("columns", None)) for entry in simple.get("entries", []): if entry is None: pal.append(None) else: s, name = entry col = RGBColor.new_from_hex_str(s) pal.append(col, name) return pal
def _unflatten_mask(flat_mask): mask = [] for shape_flat in flat_mask: shape_colors = [RGBColor.new_from_hex_str(s) for s in shape_flat] mask.append(shape_colors) return mask
# Transient on-canvas information, intended to be read quickly. # Used for fading textual info or vanishing positional markers. # Need to be high-contrast, and clear. Black and white is good. TRANSIENT_INFO_BG_RGBA = (0, 0, 0, 0.666) #: Transient text bg / outline TRANSIENT_INFO_RGBA = (1, 1, 1, 1) #: Transient text / marker # Editable on-screen items. # Used for editable handles on things like the document frame, # when it's being edited. # It's a good idea to use this and a user-tuneable alpha if the item # is to be shown on screen permanently, in modes other than the object's # own edit mode. EDITABLE_ITEM_COLOR = RGBColor.new_from_hex_str("#ECF0F1") # Active/dragging state for editable items. ACTIVE_ITEM_COLOR = RGBColor.new_from_hex_str("#F1C40F") # Prelight color (for complex modes, when there needs to be a distinction) PRELIT_ITEM_COLOR = tuple( ACTIVE_ITEM_COLOR.interpolate(EDITABLE_ITEM_COLOR, 3) )[1]
def _unflatten_mask(flat_mask): mask = [] for shape_flat in flat_mask: shape_colors = [RGBColor.new_from_hex_str(s) for s in shape_flat] mask.append(shape_colors) return mask
DROP_SHADOW_BLUR = 2.0 DROP_SHADOW_X_OFFSET = 0.25 DROP_SHADOW_Y_OFFSET = 1.0 # These are only used for otherwise flat editable or draggable objects. ## Colors for additonal on-canvas information # Transient on-canvas information, intended to be read quickly. # Used for fading textual info or vanishing positional markers. # Need to be high-contrast, and clear. Black and white is good. TRANSIENT_INFO_BG_RGBA = (0, 0, 0, 0.666) #: Transient text bg / outline TRANSIENT_INFO_RGBA = (1, 1, 1, 1) #: Transient text / marker # Passive position markers. # Used for inactive but permanent marks that convey useful information, # like the symmetry axis while it's not being edited. # These need to be non-distracting. PASSIVE_ITEM_COLOR = RGBColor.new_from_hex_str("#BDC3C7") # Editable on-screen items. # Used for editable handles on things like the document frame, # when it's being edited. EDITABLE_ITEM_COLOR = RGBColor.new_from_hex_str("#ECF0F1") # Prelit/active/dragging state for editable icons ACTIVE_ITEM_COLOR = RGBColor.new_from_hex_str("#F1C40F")