From f2fceeaa3386690b0cea0372f67cd2b5182eba48 Mon Sep 17 00:00:00 2001 From: actionless Date: Sat, 23 Dec 2017 00:33:10 +0100 Subject: [PATCH] fix(terminal theme): reset manually set colors when switching to auto/basic terminal colorsheme --- oomox_gui/export/common.py | 4 ++-- oomox_gui/main.py | 12 ++++++++++++ oomox_gui/preview_terminal.py | 4 ++-- oomox_gui/terminal.py | 19 ++++++++++++++++++- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/oomox_gui/export/common.py b/oomox_gui/export/common.py index cd5d3d8fb..6fb926221 100644 --- a/oomox_gui/export/common.py +++ b/oomox_gui/export/common.py @@ -4,7 +4,7 @@ from gi.repository import Gtk, GLib, Pango -from ..terminal import generate_theme_from_oomox, generate_xresources +from ..terminal import generate_xrdb_theme_from_oomox, generate_xresources from ..gtk_helpers import CenterLabel from ..config import ( archdroid_theme_dir, gnome_colors_icon_theme_dir, @@ -160,7 +160,7 @@ def export_terminal_theme(window, colorscheme): dialog.spinner.destroy() dialog.label.set_text(_('Paste this colorscheme to your ~/.Xresources')) try: - term_colorscheme = generate_theme_from_oomox(colorscheme) + term_colorscheme = generate_xrdb_theme_from_oomox(colorscheme) xresources_theme = generate_xresources(term_colorscheme) except Exception as e: dialog.set_text(e) diff --git a/oomox_gui/main.py b/oomox_gui/main.py index aa913b284..6fb8c6942 100755 --- a/oomox_gui/main.py +++ b/oomox_gui/main.py @@ -23,6 +23,7 @@ export_theme, export_gnome_colors_icon_theme, export_archdroid_icon_theme, export_spotify, export_terminal_theme ) +from .terminal import generate_terminal_colors_for_oomox class NewDialog(EntryDialog): @@ -216,6 +217,17 @@ def on_preset_selected(self, selected_preset, selected_preset_path): self.headerbar.props.title = selected_preset def on_color_edited(self, colorscheme): + # @TODO: don't write unused term colorscheme values? + updated_colorscheme = generate_terminal_colors_for_oomox(colorscheme) + delete_keys = [] + for theme_key, theme_value in colorscheme.items(): + if theme_key not in updated_colorscheme: + delete_keys.append(theme_key) + for theme_key in delete_keys: + del colorscheme[theme_key] + for theme_key, theme_value in updated_colorscheme.items(): + colorscheme[theme_key] = updated_colorscheme[theme_key] + self.colorscheme = colorscheme self.preview.update_preview(self.colorscheme) if not self.theme_edited: diff --git a/oomox_gui/preview_terminal.py b/oomox_gui/preview_terminal.py index 1d4108889..af179a870 100644 --- a/oomox_gui/preview_terminal.py +++ b/oomox_gui/preview_terminal.py @@ -1,6 +1,6 @@ from gi.repository import Gtk -from .terminal import generate_theme_from_oomox +from .terminal import generate_xrdb_theme_from_oomox from .helpers import convert_theme_color_to_gdk @@ -61,7 +61,7 @@ def __init__(self): self.attach(self.bg, 1, 1, 1, 1) def update_preview(self, colorscheme): - term_colorscheme = generate_theme_from_oomox(colorscheme) + term_colorscheme = generate_xrdb_theme_from_oomox(colorscheme) # print(term_colorscheme) converted = { key: convert_theme_color_to_gdk(theme_value) diff --git a/oomox_gui/terminal.py b/oomox_gui/terminal.py index 67a6b19fe..e9070f131 100644 --- a/oomox_gui/terminal.py +++ b/oomox_gui/terminal.py @@ -164,7 +164,9 @@ def generate_theme( return modified_colors -def generate_theme_from_oomox(colorscheme): +def generate_themes_from_oomox(original_colorscheme): + colorscheme = {} + colorscheme.update(original_colorscheme) if colorscheme['TERMINAL_THEME_MODE'] == 'auto': colorscheme["TERMINAL_ACCENT_COLOR"] = colorscheme["SEL_BG"] colorscheme["TERMINAL_BACKGROUND"] = colorscheme["TXT_BG"] @@ -189,9 +191,24 @@ def generate_theme_from_oomox(colorscheme): else: colorscheme[theme_key] = \ term_colorscheme[term_key] + return term_colorscheme, colorscheme + + +def generate_xrdb_theme_from_oomox(colorscheme): + term_colorscheme, _ = generate_themes_from_oomox(colorscheme) return term_colorscheme +def generate_terminal_colors_for_oomox(colorscheme): + _, new_colorscheme = generate_themes_from_oomox(colorscheme) + if new_colorscheme['TERMINAL_THEME_MODE'] != 'manual': + for i in range(16): + theme_key = "TERMINAL_COLOR{}".format(i) + if new_colorscheme.get(theme_key): + del new_colorscheme[theme_key] + return new_colorscheme + + def natural_sort(l): def convert(text): return int(text) if text.isdigit() else text.lower()