Skip to content

Commit

Permalink
fix(terminal theme): reset manually set colors when switching to auto…
Browse files Browse the repository at this point in the history
…/basic terminal colorsheme
  • Loading branch information
actionless committed Dec 22, 2017
1 parent 60cf7e1 commit f2fceea
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
4 changes: 2 additions & 2 deletions oomox_gui/export/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions oomox_gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions oomox_gui/preview_terminal.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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)
Expand Down
19 changes: 18 additions & 1 deletion oomox_gui/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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()
Expand Down

0 comments on commit f2fceea

Please sign in to comment.