From a59c6dc0561bf39463c9be02cff5f09c72b0430e Mon Sep 17 00:00:00 2001 From: deviantfero Date: Sun, 20 Jan 2019 10:21:25 -0600 Subject: [PATCH 01/45] use list() instead of an empty list --- wpgtk/data/color.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpgtk/data/color.py b/wpgtk/data/color.py index 0ea90ec0..e31c977e 100755 --- a/wpgtk/data/color.py +++ b/wpgtk/data/color.py @@ -111,7 +111,7 @@ def smart_sort(colors): """automatically set the most look-alike colors to their corresponding place in the standar xterm colors""" colors = colors[:8] - sorted_by_color = [] + sorted_by_color = list() base_colors = ["#000000", "#ff0000", "#00ff00", "#ffff00", "#0000ff", "#ff00ff", "#00ffff", "#ffffff"] From c462491481202d7d089e4e3c816766758b6250e8 Mon Sep 17 00:00:00 2001 From: deviantfero Date: Sun, 20 Jan 2019 10:21:42 -0600 Subject: [PATCH 02/45] change logging to be more brief --- wpgtk/data/util.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wpgtk/data/util.py b/wpgtk/data/util.py index cc767a88..5d954ebb 100644 --- a/wpgtk/data/util.py +++ b/wpgtk/data/util.py @@ -62,9 +62,9 @@ def setup_log(): " %(module)-13s %(message)s", level=logging.INFO, stream=sys.stdout) - logging.addLevelName(logging.ERROR, "err") - logging.addLevelName(logging.INFO, "inf") - logging.addLevelName(logging.WARNING, "wrn") + logging.addLevelName(logging.ERROR, "e") + logging.addLevelName(logging.INFO, "i") + logging.addLevelName(logging.WARNING, "w") def build_key(keyword): From 70bd70d70ab42337d6ada0c4bac21088666e6afb Mon Sep 17 00:00:00 2001 From: deviantfero Date: Sun, 20 Jan 2019 10:22:22 -0600 Subject: [PATCH 03/45] remove openbox and tint2 reload options from wpgtk --- wpgtk/gui/option_grid.py | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/wpgtk/gui/option_grid.py b/wpgtk/gui/option_grid.py index a511bca2..9901527f 100644 --- a/wpgtk/gui/option_grid.py +++ b/wpgtk/gui/option_grid.py @@ -54,9 +54,11 @@ def __init__(self, parent): # Backend Combo self.backend_list = colors.list_backends() self.backend_lbl = Gtk.Label("Select your backend:") + be_store = Gtk.ListStore(str) for elem in self.backend_list: be_store.append([elem]) + self.backend_combo = Gtk.ComboBox.new_with_model(be_store) self.backend_combo.pack_start(self.renderer_text, True) self.backend_combo.add_attribute(self.renderer_text, 'text', 0) @@ -64,18 +66,9 @@ def __init__(self, parent): self.backend_combo.connect("changed", self.combo_box_change, "backend") # Switches - self.tint2_switch = Gtk.Switch() - self.tint2_switch.connect("notify::active", self.on_activate, "tint2") - self.lbl_tint2 = Gtk.Label("Reload Tint2") - self.gtk_switch = Gtk.Switch() self.gtk_switch.connect("notify::active", self.on_activate, "gtk") - self.lbl_gtk = Gtk.Label("Reload GTK2") - - self.openbox_switch = Gtk.Switch() - self.openbox_switch.connect("notify::active", - self.on_activate, "openbox") - self.lbl_openbox = Gtk.Label("Reload openbox") + self.lbl_gtk = Gtk.Label("Reload GTK+") self.light_theme_switch = Gtk.Switch() self.light_theme_switch.connect("notify::active", @@ -123,15 +116,9 @@ def __init__(self, parent): self.switch_grid.attach(self.command_lbl, 1, 2, 3, 1) self.switch_grid.attach(self.command_switch, 4, 2, 1, 1) - self.switch_grid.attach(self.lbl_openbox, 5, 2, 3, 1) - self.switch_grid.attach(self.openbox_switch, 9, 2, 1, 1) - self.switch_grid.attach(self.lbl_light_theme, 1, 3, 3, 1) self.switch_grid.attach(self.light_theme_switch, 4, 3, 1, 1) - self.switch_grid.attach(self.lbl_tint2, 5, 3, 3, 1) - self.switch_grid.attach(self.tint2_switch, 9, 3, 1, 1) - self.switch_grid.attach(self.lbl_smart_sort, 1, 4, 3, 1) self.switch_grid.attach(self.smart_sort_switch, 4, 4, 1, 1) @@ -173,12 +160,8 @@ def load_opt_list(self): .set_active(settings.getint("active", 0)) self.gtk_switch\ .set_active(settings.getboolean("gtk", True)) - self.tint2_switch\ - .set_active(settings.getboolean("tint2", True)) self.command_switch\ .set_active(settings.getboolean("execute_cmd", False)) - self.openbox_switch\ - .set_active(settings.getboolean("openbox", True)) self.light_theme_switch\ .set_active(settings.getboolean("light_theme", False)) self.wallpaper_switch\ From 1c777f0530f39dfb36ce5b900629b2447bdf574f Mon Sep 17 00:00:00 2001 From: deviantfero Date: Sun, 20 Jan 2019 10:22:33 -0600 Subject: [PATCH 04/45] also reload kitty when applying themes --- wpgtk/data/reload.py | 1 + 1 file changed, 1 insertion(+) diff --git a/wpgtk/data/reload.py b/wpgtk/data/reload.py index 31aa9d3b..92778968 100644 --- a/wpgtk/data/reload.py +++ b/wpgtk/data/reload.py @@ -60,4 +60,5 @@ def all(): reload.i3() reload.polybar() reload.gtk() + reload.kitty() reload.sway() From bae9301002c94d737c0b77ac871a3e745949a264 Mon Sep 17 00:00:00 2001 From: deviantfero Date: Sun, 20 Jan 2019 10:24:45 -0600 Subject: [PATCH 05/45] improve icon color generation, improve wpgtk dictionary to be pywal style --- wpgtk/data/color.py | 78 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 63 insertions(+), 15 deletions(-) diff --git a/wpgtk/data/color.py b/wpgtk/data/color.py index e31c977e..48e9a310 100755 --- a/wpgtk/data/color.py +++ b/wpgtk/data/color.py @@ -206,38 +206,86 @@ def change_templates(colors): logging.error("optional file " + original, file=sys.stderr) -def split_active(hexc, is_dark_theme=True): +def add_icon_colors(colors): + try: + icon_dic = dict() + entry = re.compile(r"(.*)=(.*)$") + + with open(FILE_DIC["icon-step1"], "r") as icon_file: + for line in icon_file: + match = entry.search(line) + if match: + icon_dic[match.group(1)] = match.group(2) + + icon_dic["oldglyph"] = icon_dic["newglyph"] + icon_dic["oldfront"] = icon_dic["newfront"] + icon_dic["oldback"] = icon_dic["newback"] + + return icon_dic + + except KeyError: + logging.error("icons - badly formatted base file for icons") + return dict() + + except IOError: + logging.error("icons - base file does not exists") + return dict() + + +def wpgtk_colors(hexc, is_dark_theme=True): """extract active and inactive colors from a given hex color value""" brightness = util.get_hls_val(hexc, "light") - if is_dark_theme: - return {"COLORACT": util.alter_brightness(hexc, brightness * -0.20), - "COLORIN": util.alter_brightness(hexc, brightness * -0.45)} - else: - return {"COLORACT": util.alter_brightness(hexc, brightness * 0.30), - "COLORIN": hexc} + active = util.alter_brightness(hexc, brightness * -0.20) \ + if is_dark_theme else util.alter_brightness(hexc, brightness * -0.20) + + inactive = util.alter_brightness(hexc, brightness * -0.45) \ + if is_dark_theme else hexc + + return { + "active": active, + "inactive": inactive, + "newfront": active, + "newback": inactive, + "newglyph": util.alter_brightness(inactive, -15) + } -def add_wpgtk_colors(cdic): +def get_color_dict(cdic): """ensamble wpgtk color dictionary""" index = settings.getint("active") index = index if index > 0 else randint(9, 14) base_color = cdic["colors"]["color%s" % index] - color_list = list(cdic["colors"].values()) - cdic["wpgtk"] = split_active(base_color, is_dark_theme(color_list)) - cdic["icons"] = add_icon_colors(cdic) - return cdic + all_colors = { + "wallpaper": cdic["wallpaper"], + "alpha": cdic["alpha"], + **cdic["special"], + **cdic["colors"], + **add_icon_colors(cdic), + **wpgtk_colors(base_color, is_dark_theme(color_list)) + } + + try: + user_words = {k: v.format(**all_colors) + for k, v in user_keywords.items()} + all_colors = {**all_colors, **user_words} + + except KeyError as e: + logging.error("%s - invalid, use double {{}} " + "to escape curly braces" % e) + + return {k: pywal.util.Color(v) for k, v in all_colors.items()} def apply_colorscheme(colors): - colors = add_wpgtk_colors(colors) + color_dict = get_color_dict(colors) if os.path.isfile(FILE_DIC["icon-step2"]): - change_colors(colors, "icon-step1") + change_colors(color_dict, "icon-step1") Popen(FILE_DIC["icon-step2"]) - change_templates(colors) + change_templates(color_dict) From c5ab2bf86032ab4a62b03587c75188a795913f91 Mon Sep 17 00:00:00 2001 From: deviantfero Date: Sun, 20 Jan 2019 10:25:09 -0600 Subject: [PATCH 06/45] remove old icon function --- wpgtk/data/color.py | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/wpgtk/data/color.py b/wpgtk/data/color.py index 48e9a310..c7c22258 100755 --- a/wpgtk/data/color.py +++ b/wpgtk/data/color.py @@ -163,33 +163,6 @@ def auto_adjust_colors(clist): return clist -def add_icon_colors(colors): - try: - glyph = util.alter_brightness(colors["wpgtk"]["COLORIN"], -15) - icon_dic = {} - - with open(FILE_DIC["icon-step1"], "r") as icon_file: - for line in icon_file: - if("glyphColorNew=" in line): - icon_dic["oldglyph"] = line.split("=")[1].strip("\n") - - if("frontColorNew=" in line): - icon_dic["oldfront"] = line.split("=")[1].strip("\n") - - if("backColorNew=" in line): - icon_dic["oldback"] = line.split("=")[1].strip("\n") - - icon_dic["newglyph"] = glyph - icon_dic["newfront"] = colors["wpgtk"]["COLORACT"] - icon_dic["newback"] = colors["wpgtk"]["COLORIN"] - - return icon_dic - - except IOError: - logging.error("icons - base file does not exists") - return - - def change_templates(colors): """call change_colors on each custom template installed or defined by the user""" From c0cd8eace19c08f840775c2b88791da2e7d183d2 Mon Sep 17 00:00:00 2001 From: deviantfero Date: Sun, 20 Jan 2019 10:26:28 -0600 Subject: [PATCH 07/45] use format strings for templates instead of custom format --- wpgtk/data/color.py | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/wpgtk/data/color.py b/wpgtk/data/color.py index c7c22258..41eb19cf 100755 --- a/wpgtk/data/color.py +++ b/wpgtk/data/color.py @@ -81,27 +81,21 @@ def change_colors(colors, which): if which in FILE_DIC: which = FILE_DIC[which] - tmp_filename = which + ".base" try: - with open(tmp_filename, "r") as tmp_file: + with open("%s.base" % which, "r") as tmp_file: first_line = tmp_file.readline() - tmp_file.seek(0) - tmp_data = tmp_file.read() - if "wpgtk-ignore" not in first_line: - for k, v in user_keywords.items(): - tmp_data = tmp_data.replace(util.build_key(k), v) + if "wpgtk-ignore" not in first_line: + tmp_file.seek(0) + tmp_data = tmp_file.read() + tmp_data = tmp_data.format_map(colors) - for k, v in {**colors["wpgtk"], **colors["colors"]}.items(): - tmp_data = tmp_data.replace(util.build_key(k.upper()), v.strip("#")) + with open(which, "w") as target_file: + target_file.write(tmp_data) + logging.info("wrote: %s" % opt.split("/").pop()) - if colors["icons"] and opt == "icon-step1": - for k, v in colors["icons"].items(): - tmp_data = tmp_data.replace(k, v.strip("#")) - - with open(which, "w") as target_file: - target_file.write(tmp_data) - logging.info("wrote: %s" % opt.split("/").pop()) + except KeyError as e: + logging.error("%s in %s - key does not exist" % (e, opt)) except IOError: logging.error("%s - base file does not exist" % opt) From 6bf328b6e1e80008de8969b6320739be926213bc Mon Sep 17 00:00:00 2001 From: deviantfero Date: Sun, 20 Jan 2019 10:26:45 -0600 Subject: [PATCH 08/45] add re for icon capturing --- wpgtk/data/color.py | 1 + 1 file changed, 1 insertion(+) diff --git a/wpgtk/data/color.py b/wpgtk/data/color.py index 41eb19cf..b49201f4 100755 --- a/wpgtk/data/color.py +++ b/wpgtk/data/color.py @@ -2,6 +2,7 @@ import logging import pywal import os +import re from operator import itemgetter from subprocess import Popen from random import shuffle, randint From 9c7073da16fffc005881dd3f5d15e222aed5f1ae Mon Sep 17 00:00:00 2001 From: deviantfero Date: Sun, 20 Jan 2019 10:26:54 -0600 Subject: [PATCH 09/45] remove options from default config file --- wpgtk/misc/wpg.conf | 2 -- 1 file changed, 2 deletions(-) diff --git a/wpgtk/misc/wpg.conf b/wpgtk/misc/wpg.conf index c90050a9..f0c0e448 100644 --- a/wpgtk/misc/wpg.conf +++ b/wpgtk/misc/wpg.conf @@ -1,9 +1,7 @@ [settings] set_wallpaper = true -openbox = true gtk = true active = 0 -tint2 = true light_theme = false editor = urxvt -e vim execute_cmd = false From ddfb5d5d6bb5407fd243176de7fcbcf12e9f57da Mon Sep 17 00:00:00 2001 From: deviantfero Date: Sun, 20 Jan 2019 21:39:55 -0600 Subject: [PATCH 10/45] remove build_key function --- wpgtk/data/util.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/wpgtk/data/util.py b/wpgtk/data/util.py index 5d954ebb..e0445089 100644 --- a/wpgtk/data/util.py +++ b/wpgtk/data/util.py @@ -67,10 +67,6 @@ def setup_log(): logging.addLevelName(logging.WARNING, "w") -def build_key(keyword): - return "<{}>".format(keyword) - - def get_pid(name): """Check if a process is running, borrowed from a newer pywal version""" try: From 309745b1dca7de08682df9df9252753dbb517010 Mon Sep 17 00:00:00 2001 From: deviantfero Date: Sun, 20 Jan 2019 21:40:18 -0600 Subject: [PATCH 11/45] update pywal version required --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 28c92ec9..db12dce0 100644 --- a/setup.py +++ b/setup.py @@ -44,7 +44,7 @@ python_requires=">=3.5", install_requires=[ 'Pillow>=4.2.1', - 'pywal>=2.0.0', + 'pywal>=3.0.0', ], include_package_data=True, data_files=[('etc/wpgtk', ['wpgtk/misc/wpg.conf']), From f22ca2f76d24c5ded5650260433c49e73c1e1440 Mon Sep 17 00:00:00 2001 From: deviantfero Date: Thu, 24 Jan 2019 13:27:15 -0600 Subject: [PATCH 12/45] update auto-complete for bash and zsh --- completions/bash/wpg | 12 ++++++------ completions/zsh/_wpg | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/completions/bash/wpg b/completions/bash/wpg index 7e232a50..681c506b 100644 --- a/completions/bash/wpg +++ b/completions/bash/wpg @@ -8,13 +8,13 @@ function _wpg() { # themes, filenames optvariable="-i -o" # filenames - optfordefault="-y -a -xa -ax" + optfordefault="--link -aL -La -a -ta -at" # templates - optfortemplates="-xd -dx" + optfortemplates="-td -dt" # pywal backends optforbackends="--backends" # pywal themes - optforthemes="--pywal" + optforthemes="--theme" if [[ $COMP_CWORD = 1 ]]; then COMPREPLY=($(compgen -W "$(_parse_usage wpg)" -- "$cur")) @@ -31,7 +31,7 @@ function _wpg() { done for opt in $optforthemes; do if [[ $opt = ${COMP_WORDS[1]} ]]; then - COMPREPLY=($(compgen -W "$(wpg --pywal)" -- "$cur")) + COMPREPLY=($(compgen -W "$(wpg --theme)" -- "$cur")) fi done for opt in $optvariable; do @@ -45,7 +45,7 @@ function _wpg() { if [[ $opt = ${COMP_WORDS[1]} && $COMP_CWORD < 3 ]]; then COMPREPLY=($(compgen -W "$(wpg -l)" -- "$cur")) elif [[ $opt = ${COMP_WORDS[1]} ]]; then - COMPREPLY=($(compgen -W "$(wpg --pywal)" -- "$cur")) + COMPREPLY=($(compgen -W "$(wpg --theme)" -- "$cur")) fi done for opt in $optfordefault; do @@ -55,7 +55,7 @@ function _wpg() { done for opt in $optfortemplates; do if [[ $opt = ${COMP_WORDS[1]} ]]; then - COMPREPLY=($(compgen -W "$(wpg -xl)" -- "$cur")) + COMPREPLY=($(compgen -W "$(wpg -tl)" -- "$cur")) fi done fi diff --git a/completions/zsh/_wpg b/completions/zsh/_wpg index 3821302e..9adcc1d4 100644 --- a/completions/zsh/_wpg +++ b/completions/zsh/_wpg @@ -8,7 +8,7 @@ _profiles() { _templates() { local -a templates - templates=(`wpg -xl`) + templates=(`wpg -tl`) _describe 'templates' templates } @@ -20,7 +20,7 @@ _backends() { _themes() { local -a themes - themes=(`wpg --pywal`) + themes=(`wpg --theme`) _describe 'themes' themes } @@ -33,13 +33,13 @@ _wpg() { # themes, pywal themes optvariabletheme=(-Ti) # filenames - optforgeneric=(-y -a -xa) + optforgeneric=(--link -a -La -aL -ta -at --update_template) # templates - optfortemplates=(-xd -dx) + optfortemplates=(-td -dt) # pywal backends optforbackends=(--backend) # pywal themes - optforthemes=(--pywal) + optforthemes=(--theme) _arguments \ '1: :->generic' \ From d0d7beb635f3472f10a6cdd72c391083acb67b1e Mon Sep 17 00:00:00 2001 From: deviantfero Date: Thu, 24 Jan 2019 13:27:57 -0600 Subject: [PATCH 13/45] use fallback on failure to generate a theme, create image on fail --- wpgtk/gui/color_grid.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/wpgtk/gui/color_grid.py b/wpgtk/gui/color_grid.py index 027d7fca..7a83ec79 100644 --- a/wpgtk/gui/color_grid.py +++ b/wpgtk/gui/color_grid.py @@ -7,6 +7,7 @@ from ..data import util from ..data import files from ..data import sample +from ..data import themer from .color_picker import ColorDialog from gi import require_version @@ -267,15 +268,19 @@ def combo_box_change(self, widget): current_walls = files.get_file_list() self.selected_file = current_walls[x] sample_path = files.get_sample_path(self.selected_file) - self.color_list = color.get_color_list(self.selected_file) + try: + self.color_list = color.get_color_list(self.selected_file) + except SystemExit: + self.color_list = themer.set_fallback_theme(self.selected_file) self.render_buttons() try: self.pixbuf_sample = GdkPixbuf.Pixbuf\ .new_from_file_at_size(sample_path, width=500, height=300) - self.sample.set_from_pixbuf(self.pixbuf_sample) except: sample.create_sample(self.color_list, sample_path) + self.pixbuf_sample = GdkPixbuf.Pixbuf\ + .new_from_file_at_size(sample_path, width=500, height=300) - # Refresh parent's sample pixbuf + self.sample.set_from_pixbuf(self.pixbuf_sample) self.parent.sample.set_from_pixbuf(self.pixbuf_sample) From d3a81413d1b69814cb3378545d6d27c0bf97fa4f Mon Sep 17 00:00:00 2001 From: deviantfero Date: Thu, 24 Jan 2019 13:28:27 -0600 Subject: [PATCH 14/45] add auto_adjust setting to auto_adjust on add --- wpgtk/misc/wpg.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/wpgtk/misc/wpg.conf b/wpgtk/misc/wpg.conf index f0c0e448..1e9077ba 100644 --- a/wpgtk/misc/wpg.conf +++ b/wpgtk/misc/wpg.conf @@ -9,5 +9,6 @@ command = urxvt -e echo hi backend = wal alpha = 100 auto_sort = true +auto_adjust = false [keywords] From be3e392cf72818eaa7e9abf5d67e52f2c4a7b671 Mon Sep 17 00:00:00 2001 From: deviantfero Date: Thu, 24 Jan 2019 13:29:01 -0600 Subject: [PATCH 15/45] write_script function for writing the script to execute at startup --- wpgtk/data/files.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/wpgtk/data/files.py b/wpgtk/data/files.py index 6f1112e3..4f308a73 100644 --- a/wpgtk/data/files.py +++ b/wpgtk/data/files.py @@ -26,10 +26,24 @@ def get_file_list(path=WALL_DIR, images=True): return files +def write_script(wallpaper, colorscheme): + """writes the script that should be called on startup + to restore the theme.""" + set_wall = settings.getboolean("set_wallpaper", True) + light_theme = settings.getboolean("light_theme", True) + + flags = "-rs" if set_wall else "-nrs" + flags += "L" if light_theme else "" + + with open(join(WPG_DIR, "wp_init.sh"), "w") as script: + command = "wpg %s '%s' '%s'" % (flags, wallpaper, colorscheme) + script.writelines(["#!/usr/bin/env bash\n", command]) + + def get_cache_path(wallpaper, backend=None): """get a colorscheme cache path using a wallpaper name""" if not backend: - backend = settings.get('backend', 'wal') + backend = settings.get("backend", "wal") filepath = join(WALL_DIR, wallpaper) filename = cache_fname(filepath, backend, False, WPG_DIR) From 757a6cb7993ddf77ad57ce2b2468168ea50d5689 Mon Sep 17 00:00:00 2001 From: deviantfero Date: Thu, 24 Jan 2019 13:29:43 -0600 Subject: [PATCH 16/45] add function to update templates to new version --- wpgtk/data/files.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/wpgtk/data/files.py b/wpgtk/data/files.py index 4f308a73..63bd1bee 100644 --- a/wpgtk/data/files.py +++ b/wpgtk/data/files.py @@ -54,7 +54,7 @@ def get_cache_path(wallpaper, backend=None): def get_sample_path(wallpaper, backend=None): """gets a wallpaper colorscheme sample's path""" if not backend: - backend = settings.get('backend', 'wal') + backend = settings.get("backend", "wal") sample_filename = "%s_%s_sample.png" % (wallpaper, backend) @@ -111,6 +111,27 @@ def delete_colorschemes(wallpaper): pass +def update_color(matchobj): + if matchobj.group(1): + return "{%s}" % matchobj.group(1).lower() + + +def update_template(template_path): + with open(template_path, "r") as f: + tmp_data = f.read() + + logging.info("escaping legitimate curly braces {} -> {{}}") + tmp_data = tmp_data.replace("{", "{{") + tmp_data = tmp_data.replace("}", "}}") + + logging.info("replacing # with braces {colorxx}") + tmp_data = re.sub(r"#<(COLOR[0-9]{1,2})>", update_color, tmp_data) + tmp_data = tmp_data.replace("#", "{active}") + tmp_data = tmp_data.replace("#", "{inactive}") + + logging.info("%s update complete" % template_path) + + def change_current(filename): """update symlink to point to the current wallpaper""" os.symlink(join(WALL_DIR, filename), join(WPG_DIR, ".currentTmp")) From adbec2059de241a8903dc593b91a543624528977 Mon Sep 17 00:00:00 2001 From: deviantfero Date: Thu, 24 Jan 2019 13:30:37 -0600 Subject: [PATCH 17/45] use new write_script function --- wpgtk/data/themer.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/wpgtk/data/themer.py b/wpgtk/data/themer.py index 054fc610..4124b818 100644 --- a/wpgtk/data/themer.py +++ b/wpgtk/data/themer.py @@ -44,17 +44,12 @@ def set_theme(wallpaper, colorscheme, restore=False): set_wall = filepath if path.isfile(filepath) else colors["wallpaper"] pywal.wallpaper.change(set_wall) - flags = "-rs" if set_wall else "-nrs" - with open(path.join(WPG_DIR, "wp_init.sh"), "w") as script: - script.writelines(["#!/usr/bin/env bash\n", - "wpg %s '%s' '%s'" % - (flags, wallpaper, colorscheme)]) + files.write_script(wallpaper, colorscheme) + files.change_current(wallpaper) Popen(['chmod', '+x', path.join(WPG_DIR, "wp_init.sh")]) reload.xrdb() - files.change_current(wallpaper) - if settings.getboolean('execute_cmd'): Popen(['bash', '-c', settings['command']]) From 5282dcd24564442e61773d0c5b0c1cc2991fcff7 Mon Sep 17 00:00:00 2001 From: deviantfero Date: Thu, 24 Jan 2019 13:32:07 -0600 Subject: [PATCH 18/45] behave -s to directories and images like pywal --- wpgtk/data/color.py | 5 ++++- wpgtk/data/themer.py | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/wpgtk/data/color.py b/wpgtk/data/color.py index b49201f4..5421e68b 100755 --- a/wpgtk/data/color.py +++ b/wpgtk/data/color.py @@ -14,13 +14,16 @@ from . import sample -def get_pywal_dict(wallpaper): +def get_pywal_dict(wallpaper, is_file=False): """get the color dictionary of a given wallpaper""" + light_theme = settings.getboolean("light_theme", False) pywal.util.Color.alpha_num = settings.get("alpha", "100") + image = pywal.image.get(os.path.join(WALL_DIR, wallpaper)) return pywal.colors.get( image, + light=(is_file and light_theme), backend=settings.get("backend", "wal"), cache_dir=WPG_DIR ) diff --git a/wpgtk/data/themer.py b/wpgtk/data/themer.py index 4124b818..b508b7fc 100644 --- a/wpgtk/data/themer.py +++ b/wpgtk/data/themer.py @@ -30,8 +30,11 @@ def create_theme(filepath): def set_theme(wallpaper, colorscheme, restore=False): """apply a given wallpaper and a given colorscheme""" + is_file = path.isdir(colorscheme) or path.isfile(colorscheme) + target = colorscheme if is_file else path.join(WALL_DIR, colorscheme) + set_wall = settings.getboolean("set_wallpaper", True) - colors = color.get_pywal_dict(path.join(WALL_DIR, colorscheme)) + colors = color.get_pywal_dict(target, is_file) pywal.sequences.send(colors, WPG_DIR) if not restore: From 9b60016a929b6e9866ceed9ad69be6df022a5681 Mon Sep 17 00:00:00 2001 From: deviantfero Date: Thu, 24 Jan 2019 13:34:55 -0600 Subject: [PATCH 19/45] add setting to autoadjust on theme creation and behave accordingly --- wpgtk/data/color.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/wpgtk/data/color.py b/wpgtk/data/color.py index 5421e68b..a90b5358 100755 --- a/wpgtk/data/color.py +++ b/wpgtk/data/color.py @@ -32,6 +32,7 @@ def get_pywal_dict(wallpaper, is_file=False): def get_color_list(filename, json=False): """extract a list with 16 colors from a json or a pywal dict""" is_new = not os.path.isfile(files.get_cache_path(filename)) + auto_adjust = settings.getboolean("auto_adjust", True) if json: theme = pywal.util.read_file_json(filename) @@ -44,6 +45,8 @@ def get_color_list(filename, json=False): color_list = list(theme["colors"].values()) if is_new and not json: + if auto_adjust: + color_list = auto_adjust_colors(color_list) sample.create_sample(color_list, files.get_sample_path(filename)) write_colors(filename, color_list) @@ -152,7 +155,7 @@ def auto_adjust_colors(clist): if light == is_dark_theme(clist): clist[7], clist[0] = clist[0], clist[7] - comment = [alter_brightness(clist[0], sign * 20)] + comment = [alter_brightness(clist[0], sign * 25)] fg = [alter_brightness(clist[7], sign * 60)] clist = clist[:8] + comment \ + [alter_brightness(x, sign * get_hls_val(x, "light") * 0.3, added_sat) From db9389b71cd7f1ed3c32f4e960f461ac265d2a3b Mon Sep 17 00:00:00 2001 From: deviantfero Date: Thu, 24 Jan 2019 13:38:58 -0600 Subject: [PATCH 20/45] change -x flag for -t, and --pywal for --theme --- wpgtk/__main__.py | 57 ++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/wpgtk/__main__.py b/wpgtk/__main__.py index 68dffc8b..ace85afd 100755 --- a/wpgtk/__main__.py +++ b/wpgtk/__main__.py @@ -18,6 +18,10 @@ def read_args(args): parser = argparse.ArgumentParser() + parser.add_argument("--version", + help="print the current version", + action="store_true") + parser.add_argument("-a", help="add a wallpaper and generate a colorscheme", nargs="+") @@ -38,18 +42,19 @@ def read_args(args): help="see which wallpapers are available", action="store_true") + parser.add_argument("-t", + help="add, remove and list templates instead " + "of themes", + action="store_true") + parser.add_argument("-n", - help="don't change wallpaper", + help="avoid setting a wallpaper", action="store_true") parser.add_argument("-r", help="restore the wallpaper and colorscheme", action="store_true") - parser.add_argument("--version", - help="print the current version", - action="store_true") - parser.add_argument("-c", help="shows the current wallpaper", action="store_true") @@ -58,21 +63,17 @@ def read_args(args): help="temporarily enable light themes", action="store_true") + parser.add_argument("--theme", + help="list included pywal themes " + "or replace your current colorscheme with a " + "selection of your own", + const="list", nargs="?") + parser.add_argument("-T", help="assign a pywal theme to specific wallpaper" " instead of a json file", action="store_true") - parser.add_argument("-t", - help="send color sequences to all " - "terminals (deprecated)", - action="store_true") - - parser.add_argument("-x", - help="add, remove and list templates instead " - "of themes", - action="store_true") - parser.add_argument("-z", help="shuffles the given colorscheme(s)", nargs="+") @@ -113,11 +114,6 @@ def read_args(args): help="set a one time alpha value", nargs=1) - parser.add_argument("--pywal", - help="list included pywal themes " - "or replace your current colorscheme with a " - "selection of your own", - const="list", nargs="?") return parser.parse_args() @@ -171,29 +167,25 @@ def process_args(args): exit(0) if args.l: - if args.x: + if args.t: templates = files.get_file_list(OPT_DIR, False) any(print(t) for t in templates if ".base" in t) else: print("\n".join(files.get_file_list())) exit(0) - if args.t: - Popen(["cat", path.join(WPG_DIR, "sequences")]) - exit(0) - if args.version: print("current version: " + __version__) exit(0) if args.d: - delete_action = files.delete_template if args.x \ + delete_action = files.delete_template if args.t \ else themer.delete_theme any(delete_action(x) for x in args.d) exit(0) if args.a: - add_action = files.add_template if args.x \ + add_action = files.add_template if args.t \ else themer.create_theme for x in args.a: if path.isfile(glob.glob(x)[0]): @@ -230,7 +222,7 @@ def process_args(args): themer.export_theme(*args.o) exit(0) - if args.pywal == "list": + if args.theme == "list": name_dic = pywal.theme.list_themes() name_list = [t.name.replace(".json", "") for t in name_dic] print("\n".join(name_list)) @@ -254,14 +246,19 @@ def process_args(args): sample.create_sample(cl, files.get_sample_path(args.brt[0])) exit(0) - if args.pywal and args.pywal != "list": - themer.set_pywal_theme(args.pywal) + if args.theme and args.theme != "list": + themer.set_pywal_theme(args.theme) exit(0) if args.backend == "list": print("\n".join(pywal.colors.list_backends())) exit(0) + if args.update_template: + for arg in args.update_template: + files.update_template(arg) + exit(0) + if args.backend and args.backend != "list": if args.backend in pywal.colors.list_backends(): settings['backend'] = args.backend From 8aa835e90bd8ca81bea3f0041ea29b33c3f13f96 Mon Sep 17 00:00:00 2001 From: deviantfero Date: Thu, 24 Jan 2019 13:39:17 -0600 Subject: [PATCH 21/45] remove unnecessary imports --- wpgtk/__main__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/wpgtk/__main__.py b/wpgtk/__main__.py index ace85afd..92605748 100755 --- a/wpgtk/__main__.py +++ b/wpgtk/__main__.py @@ -5,13 +5,12 @@ import argparse import glob from os import path -from subprocess import Popen from .data import files from .data import themer from .data import color from .data import util from .data import sample -from .data.config import OPT_DIR, WPG_DIR, __version__ +from .data.config import OPT_DIR, __version__ from .data.config import settings From 20ca2091cd34fa6f66a558ebbc3cbf04d3fb25bb Mon Sep 17 00:00:00 2001 From: deviantfero Date: Thu, 24 Jan 2019 13:39:41 -0600 Subject: [PATCH 22/45] change -y flag for a more explicit --link flag --- wpgtk/__main__.py | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/wpgtk/__main__.py b/wpgtk/__main__.py index 92605748..dc52bf5c 100755 --- a/wpgtk/__main__.py +++ b/wpgtk/__main__.py @@ -85,15 +85,16 @@ def read_args(args): help="import a theme in json format and asign " "to wallpaper [wallpaper, json]", nargs=2) + parser.add_argument("-o", help="export a theme in json " "format [wallpaper, json]", nargs="+") - parser.add_argument("-y", - help="link config file to template backup" - "[config, basefile]", - nargs="+") + parser.add_argument("--link", + help="link config file to template backup " + "[config, .base]", + nargs=2) parser.add_argument("--sat", help="add or substract the saturation of a " @@ -130,14 +131,6 @@ def process_arg_errors(args): logging.error("specify at most 2 filenames") exit(1) - if args.y and len(args.y) != 2: - logging.error("specify a config and a basefile") - exit(1) - - if args.i and len(args.i) != 2: - logging.error("specify a wallpaper and a colorscheme json") - exit(1) - if args.o and len(args.o) != 2: logging.error("specify wallpaper and optionally an output path") exit(1) @@ -209,8 +202,8 @@ def process_args(args): logging.info("shuffled %s" % arg) exit(0) - if args.y: - files.add_template(args.y[0], args.y[1]) + if args.link: + files.add_template(args.link[0], args.link[1]) exit(0) if args.i: From 193cdcc4e6e0010876fa21b2adae8d621f17b9d3 Mon Sep 17 00:00:00 2001 From: deviantfero Date: Thu, 24 Jan 2019 13:40:18 -0600 Subject: [PATCH 23/45] add a --preview flag that behaves like pywal, and --update_template --- wpgtk/__main__.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/wpgtk/__main__.py b/wpgtk/__main__.py index dc52bf5c..9fc85035 100755 --- a/wpgtk/__main__.py +++ b/wpgtk/__main__.py @@ -114,6 +114,14 @@ def read_args(args): help="set a one time alpha value", nargs=1) + parser.add_argument("--preview", + help="preview your current colorscheme", + action="store_true") + + parser.add_argument("--update_template", + help="update template(s) of your choice " + "to the new format", + nargs="+") return parser.parse_args() @@ -146,11 +154,20 @@ def process_args(args): if args.alpha: settings["alpha"] = args.alpha[0] - if args.m: - filename = random.choice(files.get_file_list()) - themer.set_theme(filename, filename, args.r) + if args.preview: + pywal.colors.palette() exit(0) + if args.m: + file_list = files.get_file_list() + if len(file_list) > 0: + filename = random.choice(file_list) + themer.set_theme(filename, filename, args.r) + exit(0) + else: + logging.error("you have no themes") + exit(1) + if args.s: if len(args.s) == 1: themer.set_theme(args.s[0], args.s[0], args.r) @@ -269,8 +286,10 @@ def main(): try: _gui = __import__("wpgtk.gui.theme_picker", fromlist=['theme_picker']) _gui.run(args) + exit(0) except NameError: logging.error("missing pygobject module, use cli") + exit(1) if __name__ == "__main__": From 20f67fdb89eeb13a3aae75f8ee23e6cae3ead0dc Mon Sep 17 00:00:00 2001 From: deviantfero Date: Thu, 24 Jan 2019 21:49:16 -0600 Subject: [PATCH 24/45] auto-adjust when light theme is on, this generates light themes via wpgtk --- wpgtk/data/color.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wpgtk/data/color.py b/wpgtk/data/color.py index a90b5358..9194a722 100755 --- a/wpgtk/data/color.py +++ b/wpgtk/data/color.py @@ -33,6 +33,7 @@ def get_color_list(filename, json=False): """extract a list with 16 colors from a json or a pywal dict""" is_new = not os.path.isfile(files.get_cache_path(filename)) auto_adjust = settings.getboolean("auto_adjust", True) + light_theme = settings.getboolean("light_theme", False) if json: theme = pywal.util.read_file_json(filename) @@ -45,7 +46,7 @@ def get_color_list(filename, json=False): color_list = list(theme["colors"].values()) if is_new and not json: - if auto_adjust: + if auto_adjust or light_theme: color_list = auto_adjust_colors(color_list) sample.create_sample(color_list, files.get_sample_path(filename)) write_colors(filename, color_list) From e02c06bf652bf1480384711ae34f71ee6bd82be7 Mon Sep 17 00:00:00 2001 From: deviantfero Date: Thu, 24 Jan 2019 21:54:13 -0600 Subject: [PATCH 25/45] add switch for always auto_adjust in option_grid --- wpgtk/gui/option_grid.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/wpgtk/gui/option_grid.py b/wpgtk/gui/option_grid.py index 9901527f..92258195 100644 --- a/wpgtk/gui/option_grid.py +++ b/wpgtk/gui/option_grid.py @@ -87,6 +87,11 @@ def __init__(self, parent): "smart_sort") self.lbl_smart_sort = Gtk.Label("Use smart sort") + self.auto_adjust_switch = Gtk.Switch() + self.auto_adjust_switch.connect("notify::active", + self.on_activate, "auto_adjust") + self.lbl_auto_adjust = Gtk.Label("Always auto adjust") + # edit cmd self.editor_lbl = Gtk.Label("Open optional files with:") self.editor_txt = Gtk.Entry() @@ -113,6 +118,9 @@ def __init__(self, parent): self.switch_grid.attach(self.lbl_gtk, 5, 1, 3, 1) self.switch_grid.attach(self.gtk_switch, 9, 1, 1, 1) + self.switch_grid.attach(self.lbl_auto_adjust, 5, 2, 3, 1) + self.switch_grid.attach(self.auto_adjust_switch, 9, 2, 1, 1) + self.switch_grid.attach(self.command_lbl, 1, 2, 3, 1) self.switch_grid.attach(self.command_switch, 4, 2, 1, 1) @@ -122,8 +130,6 @@ def __init__(self, parent): self.switch_grid.attach(self.lbl_smart_sort, 1, 4, 3, 1) self.switch_grid.attach(self.smart_sort_switch, 4, 4, 1, 1) - # cmd Grid attach - # Active Grid attach self.active_grid.attach(self.backend_lbl, 1, 1, 1, 1) self.active_grid.attach(self.backend_combo, 2, 1, 1, 1) @@ -168,6 +174,8 @@ def load_opt_list(self): .set_active(settings.getboolean("set_wallpaper", True)) self.smart_sort_switch\ .set_active(settings.getboolean("smart_sort", True)) + self.auto_adjust_switch\ + .set_active(settings.getboolean("auto_adjust", False)) self.editor_txt\ .set_text(settings.get("editor", "urxvt -e vim")) From 96d27d6363a95389f7f176799cb7f880c53048c3 Mon Sep 17 00:00:00 2001 From: deviantfero Date: Thu, 24 Jan 2019 22:02:27 -0600 Subject: [PATCH 26/45] add whitespace to make code more readable --- wpgtk/gui/option_grid.py | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/wpgtk/gui/option_grid.py b/wpgtk/gui/option_grid.py index 92258195..268b4e05 100644 --- a/wpgtk/gui/option_grid.py +++ b/wpgtk/gui/option_grid.py @@ -71,25 +71,35 @@ def __init__(self, parent): self.lbl_gtk = Gtk.Label("Reload GTK+") self.light_theme_switch = Gtk.Switch() - self.light_theme_switch.connect("notify::active", - self.on_activate, "light_theme") + self.light_theme_switch.connect( + "notify::active", + self.on_activate, + "light_theme" + ) self.lbl_light_theme = Gtk.Label("Use Light Theme") self.wallpaper_switch = Gtk.Switch() - self.wallpaper_switch.connect("notify::active", - self.on_activate, - "set_wallpaper") + self.wallpaper_switch.connect( + "notify::active", + self.on_activate, + "set_wallpaper" + ) self.lbl_wallpaper = Gtk.Label("Set wallpaper") self.smart_sort_switch = Gtk.Switch() - self.smart_sort_switch.connect("notify::active", - self.on_activate, - "smart_sort") + self.smart_sort_switch.connect( + "notify::active", + self.on_activate, + "smart_sort" + ) self.lbl_smart_sort = Gtk.Label("Use smart sort") self.auto_adjust_switch = Gtk.Switch() - self.auto_adjust_switch.connect("notify::active", - self.on_activate, "auto_adjust") + self.auto_adjust_switch.connect( + "notify::active", + self.on_activate, + "auto_adjust" + ) self.lbl_auto_adjust = Gtk.Label("Always auto adjust") # edit cmd @@ -100,11 +110,16 @@ def __init__(self, parent): # cmd self.command_lbl = Gtk.Label("Run command after Colorize") self.command_exe_lbl = Gtk.Label("Command: ") + self.command_txt = Gtk.Entry() self.command_txt.connect("changed", self.on_txt_change, "command") + self.command_switch = Gtk.Switch() - self.command_switch.connect("notify::active", - self.on_activate, "execute_cmd") + self.command_switch.connect( + "notify::active", + self.on_activate, + "execute_cmd" + ) self.alpha_lbl = Gtk.Label('Alpha:') self.alpha_txt = Gtk.Entry() From 8c60d4f59f6d025bad0f7e960b07dc93e3e42c75 Mon Sep 17 00:00:00 2001 From: deviantfero Date: Fri, 25 Jan 2019 08:25:55 -0600 Subject: [PATCH 27/45] write the file once the formatting is finished --- wpgtk/data/files.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/wpgtk/data/files.py b/wpgtk/data/files.py index 63bd1bee..1832f08a 100644 --- a/wpgtk/data/files.py +++ b/wpgtk/data/files.py @@ -117,6 +117,8 @@ def update_color(matchobj): def update_template(template_path): + tmp_data = "" + with open(template_path, "r") as f: tmp_data = f.read() @@ -129,6 +131,9 @@ def update_template(template_path): tmp_data = tmp_data.replace("#", "{active}") tmp_data = tmp_data.replace("#", "{inactive}") + with open(template_path, "w") as f: + logging.info("writting %s" % template_path) + f.write(tmp_data) logging.info("%s update complete" % template_path) From 2396d6e37690bd000ed26646a3d6d8afefd5ecd5 Mon Sep 17 00:00:00 2001 From: deviantfero Date: Mon, 28 Jan 2019 01:58:46 -0600 Subject: [PATCH 28/45] fix active/inactive in light colorscheme --- wpgtk/data/color.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpgtk/data/color.py b/wpgtk/data/color.py index 9194a722..e96efe7d 100755 --- a/wpgtk/data/color.py +++ b/wpgtk/data/color.py @@ -213,7 +213,7 @@ def wpgtk_colors(hexc, is_dark_theme=True): brightness = util.get_hls_val(hexc, "light") active = util.alter_brightness(hexc, brightness * -0.20) \ - if is_dark_theme else util.alter_brightness(hexc, brightness * -0.20) + if is_dark_theme else util.alter_brightness(hexc, brightness * 0.30) inactive = util.alter_brightness(hexc, brightness * -0.45) \ if is_dark_theme else hexc From a35ec5366b4ff932196cda694569ebc6582f441c Mon Sep 17 00:00:00 2001 From: deviantfero Date: Sun, 3 Feb 2019 16:22:18 -0600 Subject: [PATCH 29/45] remove create_sample repetition add it to render_sample instead --- wpgtk/gui/color_grid.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/wpgtk/gui/color_grid.py b/wpgtk/gui/color_grid.py index 7a83ec79..6a3b1cae 100644 --- a/wpgtk/gui/color_grid.py +++ b/wpgtk/gui/color_grid.py @@ -158,10 +158,10 @@ def hls_change(self, widget, *gparam): self.color_list = [util.alter_brightness(x, val, 0) for x in self.color_list] self.render_buttons() - sample.create_sample(self.color_list) self.render_sample() def render_sample(self): + sample.create_sample(self.color_list) sample_path = os.path.join(WALL_DIR, ".tmp.sample.png") self.pixbuf_sample = GdkPixbuf.Pixbuf.new_from_file_at_size( str(sample_path), @@ -195,9 +195,12 @@ def on_ok_click(self, widget): def on_auto_click(self, widget): self.color_list = color.auto_adjust_colors(self.color_list) self.render_buttons() - sample.create_sample(self.color_list) self.render_sample() + def on_reset_click(self, widget): + themer.reset_theme(self.selected_file) + self.render_theme() + def on_import_click(self, widget): fcd = Gtk.FileChooserDialog( 'Select a colorscheme', self.parent, @@ -214,14 +217,12 @@ def on_import_click(self, widget): if response == Gtk.ResponseType.OK: self.color_list = color.get_color_list(fcd.get_filename(), True) self.render_buttons() - sample.create_sample(self.color_list[:]) self.render_sample() fcd.destroy() def on_shuffle_click(self, widget): self.color_list = color.shuffle_colors(self.color_list) self.render_buttons() - sample.create_sample(self.color_list) self.render_sample() def on_color_click(self, widget): @@ -241,14 +242,15 @@ def on_color_click(self, widget): if util.get_hls_val(hex_color, 'light') < 100: fgcolor = Gdk.color_parse('#FFFFFF') else: - fgcolor = Gdk.color_parse('#101010') + fgcolor = Gdk.color_parse('#000000') + widget.set_sensitive(True) widget.modify_bg(Gtk.StateType.NORMAL, gcolor) widget.modify_fg(Gtk.StateType.NORMAL, fgcolor) + for i, c in enumerate(self.button_list): if c.get_label() != self.color_list[i]: self.color_list[i] = c.get_label() - sample.create_sample(self.color_list) self.render_sample() dialog.destroy() From d6e9298d59fbca76e0de1bb56d5444394de4cb6d Mon Sep 17 00:00:00 2001 From: deviantfero Date: Sun, 3 Feb 2019 16:23:04 -0600 Subject: [PATCH 30/45] separate rendering the theme to a different function --- wpgtk/gui/color_grid.py | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/wpgtk/gui/color_grid.py b/wpgtk/gui/color_grid.py index 6a3b1cae..8d8c9bb8 100644 --- a/wpgtk/gui/color_grid.py +++ b/wpgtk/gui/color_grid.py @@ -148,6 +148,26 @@ def render_buttons(self): button.modify_bg(Gtk.StateType.NORMAL, gcolor) button.modify_fg(Gtk.StateType.NORMAL, fgcolor) + def render_theme(self): + sample_path = files.get_sample_path(self.selected_file) + + try: + self.color_list = color.get_color_list(self.selected_file) + except SystemExit: + self.color_list = themer.set_fallback_theme(self.selected_file) + self.render_buttons() + + try: + self.pixbuf_sample = GdkPixbuf.Pixbuf\ + .new_from_file_at_size(sample_path, width=500, height=300) + except: + sample.create_sample(self.color_list, sample_path) + self.pixbuf_sample = GdkPixbuf.Pixbuf\ + .new_from_file_at_size(sample_path, width=500, height=300) + + self.sample.set_from_pixbuf(self.pixbuf_sample) + self.parent.sample.set_from_pixbuf(self.pixbuf_sample) + def hls_change(self, widget, *gparam): if gparam[0] == "sat": val = 0.05 if gparam[1] == "add" else -0.05 @@ -264,25 +284,10 @@ def combo_box_change(self, widget): self.import_button.set_sensitive(True) self.light_add.set_sensitive(True) self.light_red.set_sensitive(True) + self.reset_button.set_sensitive(True) self.sat_add.set_sensitive(True) self.sat_red.set_sensitive(True) current_walls = files.get_file_list() self.selected_file = current_walls[x] - sample_path = files.get_sample_path(self.selected_file) - try: - self.color_list = color.get_color_list(self.selected_file) - except SystemExit: - self.color_list = themer.set_fallback_theme(self.selected_file) - self.render_buttons() - - try: - self.pixbuf_sample = GdkPixbuf.Pixbuf\ - .new_from_file_at_size(sample_path, width=500, height=300) - except: - sample.create_sample(self.color_list, sample_path) - self.pixbuf_sample = GdkPixbuf.Pixbuf\ - .new_from_file_at_size(sample_path, width=500, height=300) - - self.sample.set_from_pixbuf(self.pixbuf_sample) - self.parent.sample.set_from_pixbuf(self.pixbuf_sample) + self.render_theme() From ed3bb8008385f387d0d43bc055c1e5f5c8130a68 Mon Sep 17 00:00:00 2001 From: deviantfero Date: Sun, 3 Feb 2019 16:23:37 -0600 Subject: [PATCH 31/45] handle delete_theme errors outside function --- wpgtk/data/themer.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/wpgtk/data/themer.py b/wpgtk/data/themer.py index b508b7fc..a2cdf5ed 100644 --- a/wpgtk/data/themer.py +++ b/wpgtk/data/themer.py @@ -58,12 +58,8 @@ def set_theme(wallpaper, colorscheme, restore=False): def delete_theme(filename): - try: - remove(path.join(WALL_DIR, filename)) - files.delete_colorschemes(filename) - except IOError as e: - logging.error("file not available") - logging.error(e.message) + remove(path.join(WALL_DIR, filename)) + files.delete_colorschemes(filename) def get_current(): From 17f855dceb78809233ca778e41dc9968fb65de89 Mon Sep 17 00:00:00 2001 From: deviantfero Date: Sun, 3 Feb 2019 16:23:50 -0600 Subject: [PATCH 32/45] add reset_theme function --- wpgtk/data/themer.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/wpgtk/data/themer.py b/wpgtk/data/themer.py index a2cdf5ed..441e5864 100644 --- a/wpgtk/data/themer.py +++ b/wpgtk/data/themer.py @@ -67,6 +67,14 @@ def get_current(): return image +def reset_theme(theme_name): + """restore a colorscheme to it's original state by deleting + and re adding the image""" + wallpaper = realpath(path.join(WALL_DIR, theme_name)) + delete_theme(theme_name) + create_theme(wallpaper) + + def import_theme(wallpaper, json_file, theme=False): """import a colorscheme from a JSON file either in terminal.sexy or pywal format""" From 2937c10932cfe818d0ffee11fc50c0b7f2a94670 Mon Sep 17 00:00:00 2001 From: deviantfero Date: Sun, 3 Feb 2019 16:24:02 -0600 Subject: [PATCH 33/45] add -R flag to reset themes to their original state --- wpgtk/__main__.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/wpgtk/__main__.py b/wpgtk/__main__.py index 9fc85035..ce9666de 100755 --- a/wpgtk/__main__.py +++ b/wpgtk/__main__.py @@ -91,6 +91,10 @@ def read_args(args): "format [wallpaper, json]", nargs="+") + parser.add_argument("-R", + help="reset template(s) to their original colors", + nargs="+") + parser.add_argument("--link", help="link config file to template backup " "[config, .base]", @@ -127,7 +131,7 @@ def read_args(args): def process_arg_errors(args): - if args.m and args.s: + if args.m and (args.s or args.R): logging.error("invalid combination of flags") exit(1) @@ -139,7 +143,7 @@ def process_arg_errors(args): logging.error("specify at most 2 filenames") exit(1) - if args.o and len(args.o) != 2: + if args.o and (len(args.o) < 1 or len(args.o) > 2): logging.error("specify wallpaper and optionally an output path") exit(1) @@ -190,7 +194,12 @@ def process_args(args): if args.d: delete_action = files.delete_template if args.t \ else themer.delete_theme - any(delete_action(x) for x in args.d) + try: + any(delete_action(x) for x in args.d) + except IOError: + logging.error("file not found") + exit(1) + exit(0) if args.a: @@ -231,6 +240,14 @@ def process_args(args): themer.export_theme(*args.o) exit(0) + if args.R: + try: + any(themer.reset_theme(arg) for arg in args.R) + except IOError: + logging.error("file not found") + exit(1) + exit(0) + if args.theme == "list": name_dic = pywal.theme.list_themes() name_list = [t.name.replace(".json", "") for t in name_dic] From 4f2cd31d332ebeb70ecaa43937bbb9dd78a343e2 Mon Sep 17 00:00:00 2001 From: deviantfero Date: Sun, 3 Feb 2019 16:24:20 -0600 Subject: [PATCH 34/45] add -R flag to autocompletion --- completions/bash/wpg | 2 +- completions/zsh/_wpg | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/completions/bash/wpg b/completions/bash/wpg index 681c506b..f460c4dd 100644 --- a/completions/bash/wpg +++ b/completions/bash/wpg @@ -2,7 +2,7 @@ function _wpg() { local optforprofiles _get_comp_words_by_ref cur # themes - optforprofiles="-s -e -d -z -m -LA -A --brt --sat" + optforprofiles="-s -e -d -z -m -LA -A --brt --sat -R" # themes, pywal themes optforvariabletheme="-Ti" # themes, filenames diff --git a/completions/zsh/_wpg b/completions/zsh/_wpg index 9adcc1d4..0fc22dda 100644 --- a/completions/zsh/_wpg +++ b/completions/zsh/_wpg @@ -7,9 +7,9 @@ _profiles() { } _templates() { - local -a templates - templates=(`wpg -tl`) - _describe 'templates' templates + local -a templates + templates=(`wpg -tl`) + _describe 'templates' templates } _backends() { @@ -27,7 +27,7 @@ _themes() { _wpg() { local state optforprofiles # themes - optforprofiles=(-s -e -d -z -m -A -LA --brt --sat) + optforprofiles=(-s -e -d -z -m -A -LA --brt --sat -R) # themes, filenames optvariable=(-i -o) # themes, pywal themes @@ -90,9 +90,9 @@ _wpg() { _themes fi done - fi - ;; - esac + fi + ;; + esac } _wpg "$@" From c7a64f279388b8a17b15d4b85070774e8cf2e6f9 Mon Sep 17 00:00:00 2001 From: deviantfero Date: Sun, 3 Feb 2019 17:05:01 -0600 Subject: [PATCH 35/45] re-arrange buttons to include reset action in UI --- wpgtk/gui/color_grid.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/wpgtk/gui/color_grid.py b/wpgtk/gui/color_grid.py index 8d8c9bb8..ab7b1595 100644 --- a/wpgtk/gui/color_grid.py +++ b/wpgtk/gui/color_grid.py @@ -64,6 +64,11 @@ def __init__(self, parent): self.button_grid.set_column_spacing(PAD) self.button_grid.set_row_spacing(PAD) + self.combo_grid = Gtk.Grid() + self.combo_grid.set_column_homogeneous(1) + self.combo_grid.set_column_spacing(PAD) + self.combo_grid.set_row_spacing(PAD) + self.color_list = ['000000']*16 self.button_list = [Gtk.Button('000000') for x in range(16)] self.selected_file = "" @@ -104,6 +109,10 @@ def __init__(self, parent): self.auto_button.connect("pressed", self.on_auto_click) self.auto_button.set_sensitive(False) + self.reset_button = Gtk.Button("Reset") + self.reset_button.set_sensitive(False) + self.reset_button.connect("pressed", self.on_reset_click) + self.done_lbl = Gtk.Label("") option_list = Gtk.ListStore(str) @@ -116,10 +125,13 @@ def __init__(self, parent): self.option_combo.set_entry_text_column(0) self.option_combo.connect("changed", self.combo_box_change) - self.button_grid.attach(self.import_button, 0, 0, 3, 1) - self.button_grid.attach(self.ok_button, 0, 1, 1, 1) - self.button_grid.attach(self.auto_button, 1, 1, 1, 1) - self.button_grid.attach(self.shuffle_button, 2, 1, 1, 1) + self.combo_grid.attach(self.option_combo, 0, 0, 3, 1) + self.combo_grid.attach(self.reset_button, 3, 0, 1, 1) + + self.button_grid.attach(self.ok_button, 0, 0, 1, 1) + self.button_grid.attach(self.auto_button, 1, 0, 1, 1) + self.button_grid.attach(self.shuffle_button, 2, 0, 1, 1) + self.button_grid.attach(self.import_button, 3, 0, 1, 1) self.sat_light_grid.attach(self.sat_lbl, 0, 0, 1, 1) self.sat_light_grid.attach(self.sat_red, 1, 0, 1, 1) @@ -129,7 +141,7 @@ def __init__(self, parent): self.sat_light_grid.attach(self.light_red, 4, 0, 1, 1) self.sat_light_grid.attach(self.light_add, 5, 0, 1, 1) - self.attach(self.option_combo, 0, 0, 1, 1) + self.attach(self.combo_grid, 0, 0, 1, 1) self.attach(self.button_grid, 0, 1, 1, 1) self.attach(self.colorgrid, 0, 2, 1, 1) self.attach(self.sample, 0, 3, 1, 1) From 0d18eb70fc517fe3e7391799233f0b65bff1dd9b Mon Sep 17 00:00:00 2001 From: deviantfero Date: Sun, 3 Feb 2019 17:32:13 -0600 Subject: [PATCH 36/45] add dark variant to icon-theme in installer --- wpgtk/misc/wpg-install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/wpgtk/misc/wpg-install.sh b/wpgtk/misc/wpg-install.sh index f04cf776..83c8c5d9 100755 --- a/wpgtk/misc/wpg-install.sh +++ b/wpgtk/misc/wpg-install.sh @@ -141,6 +141,7 @@ install_icons() { echo "Installing icon pack"; cp -r flattrcolor "${HOME}/.icons/" && \ + cp -r flattrcolor-dark "${HOME}/.icons/" && \ echo ":: flattr icons install done." } From cc64e02aabe3846709a5bb12f2db2d4e01774e82 Mon Sep 17 00:00:00 2001 From: deviantfero Date: Wed, 6 Feb 2019 01:34:59 -0600 Subject: [PATCH 37/45] use threads to process templates --- wpgtk/data/color.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/wpgtk/data/color.py b/wpgtk/data/color.py index e96efe7d..7dd96e31 100755 --- a/wpgtk/data/color.py +++ b/wpgtk/data/color.py @@ -3,6 +3,7 @@ import pywal import os import re +import threading from operator import itemgetter from subprocess import Popen from random import shuffle, randint @@ -174,7 +175,9 @@ def change_templates(colors): try: for template in templates: original = template.split(".base").pop(0) - change_colors(colors, os.path.join(OPT_DIR, original)) + args = (colors, os.path.join(OPT_DIR, original)) + t = threading.Thread(target=change_colors, args=args) + t.start() except Exception as e: logging.error(str(e)) From 3fdb4c9a9ae4eb997a793512f014a2c3bd09c12d Mon Sep 17 00:00:00 2001 From: deviantfero Date: Sun, 10 Feb 2019 20:18:31 -0600 Subject: [PATCH 38/45] only reload GTK+ if option is enabled --- wpgtk/data/reload.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/wpgtk/data/reload.py b/wpgtk/data/reload.py index 92778968..d7ea0e13 100644 --- a/wpgtk/data/reload.py +++ b/wpgtk/data/reload.py @@ -6,7 +6,7 @@ from pywal import reload from . import util -from .config import FORMAT_DIR, HOME +from .config import FORMAT_DIR, HOME, settings def xrdb(): @@ -36,7 +36,7 @@ def openbox(): def gtk3(): - if shutil.which("xsettingsd"): + if shutil.which("xsettingsd") and settings.getboolean("gtk", True): fd, path = tempfile.mkstemp() try: with os.fdopen(fd, 'w+') as tmp: @@ -56,9 +56,11 @@ def all(): tint2() dunst() openbox() - gtk3() reload.i3() reload.polybar() reload.gtk() reload.kitty() reload.sway() + + if settings.getboolean("gtk", True): + gtk3() From 9c3341b74cd3d4b0f34d9de15720881c8e415a17 Mon Sep 17 00:00:00 2001 From: deviantfero Date: Sun, 10 Feb 2019 21:05:29 -0600 Subject: [PATCH 39/45] change update_template flag for just update --- wpgtk/__main__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/wpgtk/__main__.py b/wpgtk/__main__.py index ce9666de..87e572cc 100755 --- a/wpgtk/__main__.py +++ b/wpgtk/__main__.py @@ -122,7 +122,7 @@ def read_args(args): help="preview your current colorscheme", action="store_true") - parser.add_argument("--update_template", + parser.add_argument("--update", help="update template(s) of your choice " "to the new format", nargs="+") @@ -280,9 +280,9 @@ def process_args(args): print("\n".join(pywal.colors.list_backends())) exit(0) - if args.update_template: - for arg in args.update_template: - files.update_template(arg) + if args.update: + for arg in args.update: + files.update(arg) exit(0) if args.backend and args.backend != "list": From 6f0e297925a5f736cb0442bdfebaff2e1f15665a Mon Sep 17 00:00:00 2001 From: deviantfero Date: Sun, 10 Feb 2019 21:15:23 -0600 Subject: [PATCH 40/45] change default configuration file --- wpgtk/misc/wpg.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpgtk/misc/wpg.conf b/wpgtk/misc/wpg.conf index 1e9077ba..d5f82ca2 100644 --- a/wpgtk/misc/wpg.conf +++ b/wpgtk/misc/wpg.conf @@ -8,7 +8,7 @@ execute_cmd = false command = urxvt -e echo hi backend = wal alpha = 100 -auto_sort = true +smart_sort = true auto_adjust = false [keywords] From c1732262a65e9fd1064bc02a3f88666badb70385 Mon Sep 17 00:00:00 2001 From: deviantfero Date: Sun, 10 Feb 2019 21:25:27 -0600 Subject: [PATCH 41/45] change link order to be consistent with ln, thus more intuitive --- wpgtk/__main__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wpgtk/__main__.py b/wpgtk/__main__.py index 87e572cc..5243de5b 100755 --- a/wpgtk/__main__.py +++ b/wpgtk/__main__.py @@ -97,7 +97,7 @@ def read_args(args): parser.add_argument("--link", help="link config file to template backup " - "[config, .base]", + "[.base, config]", nargs=2) parser.add_argument("--sat", @@ -229,7 +229,7 @@ def process_args(args): exit(0) if args.link: - files.add_template(args.link[0], args.link[1]) + files.add_template(args.link[1], args.link[0]) exit(0) if args.i: From 9998dc9a8bae58cf21c62eb223dd1cdf03b3903a Mon Sep 17 00:00:00 2001 From: deviantfero Date: Sun, 10 Feb 2019 21:29:37 -0600 Subject: [PATCH 42/45] order flags in a more logical manner --- wpgtk/__main__.py | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/wpgtk/__main__.py b/wpgtk/__main__.py index 5243de5b..f9edcd23 100755 --- a/wpgtk/__main__.py +++ b/wpgtk/__main__.py @@ -29,35 +29,43 @@ def read_args(args): help="delete the wallpaper(s) from wallpaper folder", nargs="+") + parser.add_argument("-t", + help="add, remove and list templates instead " + "of themes", + action="store_true") + parser.add_argument("-s", help="set the wallpaper and/or colorscheme", nargs="+") - parser.add_argument("-m", - help="pick a random wallpaper/colorscheme", - action="store_true") - parser.add_argument('-l', help="see which wallpapers are available", action="store_true") - parser.add_argument("-t", - help="add, remove and list templates instead " - "of themes", - action="store_true") - parser.add_argument("-n", help="avoid setting a wallpaper", action="store_true") - parser.add_argument("-r", - help="restore the wallpaper and colorscheme", + parser.add_argument("-m", + help="pick a random wallpaper/colorscheme", action="store_true") parser.add_argument("-c", help="shows the current wallpaper", action="store_true") + parser.add_argument("-z", + help="shuffles the given colorscheme(s)", + nargs="+") + + parser.add_argument("-A", + help="auto-adjusts the given colorscheme(s)", + nargs="+") + + parser.add_argument("-r", + help="restore the wallpaper and colorscheme", + action="store_true") + parser.add_argument("-L", "--light", help="temporarily enable light themes", action="store_true") @@ -73,14 +81,6 @@ def read_args(args): " instead of a json file", action="store_true") - parser.add_argument("-z", - help="shuffles the given colorscheme(s)", - nargs="+") - - parser.add_argument("-A", - help="auto-adjusts the given colorscheme(s)", - nargs="+") - parser.add_argument("-i", help="import a theme in json format and asign " "to wallpaper [wallpaper, json]", From 014acc082e50aa26f68bde0b0e1f24b542f3c863 Mon Sep 17 00:00:00 2001 From: deviantfero Date: Sun, 10 Feb 2019 21:43:36 -0600 Subject: [PATCH 43/45] ignore files that don't end with .base --- wpgtk/__main__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wpgtk/__main__.py b/wpgtk/__main__.py index f9edcd23..7508ed88 100755 --- a/wpgtk/__main__.py +++ b/wpgtk/__main__.py @@ -282,7 +282,8 @@ def process_args(args): if args.update: for arg in args.update: - files.update(arg) + if arg.endswith(".base"): + files.update_template(arg) exit(0) if args.backend and args.backend != "list": From b7ce530301a1b33ef30484c67a5340fdba22b1e2 Mon Sep 17 00:00:00 2001 From: deviantfero Date: Sun, 10 Feb 2019 21:47:34 -0600 Subject: [PATCH 44/45] update completion functions --- completions/bash/wpg | 8 ++++---- completions/zsh/_wpg | 26 +++++++++++++------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/completions/bash/wpg b/completions/bash/wpg index f460c4dd..69d952f7 100644 --- a/completions/bash/wpg +++ b/completions/bash/wpg @@ -1,14 +1,14 @@ function _wpg() { - local optforprofiles + local optforcolorschemes _get_comp_words_by_ref cur # themes - optforprofiles="-s -e -d -z -m -LA -A --brt --sat -R" + optforcolorschemes="-s -e -d -z -m -LA -A --brt --sat -R" # themes, pywal themes optforvariabletheme="-Ti" # themes, filenames optvariable="-i -o" # filenames - optfordefault="--link -aL -La -a -ta -at" + optfordefault="--link -aL -La -a -ta -at --update" # templates optfortemplates="-td -dt" # pywal backends @@ -19,7 +19,7 @@ function _wpg() { if [[ $COMP_CWORD = 1 ]]; then COMPREPLY=($(compgen -W "$(_parse_usage wpg)" -- "$cur")) elif [[ $COMP_CWORD < 4 || ${COMP_WORDS[1]} != "-s" ]]; then - for opt in $optforprofiles; do + for opt in $optforcolorschemes; do if [[ $opt = ${COMP_WORDS[1]} ]]; then COMPREPLY=($(compgen -W "$(wpg -l)" -- "$cur")) fi diff --git a/completions/zsh/_wpg b/completions/zsh/_wpg index 0fc22dda..afa3a610 100644 --- a/completions/zsh/_wpg +++ b/completions/zsh/_wpg @@ -1,9 +1,9 @@ #compdef wpg -_profiles() { - local -a profiles - profiles=(`wpg -l`) - _describe 'profiles' profiles +_colorschemes() { + local -a colorschemes + colorschemes=(`wpg -l`) + _describe 'colorschemes' colorschemes } _templates() { @@ -25,15 +25,15 @@ _themes() { } _wpg() { - local state optforprofiles + local state optforcolorschemes # themes - optforprofiles=(-s -e -d -z -m -A -LA --brt --sat -R) + optforcolorschemes=(-s -e -d -z -m -A -LA --brt --sat -R) # themes, filenames optvariable=(-i -o) # themes, pywal themes optvariabletheme=(-Ti) # filenames - optforgeneric=(--link -a -La -aL -ta -at --update_template) + optforgeneric=(--link -a -La -aL -ta -at --update) # templates optfortemplates=(-td -dt) # pywal backends @@ -43,29 +43,29 @@ _wpg() { _arguments \ '1: :->generic' \ - '*: :->listprofiles' + '*: :->listcolorschemes' case $state in (generic) _gnu_generic ;; - (listprofiles) + (listcolorschemes) if [[ $CURRENT < 5 || ${words[2]} != "-s" ]]; then - for opt in $optforprofiles; do + for opt in $optforcolorschemes; do if [[ $opt = ${words[2]} ]]; then - _profiles + _colorschemes fi done for opt in $optvariable; do if [[ $opt = ${words[2]} && $CURRENT < 4 ]]; then - _profiles + _colorschemes elif [[ $opt = ${words[2]} ]]; then _gnu_generic fi done for opt in $optvariabletheme; do if [[ $opt = ${words[2]} && $CURRENT < 4 ]]; then - _profiles + _colorschemes elif [[ $opt = ${words[2]} ]]; then _themes fi From 1f15384ad8dfc5dca7791ce1c111d6750abf80b0 Mon Sep 17 00:00:00 2001 From: deviantfero Date: Sun, 10 Feb 2019 22:46:33 -0600 Subject: [PATCH 45/45] update version tag --- wpgtk/data/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpgtk/data/config.py b/wpgtk/data/config.py index 7cf25b3a..df1209e0 100644 --- a/wpgtk/data/config.py +++ b/wpgtk/data/config.py @@ -3,7 +3,7 @@ import os import logging -__version__ = '5.8.7' +__version__ = '6.0.0' parser = None