def __init__(self, colors=None, **kwargs): self.colorNames = set( ) # Collect the total set of installed color names. # Set lighter/darker factors from arguments or default self.factorDarkest = kwargs.get('darkest', self.FACTOR_DARKEST) self.factorDarker = kwargs.get('darker', self.FACTOR_DARKER) self.factorDark = kwargs.get('dark', self.FACTOR_DARK) self.factorLight = kwargs.get('light', self.FACTOR_LIGHT) self.factorLightest = kwargs.get('lightest', self.FACTOR_LIGHTEST) self.factorLighter = kwargs.get('lighter', self.FACTOR_LIGHTER) # Install default colors self.addColors(self.BASE_COLORS) if colors is not None: self.addColors(colors) relatedColors = dict(logoLight=spotColor(165).lighter(), logoDark=spotColor(165).darker(), supporter1=self.BASE_COLOR.darker(0.75), supporter2=self.BASE_COLOR.lighter(0.75)) for n in range(self.NUM_BASE): base = self['base%d' % n] relatedColors['darker%d' % n] = base.darker(self.factorDarker) relatedColors['dark%d' % n] = base.darker(self.factorDark) relatedColors['darkest%d' % n] = base.darker(self.factorDarkest) relatedColors['lighter%d' % n] = base.lighter(self.factorLighter) relatedColors['light%d' % n] = base.lighter(self.factorLight) relatedColors['lightest%d' % n] = base.lighter(self.factorLightest) #relatedColors['warmer%d' % n] = base.warmer(self.LEAST) #relatedColors['warm%d' % n] = base.warmer(self.MIDDLE) #relatedColors['warmest%d' % n] = base.warmer(self.MOST) #relatedColors['cooler%d' % n] = base.cooler(self.LEAST) #relatedColors['cool%d' % n] = base.cooler(self.MIDDLE) #relatedColors['coolest%d' % n] = base.cooler(self.MOST) self.addColors(relatedColors, overwrite=False)
class FreshAndShiny(BaseTheme): """The FreshAndShiny theme is ... """ """ >>> theme = FreshAndShiny() >>> theme.mood['h1.color'] 'hilite2' >>> theme.selectMood('dark') # Select another mode >>> theme.mood['h1.color'] 'hilite2' """ NAME = 'Fresh and Shiny' BASE_COLORS = dict( base0=spotColor('coolgray11u'), base1=spotColor('rhodamineredu'), base2=spotColor(265), base3=spotColor(3005), base4=spotColor(375), # Supporter1 base5=rgbColor('red'),#spotColor('red032u'), )
class SomethingInTheAir(BaseTheme): """The SomethingInTheAir theme is ...""" NAME = 'Something in the Air' BASE_COLORS = dict( base0=spotColor('reflexblueu'), base1=spotColor(540), base2=spotColor(542), base3=spotColor(306), base4=spotColor(245), # Supporter1 base5=spotColor(190), )
class BackToTheCity(BaseTheme): """The BackToTheCity theme is ...""" NAME = 'Back to the City' BASE_COLORS = dict( base0=spotColor(476), base1=spotColor(1405), base2=spotColor(139), base3=spotColor(480), base4=spotColor(421), # Supporter1 base5=spotColor(157), )
class SeasoningTheDish(BaseTheme): """The SeasoningTheDish theme is ...""" NAME = 'Seasoning the Dish' BASE_COLORS = dict( base0=spotColor(412), base1=spotColor(214), base2=spotColor(369), base3=spotColor(389), base4=spotColor(401), # Supporter1 base5=spotColor(103), )
class FairyTales(BaseTheme): """The FairyTales theme is ...""" NAME = 'Fairy Tales' BASE_COLORS = dict( base0=spotColor(425), base1=spotColor(237), base2=spotColor(278), base3=spotColor(373), base4=spotColor(422), # Supporter1 base5=spotColor(473), )
class BusinessAsUsual(BaseTheme): """The BusinessAsUsual theme is a generic “woody cool gray” theme, with settings that can be used in environments when functionality is more important than “arty” appearance.""" NAME = 'Business as Usual' BASE_COLORS = dict( base0=spotColor('blacku'), base1=spotColor(404), base2=spotColor(541), base3=spotColor(542), base4=spotColor(139), # Supporter1 base5=spotColor(877), )
class IntoTheWoods(BaseTheme): """The IntoTheWoods theme is ... >>> theme = IntoTheWoods """ NAME = 'Into the Woods' BASE_COLORS = dict( base0=spotColor('gray10u'), base1=spotColor(348), base2=spotColor(376), base3=spotColor(381), base4=spotColor(392), # Supporter1 base5=spotColor(398), )
class WordlyWise(BaseTheme): """The WordlyWise theme is ... >>> theme = WordlyWise() >>> theme.palette <Palette colors=51> """ NAME = 'Wordly Wise' BASE_COLORS = dict( base0=spotColor('warmgray8u'), base1=spotColor(286), base2=spotColor(265), base3=spotColor(258), base4=spotColor(278), # Supporter1 base5=spotColor(270), )
class Palette: """A theme Palette instance holds a limited set of base colors, and from there is capable to generate others, based on value recipes. >>> p = Palette() >>> p.black Color(r=0, g=0, b=0) >>> p.base1 Color(r=0.5, g=0.5, b=0.5) >>> p.dark5.hex '9C9C9C' >>> p.base1 Color(r=0.5, g=0.5, b=0.5) """ NUM_BASE = 6 # $ base and 2 supporters BASE_COLOR = grayColor BASE_COLORS = dict( black=blackColor, gray=BASE_COLOR, white=whiteColor, background=rgbColor('yellow'), # Safe light text and photo background logo=spotColor(165), # Base colors base0=BASE_COLOR.darker(0.75), base1=BASE_COLOR, base2=BASE_COLOR.lighter(0.35), base3=BASE_COLOR.lighter(0.75), base4=BASE_COLOR.darker(0.75), # Supporter 1 base5=BASE_COLOR.lighter(0.75), # Supporter 2 ) FACTOR_DARKEST = 0.15 # Factor between 0 <---> current color FACTOR_DARKER = 0.4 FACTOR_DARK = 0.7 FACTOR_LIGHT = 0.3 # Factor between current color <---> 1 FACTOR_LIGHTER = 0.6 FACTOR_LIGHTEST = 0.85 def __init__(self, colors=None, **kwargs): self.colorNames = set( ) # Collect the total set of installed color names. # Set lighter/darker factors from arguments or default self.factorDarkest = kwargs.get('darkest', self.FACTOR_DARKEST) self.factorDarker = kwargs.get('darker', self.FACTOR_DARKER) self.factorDark = kwargs.get('dark', self.FACTOR_DARK) self.factorLight = kwargs.get('light', self.FACTOR_LIGHT) self.factorLightest = kwargs.get('lightest', self.FACTOR_LIGHTEST) self.factorLighter = kwargs.get('lighter', self.FACTOR_LIGHTER) # Install default colors self.addColors(self.BASE_COLORS) if colors is not None: self.addColors(colors) relatedColors = dict(logoLight=spotColor(165).lighter(), logoDark=spotColor(165).darker(), supporter1=self.BASE_COLOR.darker(0.75), supporter2=self.BASE_COLOR.lighter(0.75)) for n in range(self.NUM_BASE): base = self['base%d' % n] relatedColors['darker%d' % n] = base.darker(self.factorDarker) relatedColors['dark%d' % n] = base.darker(self.factorDark) relatedColors['darkest%d' % n] = base.darker(self.factorDarkest) relatedColors['lighter%d' % n] = base.lighter(self.factorLighter) relatedColors['light%d' % n] = base.lighter(self.factorLight) relatedColors['lightest%d' % n] = base.lighter(self.factorLightest) #relatedColors['warmer%d' % n] = base.warmer(self.LEAST) #relatedColors['warm%d' % n] = base.warmer(self.MIDDLE) #relatedColors['warmest%d' % n] = base.warmer(self.MOST) #relatedColors['cooler%d' % n] = base.cooler(self.LEAST) #relatedColors['cool%d' % n] = base.cooler(self.MIDDLE) #relatedColors['coolest%d' % n] = base.cooler(self.MOST) self.addColors(relatedColors, overwrite=False) def addColors(self, colors, overwrite=True): # Add / overwrite custom base colors and recipes for this palette. for colorName, c in colors.items(): if overwrite or not hasattr(self, colorName): self.colorNames.add( colorName) # Called can overwrite any color recipe. setattr(self, colorName, c) def _get_random(self): return self.get(choice(list(self.colorNames))) random = property(_get_random) def __repr__(self): return '<%s colors=%d>' % (self.__class__.__name__, len(self)) def __getitem__(self, colorName): return self.get(colorName) def __len__(self): return len(self.colorNames) def get(self, colorName): """Interpret the name, and try to match/construct a color based on the recipe. """ assert colorName in self.colorNames, ( '%s.get: Unknown color name "%s"' % (self.__class__.__name__, colorName)) return getattr(self, colorName)