def read_colorscheme_from_path(self, preset_path): from oomox_gui.theme_model import THEME_MODEL_BY_KEY THEME_MODEL_BY_KEY['_PIL_IMAGE_PREVIEW'][ 'fallback_value'] = preset_path image_palette = self.generate_terminal_palette( THEME_MODEL_BY_KEY.get('_PIL_PALETTE_STYLE', {}).get('fallback_value'), preset_path) inverse_palette = bool( THEME_MODEL_BY_KEY.get('_PIL_PALETTE_INVERSE', {}).get('fallback_value')) theme_template = THEME_MODEL_BY_KEY.get('_PIL_THEME_TEMPLATE', {}).get('fallback_value') oomox_theme = {} oomox_theme.update(self.default_theme) if theme_template in self.default_themes: oomox_theme.update(self.default_themes[theme_template]) translation = {} translation.update(self.translation_common) translation.update(self.theme_translations[theme_template]) for oomox_key, image_palette_key in translation.items(): if image_palette_key in image_palette: oomox_theme[oomox_key] = image_palette[image_palette_key] if inverse_palette: oomox_theme['TERMINAL_FOREGROUND'], oomox_theme['TERMINAL_BACKGROUND'] = \ oomox_theme['TERMINAL_BACKGROUND'], oomox_theme['TERMINAL_FOREGROUND'] return oomox_theme
def generate_terminal_palette(cls, template_path, image_path): from oomox_gui.theme_model import THEME_MODEL_BY_KEY quality = int( THEME_MODEL_BY_KEY.get('_PIL_PALETTE_QUALITY', {}).get('fallback_value')) use_whole_palette = bool( THEME_MODEL_BY_KEY.get('_PIL_PALETTE_STRICT', {}).get('fallback_value')) _id = template_path + image_path + str(quality) + str( use_whole_palette) if not cls._terminal_palette_cache.get(_id): cls._terminal_palette_cache[_id] = cls._generate_terminal_palette( template_path, image_path, quality, use_whole_palette) palette = {} palette.update(cls._terminal_palette_cache[_id]) return palette
def read_colorscheme_from_path(self, preset_path): from oomox_gui.theme_model import THEME_MODEL_BY_KEY base16_theme = {} with open(preset_path) as preset_file: for line in preset_file.readlines(): try: key, value, *_rest = line.split() key = key.rstrip(':').lower() value = value.strip('\'"').lower() base16_theme[key] = value except Exception: pass oomox_theme = {} oomox_theme.update(self.default_theme) translation = {} translation.update(self.translation_common) if THEME_MODEL_BY_KEY.get('BASE16_GENERATE_DARK', {}).get('fallback_value'): translation.update(self.translation_dark) else: translation.update(self.translation_light) for oomox_key, base16_key in translation.items(): if base16_key in base16_theme: oomox_theme[oomox_key] = base16_theme[base16_key] return oomox_theme