Esempio n. 1
0
    def generate_terminal_palette(  # pylint: disable=too-many-arguments
            cls, template_path, image_path,
            result_callback,
    ):
        from oomox_gui.theme_model import get_first_theme_option
        quality = get_first_theme_option('_PIL_PALETTE_QUALITY', {}).get('fallback_value')
        use_whole_palette = bool(
            get_first_theme_option('_PIL_PALETTE_STRICT', {}).get('fallback_value')
        )
        inverse_palette = bool(
            get_first_theme_option('_PIL_PALETTE_INVERSE', {}).get('fallback_value')
        )
        _id = template_path+image_path+str(quality)+str(use_whole_palette)+str(inverse_palette)

        def _result_callback(generated_palette):
            cls._terminal_palette_cache[_id] = generated_palette
            palette = {}
            palette.update(cls._terminal_palette_cache[_id])
            result_callback(palette)

        if not cls._terminal_palette_cache.get(_id):
            _app = cls.get_app()
            _app.disable(_('Generating terminal palette…'))
            _app.schedule_task(
                cls._generate_terminal_palette,
                template_path, image_path, quality, use_whole_palette, inverse_palette,
                _result_callback
            )
            _app.enable()
        else:
            _result_callback(cls._terminal_palette_cache[_id])
Esempio n. 2
0
    def generate_terminal_palette(
        cls,
        template_path,
        image_path,
        result_callback,
    ):
        quality = get_first_theme_option('_PIL_PALETTE_QUALITY',
                                         {}).get('fallback_value')
        use_whole_palette = bool(
            get_first_theme_option('_PIL_PALETTE_STRICT',
                                   {}).get('fallback_value'))
        inverse_palette = bool(
            get_first_theme_option('_PIL_PALETTE_INVERSE',
                                   {}).get('fallback_value'))
        _id = template_path + image_path + str(quality) + str(
            use_whole_palette) + str(inverse_palette)

        def _result_callback(generated_palette):
            cls._terminal_palette_cache[_id] = generated_palette
            palette = {}
            palette.update(cls._terminal_palette_cache[_id])
            result_callback(palette)

        if not cls._terminal_palette_cache.get(_id):
            _app = OomoxApplicationWindow.get_instance()
            _app.disable(translate('Generating terminal palette…'))
            _app.schedule_task(cls._generate_terminal_palette, template_path,
                               image_path, quality, use_whole_palette,
                               inverse_palette, _result_callback)
            _app.enable()
        else:
            _result_callback(cls._terminal_palette_cache[_id])
Esempio n. 3
0
    def read_colorscheme_from_path(self, preset_path, callback):
        from oomox_gui.theme_model import get_first_theme_option

        get_first_theme_option('_PIL_IMAGE_PREVIEW')['fallback_value'] = preset_path

        def _callback(image_palette):
            self.read_colorscheme_from_path_callback(image_palette, callback)

        self.generate_terminal_palette(
            get_first_theme_option('_PIL_PALETTE_STYLE').get('fallback_value'),
            preset_path,
            result_callback=_callback,
        )
Esempio n. 4
0
 def generate_terminal_palette(cls, template_path, image_path):
     from oomox_gui.theme_model import get_first_theme_option
     quality = get_first_theme_option('_PIL_PALETTE_QUALITY', {}).get('fallback_value')
     use_whole_palette = bool(
         get_first_theme_option('_PIL_PALETTE_STRICT', {}).get('fallback_value')
     )
     inverse_palette = bool(
         get_first_theme_option('_PIL_PALETTE_INVERSE', {}).get('fallback_value')
     )
     _id = template_path+image_path+str(quality)+str(use_whole_palette)+str(inverse_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, inverse_palette
         )
     palette = {}
     palette.update(cls._terminal_palette_cache[_id])
     return palette
Esempio n. 5
0
    def read_colorscheme_from_path(self, preset_path):
        # pylint:disable=bad-option-value,import-outside-toplevel
        from oomox_gui.theme_model import get_first_theme_option

        base16_theme = {}
        with open(preset_path) as preset_file:
            for line in preset_file.readlines():
                try:
                    key, value, *_rest = line.split()
                    key = key.rstrip(':')
                    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 get_first_theme_option('BASE16_GENERATE_DARK',
                                  {}).get('fallback_value'):
            translation.update(self.translation_dark)
        else:
            translation.update(self.translation_light)

        if get_first_theme_option('BASE16_INVERT_TERMINAL',
                                  {}).get('fallback_value'):
            translation.update(self.translation_terminal_inverse)

        if get_first_theme_option('BASE16_MILD_TERMINAL',
                                  {}).get('fallback_value'):
            if get_first_theme_option('BASE16_INVERT_TERMINAL',
                                      {}).get('fallback_value'):
                translation.update(self.translation_terminal_mild)
            else:
                translation.update(self.translation_terminal_mild_inverse)

        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
Esempio n. 6
0
    def read_colorscheme_from_path(self, preset_path):
        from oomox_gui.theme_model import get_first_theme_option

        get_first_theme_option(
            '_PIL_IMAGE_PREVIEW')['fallback_value'] = preset_path
        image_palette = self.generate_terminal_palette(
            get_first_theme_option('_PIL_PALETTE_STYLE').get('fallback_value'),
            preset_path)
        theme_template = get_first_theme_option('_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]
        return oomox_theme
Esempio n. 7
0
    def read_colorscheme_from_path(self, preset_path):
        from oomox_gui.theme_model import get_first_theme_option

        base16_theme = {}
        with open(preset_path) as preset_file:
            for line in preset_file.readlines():
                try:
                    key, value, *_rest = line.split()
                    key = key.rstrip(':')
                    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 get_first_theme_option('BASE16_GENERATE_DARK', {}).get('fallback_value'):
            translation.update(self.translation_dark)
        else:
            translation.update(self.translation_light)

        if get_first_theme_option('BASE16_INVERT_TERMINAL', {}).get('fallback_value'):
            translation.update(self.translation_terminal_inverse)

        if get_first_theme_option('BASE16_MILD_TERMINAL', {}).get('fallback_value'):
            if get_first_theme_option('BASE16_INVERT_TERMINAL', {}).get('fallback_value'):
                translation.update(self.translation_terminal_mild)
            else:
                translation.update(self.translation_terminal_mild_inverse)

        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
Esempio n. 8
0
    def read_colorscheme_from_path(self, preset_path):
        from oomox_gui.theme_model import get_first_theme_option

        get_first_theme_option('_PIL_IMAGE_PREVIEW')['fallback_value'] = preset_path
        image_palette = self.generate_terminal_palette(
            get_first_theme_option('_PIL_PALETTE_STYLE').get('fallback_value'),
            preset_path
        )
        theme_template = get_first_theme_option(
            '_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]
        return oomox_theme
Esempio n. 9
0
 def read_colorscheme_from_path_callback(self,
                                         image_palette: Dict[str, HexColor],
                                         callback) -> None:
     theme_template: str = get_first_theme_option('_PIL_THEME_TEMPLATE',
                                                  {}).get('fallback_value')
     oomox_theme: Dict[str, Any] = {}
     oomox_theme.update(self.default_theme)
     if theme_template in self.default_themes:
         oomox_theme.update(self.default_themes[theme_template])
     translation: Dict[str, str] = {}
     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]
     callback(oomox_theme)
Esempio n. 10
0
 def read_colorscheme_from_path_callback(self, image_palette, callback):
     from oomox_gui.theme_model import get_first_theme_option
     theme_template = get_first_theme_option(
         '_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]
     callback(oomox_theme)