def __init__(self, main): # Current theme self.theme_key = '' self.default = 'solarized_lt' self.hsv = [0.00, 0.29, 0.35] # dark rose self.theme_contrast = 65 self.d = OrderedDict() self._ui_palette = None self._palette = None self._accent_palettes = {} self.current_hex = '' self.gradient = QtGui.QRadialGradient(0, 0, 300) self.gradient.setSpread(QtGui.QGradient.PadSpread) self.background_lightness = 0.5 self.custom = False # Theme management self.default_themes = color_themes self.custom_themes = OrderedDict() # Create some defaults self.activate_color_theme(self.default, try_to_remember=False) self.red = c(220, 50, 47) self.blue = c(38, 139, 210) # Keep an eye on relevant changes main.document_changed.connect(self.update_themes_and_colors_and_announce_it)
def compute_palette(self, hsv, contrast=55, faded=False): """ Create/get root color and build palette around it. :param hsv: Leaves custom colors as they are. """ self.hsv = hsv self.theme_contrast = contrast # # This is the base color ## key = c() key.setHsvF(*hsv) self.current_hex = key.name() r, g, b, a = key.getRgbF() h, s, l = rgb_to_husl(r, g, b) if l > 50: back_l = max(0, l - contrast) accent_l = min(l, 62) else: back_l = min(99, l + contrast) accent_l = max(45, l) background1 = c() bg_rgb = husl_to_rgb(h, s, back_l) background1.setRgbF(*bg_rgb) self.d['content1'] = key con2 = adjust_lightness(key, 8) con3 = adjust_lightness(key, -8) self.d['content2'] = con2 self.d['content3'] = con3 self.d['content1tr'] = shady(key, 0.5) self.d['content2tr'] = shady(con2, 0.5) self.d['content3tr'] = shady(con3, 0.5) for i, accent in enumerate(accents): # accent colors have the same luminence as key color adjusted_accent = c(accent) ar, ag, ab, aa = accent.getRgbF() ach, acs, acl = rgb_to_husl(ar, ag, ab) # if bw: # acs = 0 if faded: acs /= 2 ar, ag, ab = husl_to_rgb(ach, acs, accent_l) adjusted_accent.setRgbF(ar, ag, max(0, ab)) self.d['accent%s' % (i + 1)] = adjusted_accent self.d['accent%str' % (i + 1)] = shady(adjusted_accent, 0.5) self.d['background1'] = background1 if l < 0.7: background2 = adjust_lightness(background1, -8) else: background2 = adjust_lightness(background1, 8) self.d['background2'] = background2 self.gradient.setColorAt(1, self.d['background1']) self.gradient.setColorAt(0, self.d['background1'].lighter()) self.background_lightness = background1.lightnessF()
def get_color_name(self, color) -> str: """ Try to find the closest matching color from a dictionary of color names :param color: can be HSV(!) tuple, palette key (str) or QColor :return: """ if isinstance(color, (tuple, list)): cc = c() cc.setHsvF(color[0], color[1], color[2]) elif isinstance(color, str): cc = self.get(color) elif isinstance(color, QColor): cc = color else: log.critical('Unknown color: ', color) return 'unknown' if not cc: log.critical('Unknown color: ', color) return 'unknown' r, g, b, a = cc.getRgb() d_min = 100000 best = 0 for i, (name, hex, rgb) in enumerate(color_names): ir, ig, ib = rgb d = (r - ir) * (r - ir) + (g - ig) * (g - ig) + (b - ib) * (b - ib) if d < d_min: d_min = d best = i return color_names[best][0]
def compute_palette(self, hsv, contrast=55, faded=False): """ Create/get root color and build palette around it. :param hsv: Leaves custom colors as they are. """ self.hsv = hsv self.theme_contrast = contrast # # This is the base color ## key = c() key.setHsvF(*hsv) self.current_hex = key.name() r, g, b, a = key.getRgbF() h, s, l = rgb_to_husl(r, g, b) if l > 50: back_l = max(0, l - contrast) accent_l = min(l, 62) else: back_l = min(99, l + contrast) accent_l = max(45, l) background1 = c() bg_rgb = husl_to_rgb(h, s, back_l) background1.setRgbF(*bg_rgb) self.d['content1'] = key self.d['content2'] = adjust_lightness(key, 8) self.d['content3'] = adjust_lightness(key, -8) for i, accent in enumerate(accents): # accent colors have the same luminence as key color adjusted_accent = c(accent) ar, ag, ab, aa = accent.getRgbF() ach, acs, acl = rgb_to_husl(ar, ag, ab) # if bw: # acs = 0 if faded: acs /= 2 ar, ag, ab = husl_to_rgb(ach, acs, accent_l) adjusted_accent.setRgbF(ar, ag, max(0, ab)) self.d['accent%s' % (i + 1)] = adjusted_accent self.d['accent%str' % (i + 1)] = shady(adjusted_accent, 0.5) self.d['background1'] = background1 if l < 0.7: background2 = adjust_lightness(background1, -8) else: background2 = adjust_lightness(background1, 8) self.d['background2'] = background2 self.gradient.setColorAt(1, self.d['background1']) self.gradient.setColorAt(0, self.d['background1'].lighter()) self.background_lightness = background1.lightnessF()
def get(self, key, allow_none=False) -> QColor: """ Shortcut to palette dictionary (self.d) """ color = self.d.get(key, None) if color or allow_none: return color log.warning(f"Missing color '{key}'.") color = c(0, 0, 255) return color
def inactive(self, color) -> QColor: """ :param color: :return: """ nc = c(color) nc.setAlphaF(0.5) return nc
def get(self, key, allow_none=False) -> QColor: """ Shortcut to palette dictionary (self.d) """ color = self.d.get(key, None) if color or allow_none: return color log.critical(f"Missing color '{key}'.") color = c(0, 0, 255) self.set_color(key, color, can_save=False) return color
# base00 #657b83 11/7 bryellow 241 #626262 50 -07 -07 101 123 131 195 23 51 # base0 #839496 12/6 brblue 244 #808080 60 -06 -03 131 148 150 186 13 59 # base1 #93a1a1 14/4 brcyan 245 #8a8a8a 65 -05 -02 147 161 161 180 9 63 # base2 #eee8d5 7/7 white 254 #e4e4e4 92 -00 10 238 232 213 44 11 93 # base3 #fdf6e3 15/7 brwhite 230 #ffffd7 97 00 10 253 246 227 44 10 99 # yellow #b58900 3/3 yellow 136 #af8700 60 10 65 181 137 0 45 100 71 # orange #cb4b16 9/3 brred 166 #d75f00 50 50 55 203 75 22 18 89 80 # red #dc322f 1/1 red 160 #d70000 50 65 45 220 50 47 1 79 86 # magenta #d33682 5/5 magenta 125 #af005f 50 65 -05 211 54 130 331 74 83 # violet #6c71c4 13/5 brmagenta 61 #5f5faf 50 15 -45 108 113 196 237 45 77 # blue #268bd2 4/4 blue 33 #0087ff 55 -10 -45 38 139 210 205 82 82 # cyan #2aa198 6/6 cyan 37 #00afaf 60 -35 -05 42 161 152 175 74 63 # green #859900 2/2 green 64 #5f8700 60 -20 65 133 153 0 68 100 60 sol = [ c(0, 43, 54), c(7, 54, 66), c(88, 110, 117), c(101, 123, 131), c(131, 148, 150), c(147, 161, 161), c(238, 232, 213), c(253, 246, 227) ] accents = [ c(181, 137, 0), c(203, 75, 22), c(220, 50, 47), c(211, 54, 130), c(108, 113, 196), c(38, 139, 210),
# base01 #586e75 10/7 brgreen 240 #585858 45 -07 -07 88 110 117 194 25 46 # base00 #657b83 11/7 bryellow 241 #626262 50 -07 -07 101 123 131 195 23 51 # base0 #839496 12/6 brblue 244 #808080 60 -06 -03 131 148 150 186 13 59 # base1 #93a1a1 14/4 brcyan 245 #8a8a8a 65 -05 -02 147 161 161 180 9 63 # base2 #eee8d5 7/7 white 254 #e4e4e4 92 -00 10 238 232 213 44 11 93 # base3 #fdf6e3 15/7 brwhite 230 #ffffd7 97 00 10 253 246 227 44 10 99 # yellow #b58900 3/3 yellow 136 #af8700 60 10 65 181 137 0 45 100 71 # orange #cb4b16 9/3 brred 166 #d75f00 50 50 55 203 75 22 18 89 80 # red #dc322f 1/1 red 160 #d70000 50 65 45 220 50 47 1 79 86 # magenta #d33682 5/5 magenta 125 #af005f 50 65 -05 211 54 130 331 74 83 # violet #6c71c4 13/5 brmagenta 61 #5f5faf 50 15 -45 108 113 196 237 45 77 # blue #268bd2 4/4 blue 33 #0087ff 55 -10 -45 38 139 210 205 82 82 # cyan #2aa198 6/6 cyan 37 #00afaf 60 -35 -05 42 161 152 175 74 63 # green #859900 2/2 green 64 #5f8700 60 -20 65 133 153 0 68 100 60 sol = [c(0, 43, 54), c(7, 54, 66), c(88, 110, 117), c(101, 123, 131), c(131, 148, 150), c(147, 161, 161), c(238, 232, 213), c(253, 246, 227)] accents = [c(181, 137, 0), c(203, 75, 22), c(220, 50, 47), c(211, 54, 130), c(108, 113, 196), c(38, 139, 210), c(42, 161, 152), c(133, 153, 0)] color_themes = OrderedDict([('solarized_dk', { 'name': 'Solarized dark', 'hsv': [sol[3].hueF(), sol[3].saturationF(), sol[3].valueF()], 'build': 'solarized_dk' }), ('solarized_lt', { 'name': 'Solarized light', 'hsv': [sol[4].hueF(), sol[4].saturationF(), sol[4].valueF()], 'build': 'solarized_lt', }), ('random', { 'name': 'Random for each treeset',