def load_palette_from_module(module_name): base_module_dir = os.path.join(os.path.dirname(sys.argv[0]), 'palettes') sys.path.insert(0, base_module_dir) m = importlib.import_module(module_name) palette = { name: convert_color.Color(color, name) for name, color in m.palette.items() } # Add more attributes that can be used in templates for name, color in palette.items(): color.r = int(round(color.srgb.rgb_r*255)) color.g = int(round(color.srgb.rgb_g*255)) color.b = int(round(color.srgb.rgb_b*255)) color.r1 = color.srgb.rgb_r color.g1 = color.srgb.rgb_g color.b1 = color.srgb.rgb_b color.rs = str(color.srgb.rgb_r) color.gs = str(color.srgb.rgb_g) color.bs = str(color.srgb.rgb_b) color.r16bit = int(round(color.srgb.rgb_r*255*257)) color.g16bit = int(round(color.srgb.rgb_g*255*257)) color.b16bit = int(round(color.srgb.rgb_b*255*257)) color.apple.r = float(color.apple.rgb_r) color.apple.g = float(color.apple.rgb_g) color.apple.b = float(color.apple.rgb_b) color.srgb_no_hash = re.sub(re.compile(r'^#'), '', color.srgb.__str__()) # Storing palette name in the same dictionary as the colors doesn't look # like the best data structure ever, but it will allow accessing the name # inside templates easily. try: palette['name'] = m.name except AttributeError: palette['name'] = module_name print('Palette: ' + palette['name'] + '\n') for color in DEFAULT_COLOR_ORDER: if color in ['red', 'br_red']: print ('') # section separator if color in palette: print("{:<12}{}".format(color, palette[color])) return palette
def load_palette_from_module(module_name): base_module_dir = os.path.join(os.path.dirname(sys.argv[0]), 'palettes') sys.path.insert(0, base_module_dir) m = importlib.import_module(module_name) palette = { name: convert_color.Color(color, name) for name, color in m.palette.items() } # Add more attributes that can be used in templates for name, color in palette.items(): color.r = int(round(color.srgb.rgb_r * 255)) color.g = int(round(color.srgb.rgb_g * 255)) color.b = int(round(color.srgb.rgb_b * 255)) color.r1 = color.srgb.rgb_r color.g1 = color.srgb.rgb_g color.b1 = color.srgb.rgb_b color.rs = str(color.srgb.rgb_r) color.gs = str(color.srgb.rgb_g) color.bs = str(color.srgb.rgb_b) color.r16bit = int(round(color.srgb.rgb_r * 255 * 257)) color.g16bit = int(round(color.srgb.rgb_g * 255 * 257)) color.b16bit = int(round(color.srgb.rgb_b * 255 * 257)) color.apple.r = float(color.apple.rgb_r) color.apple.g = float(color.apple.rgb_g) color.apple.b = float(color.apple.rgb_b) color.srgb_no_hash = re.sub(re.compile(r'^#'), '', color.srgb.__str__()) # for Notepad++ color.npp = re.sub(re.compile(r'#'), '', color.srgb.__str__()).upper() # Storing palette name in the same dictionary as the colors doesn't look # like the best data structure ever, but it will allow accessing the name # inside templates easily. try: palette['name'] = m.name except AttributeError: palette['name'] = module_name return palette