diff --git a/wpgtk/__main__.py b/wpgtk/__main__.py index 68cceeca..cb089166 100755 --- a/wpgtk/__main__.py +++ b/wpgtk/__main__.py @@ -122,11 +122,6 @@ def read_args(args): help="preview your current colorscheme", action="store_true") - parser.add_argument("--update", - help="update template(s) of your choice " - "to the new format", - nargs="+") - parser.add_argument("--noreload", help="Skip reloading other software after" "applying colorscheme", @@ -136,6 +131,10 @@ def read_args(args): def process_arg_errors(args): + if args.r and not args.s: + logging.error("invalid combination of flags, use with -s") + exit(1) + if args.m and (args.s or args.R): logging.error("invalid combination of flags") exit(1) @@ -194,8 +193,8 @@ def process_args(args): if args.l: if args.t: - templates = files.get_file_list(OPT_DIR, False) - any(print(t) for t in templates if ".base" in t) + templates = files.get_file_list(OPT_DIR, r".*\.base$") + any(print(t) for t in templates) else: print("\n".join(files.get_file_list())) exit(0) @@ -295,12 +294,6 @@ def process_args(args): print("\n".join(pywal.colors.list_backends())) exit(0) - if args.update: - for arg in args.update: - if arg.endswith(".base"): - files.update_template(arg) - exit(0) - if args.noreload: settings["reload"] = "false" diff --git a/wpgtk/data/color.py b/wpgtk/data/color.py index 93ea70a0..0428bec8 100755 --- a/wpgtk/data/color.py +++ b/wpgtk/data/color.py @@ -8,8 +8,9 @@ from subprocess import Popen from random import shuffle, randint -from .config import settings, user_keywords +from .config import settings from .config import WALL_DIR, WPG_DIR, FILE_DIC, OPT_DIR +from . import keywords from . import files from . import util from . import sample @@ -169,8 +170,7 @@ def auto_adjust(colors): def change_templates(colors): """call change_colors on each custom template installed or defined by the user""" - templates = files.get_file_list(OPT_DIR, images=False) - templates = [x for x in templates if ".base" in x] + templates = files.get_file_list(OPT_DIR, r".*\.base$") try: for template in templates: @@ -230,38 +230,45 @@ def keyword_colors(hexc, is_dark_theme=True): } -def get_color_dict(cdic): - """ensamble wpgtk color dictionary""" +def get_color_dict(pywal_colors, colorscheme): + """ensamble wpgtk color dictionary from pywal color dictionary""" + keyword_set = settings.get('keywords', 'default') 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()) + base_color = pywal_colors["colors"]["color%s" % index] + color_list = list(pywal_colors["colors"].values()) + keyword_dict = keywords.get_keywords_section(keyword_set) all_colors = { - "wallpaper": cdic["wallpaper"], - "alpha": cdic["alpha"], - **cdic["special"], - **cdic["colors"], - **add_icon_colors(cdic), + "wallpaper": pywal_colors["wallpaper"], + "alpha": pywal_colors["alpha"], + **pywal_colors["special"], + **pywal_colors["colors"], + **add_icon_colors(pywal_colors), **keyword_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} + all_colors = { + k: pywal.util.Color(v) for k, v in all_colors.items() + } + try: + user_words = { + k: pywal.util.Color(v.format_map(all_colors)) + for k, v in keyword_dict.items() + } 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()} - + return {**all_colors, **user_words} -def apply_colorscheme(colors): - color_dict = get_color_dict(colors) +def apply_colorscheme(color_dict): + """Receives a colorscheme dict ensambled by + color.get_color_dict as argument and applies it + system-wide.""" if os.path.isfile(FILE_DIC["icon-step2"]): change_colors(color_dict, "icon-step1") Popen(FILE_DIC["icon-step2"]) diff --git a/wpgtk/data/config.py b/wpgtk/data/config.py index ed1dc097..c0604dda 100644 --- a/wpgtk/data/config.py +++ b/wpgtk/data/config.py @@ -3,9 +3,10 @@ import os import logging -__version__ = '6.2.5' +__version__ = '6.5.0' -parser = None + +settings = None HOME = os.getenv("HOME", os.path.expanduser("~")) CACHE = os.getenv("XDG_CACHE_HOME", os.path.join(HOME, ".cache")) @@ -14,6 +15,7 @@ WPG_DIR = os.path.join(CONFIG, "wpg") CONF_FILE = os.path.join(WPG_DIR, "wpg.conf") +KEYWORD_FILE = os.path.join(WPG_DIR, "keywords.conf") MODULE_DIR = os.path.abspath(os.path.join(__file__, "../../")) CONF_BACKUP = os.path.join(MODULE_DIR, "misc/wpg.conf") WALL_DIR = os.path.join(WPG_DIR, "wallpapers") @@ -30,24 +32,47 @@ def write_conf(config_path=CONF_FILE): - global parser + global config_parser with open(config_path, 'w') as config_file: - parser.write(config_file) + config_parser.write(config_file) + + +def write_keywords(keywords_path=KEYWORD_FILE): + global user_keywords + with open(keywords_path, 'w') as keywords_file: + user_keywords.write(keywords_file) -def load_sections(): + +def load_settings(): """reads the sections of the config file""" - global parser + global settings + global user_keywords + global config_parser - parser = configparser.ConfigParser() - parser.optionxform = str - parser.read(CONF_FILE) + config_parser = configparser.ConfigParser() + config_parser.optionxform = str + config_parser.read(CONF_FILE) + settings = config_parser['settings'] - return [parser['settings'], parser['keywords']] +def load_keywords(): + global user_keywords -def load_settings(): + if not os.path.exists(KEYWORD_FILE): + open(KEYWORD_FILE, 'a').close() + + user_keywords = configparser.ConfigParser() + user_keywords.optionxform = str + user_keywords.read(KEYWORD_FILE) + + if not user_keywords.has_section('default'): + user_keywords.add_section('default') + write_keywords() + + +def init_config(): os.makedirs(WALL_DIR, exist_ok=True) os.makedirs(SAMPLE_DIR, exist_ok=True) os.makedirs(SCHEME_DIR, exist_ok=True) @@ -55,13 +80,15 @@ def load_settings(): os.makedirs(OPT_DIR, exist_ok=True) try: - return load_sections() + load_settings() + load_keywords() except Exception: logging.error("not a valid config file") logging.info("copying default config file") shutil.copy(CONF_BACKUP, CONF_FILE) - return load_sections() + load_settings() + load_keywords() -settings, user_keywords = load_settings() +init_config() diff --git a/wpgtk/data/files.py b/wpgtk/data/files.py index dbf2a348..87e62b79 100644 --- a/wpgtk/data/files.py +++ b/wpgtk/data/files.py @@ -2,17 +2,23 @@ import shutil import re import logging +from subprocess import Popen from pywal.colors import cache_fname, list_backends -from .config import settings, WALL_DIR, WPG_DIR, OPT_DIR, SAMPLE_DIR from os.path import join, basename +from .config import ( + settings, + WALL_DIR, + WPG_DIR, + OPT_DIR, + SAMPLE_DIR, +) -def get_file_list(path=WALL_DIR, images=True): - """gets filenames in a given directory, optional - parameters for image filter.""" +def get_file_list(path=WALL_DIR, regex=None): + """gets file names in a given directory, optional regex + parameter to filter the list of files by.""" - valid = re.compile(r"^[^\.](.*\.png$|.*\.jpg$|.*\.jpeg$|.*\.jpe$|.*\.gif$)") files = [] for _, _, filenames in os.walk(path): @@ -21,7 +27,8 @@ def get_file_list(path=WALL_DIR, images=True): files.sort() - if images: + if regex is not None: + valid = re.compile(regex) return [elem for elem in files if valid.fullmatch(elem)] else: return files @@ -39,6 +46,7 @@ def write_script(wallpaper, colorscheme): 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]) + Popen(['chmod', '+x', join(WPG_DIR, "wp_init.sh")]) def get_cache_path(wallpaper, backend=None): @@ -79,8 +87,7 @@ def add_template(cfile, bfile=None): src_file = bfile if bfile else cfile shutil.copy2(src_file, join(OPT_DIR, template_name)) - os.symlink(cfile, join(OPT_DIR, - template_name.replace(".base", ""))) + os.symlink(cfile, join(OPT_DIR, template_name.replace(".base", ""))) logging.info("created backup %s.bak" % cfile) logging.info("added %s @ %s" % (template_name, cfile)) @@ -102,42 +109,16 @@ def delete_template(basefile): logging.error(str(e.strerror)) -def delete_colorschemes(wallpaper): - """delete all colorschemes related to the given wallpaper""" +def delete_colorschemes(colorscheme): + """delete all files related to the given colorscheme""" for backend in list_backends(): try: - os.remove(get_cache_path(wallpaper, backend)) - os.remove(get_sample_path(wallpaper, backend)) + os.remove(get_cache_path(colorscheme, backend)) + os.remove(get_sample_path(colorscheme, backend)) except OSError: pass -def update_color(matchobj): - if matchobj.group(1): - return "{%s}" % matchobj.group(1).lower() - - -def update_template(template_path): - tmp_data = "" - - 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}") - - with open(template_path, "w") as f: - logging.info("writting %s" % template_path) - f.write(tmp_data) - 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")) diff --git a/wpgtk/data/keywords.py b/wpgtk/data/keywords.py index 98e912c8..df41f172 100644 --- a/wpgtk/data/keywords.py +++ b/wpgtk/data/keywords.py @@ -1,41 +1,71 @@ -from .config import user_keywords, write_conf +from .config import user_keywords, write_keywords KEY_LENGTH = 5 VAL_LENGTH = 2 -def update_key(old_keyword, new_keyword, save=False): - """validates and updates a keyword""" +def delete_keywords_section(name): + if name != 'default': + user_keywords.remove_section(name) + write_keywords() + + +def create_keywords_section(name): + user_keywords.add_section(name) + write_keywords() + + +def get_keywords_section(theme): + """get keyword file configparser for current wallpaper + or create one if it does not exist""" + if not user_keywords.has_section(theme): + create_keywords_section(theme) + + return user_keywords[theme] + + +def update_key(old_keyword, new_keyword, theme=None): + """validates and updates a keyword for a wallpaper""" if not new_keyword: raise Exception('Keyword must be longer than 5 characters') - user_keywords[new_keyword] = user_keywords[old_keyword] + keywords = get_keywords_section(theme) + keywords[new_keyword] = keywords[old_keyword] - if(old_keyword != new_keyword): - user_keywords.pop(old_keyword, None) + if (old_keyword != new_keyword): + keywords.pop(old_keyword, None) - if save: - write_conf() + write_keywords() -def update_value(keyword, value, save=False): +def update_value(keyword, value, theme): + """update the value to replace the user defined keyword with""" if not value: raise Exception('Value must exist') - user_keywords[keyword] = value + keywords = get_keywords_section(theme) + keywords[keyword] = value - if save: - write_conf() + write_keywords() -def create_pair(keyword, value, save=False): +def create_pair(keyword, value, theme): + """create a key value pair for a wallpaper""" if not value: raise Exception('There must be a value') if not keyword: - raise Exception('There must be a value') + raise Exception('There must be a keyword') + + keywords = get_keywords_section(theme) + keywords[keyword] = value + + write_keywords() + - user_keywords[keyword] = value +def remove_pair(keyword, theme): + """removes a pair of keyword value for a wallpaper""" + keywords = get_keywords_section(theme) + keywords.pop(keyword, None) - if save: - write_conf() + write_keywords() diff --git a/wpgtk/data/reload.py b/wpgtk/data/reload.py index ec09cb8f..6a4415a4 100644 --- a/wpgtk/data/reload.py +++ b/wpgtk/data/reload.py @@ -108,7 +108,6 @@ def gtk3(): else: xsettingsd("FlatColor") - # The system has no known settings daemon installed, # but dconf gtk-theme exists, just refreshing its theme # Because user might be using unknown settings daemon diff --git a/wpgtk/data/sample.py b/wpgtk/data/sample.py index 3fe62964..25ee6a33 100755 --- a/wpgtk/data/sample.py +++ b/wpgtk/data/sample.py @@ -10,6 +10,7 @@ def create_sample(colors, f=os.path.join(WALL_DIR, ".tmp.sample.png")): + """Creates sample image from a pywal color dictionary""" im = Image.new("RGB", (480, 50), "white") pix = im.load() width_sample = im.size[0]//(len(colors)//2) diff --git a/wpgtk/data/themer.py b/wpgtk/data/themer.py index 6ebc35a4..6d8faa23 100644 --- a/wpgtk/data/themer.py +++ b/wpgtk/data/themer.py @@ -1,11 +1,10 @@ import pywal import shutil import logging -from os.path import realpath, basename from os import remove, path, symlink from subprocess import Popen -from .config import WPG_DIR, WALL_DIR, FORMAT_DIR, settings +from .config import WPG_DIR, WALL_DIR, FORMAT_DIR, settings, user_keywords from . import color from . import files from . import sample @@ -14,8 +13,8 @@ def create_theme(filepath): """create a colors-scheme from a filepath""" - filepath = realpath(filepath) - filename = basename(filepath).replace(" ", "_") + filepath = path.realpath(filepath) + filename = path.basename(filepath).replace(" ", "_") tmplink = path.join(WALL_DIR, ".tmp.link") symlink(filepath, tmplink) @@ -40,7 +39,7 @@ def set_theme(wallpaper, colorscheme, restore=False): if not restore: pywal.export.every(colors, FORMAT_DIR) - color.apply_colorscheme(colors) + color.apply_colorscheme(color.get_color_dict(colors, colorscheme)) if reload_all: reload.all() else: @@ -48,25 +47,24 @@ def set_theme(wallpaper, colorscheme, restore=False): if set_wall: filepath = path.join(WALL_DIR, wallpaper) - set_wall = filepath if path.isfile(filepath) else colors["wallpaper"] - pywal.wallpaper.change(set_wall) + imagepath = filepath if path.isfile(filepath) else colors["wallpaper"] + pywal.wallpaper.change(imagepath) files.write_script(wallpaper, colorscheme) files.change_current(wallpaper) - Popen(['chmod', '+x', path.join(WPG_DIR, "wp_init.sh")]) - if settings.getboolean('execute_cmd', False) and not restore: - Popen(['bash', '-c', settings['command']]) + Popen(settings['command'].split()) def delete_theme(filename): remove(path.join(WALL_DIR, filename)) files.delete_colorschemes(filename) + user_keywords.remove_section(filename) def get_current(): - image = basename(realpath(path.join(WPG_DIR, '.current'))) + image = path.basename(path.realpath(path.join(WPG_DIR, '.current'))) return image @@ -84,8 +82,8 @@ def reset_theme(theme_name): def import_theme(wallpaper, json_file, theme=False): """import a colorscheme from a JSON file either in terminal.sexy or pywal format""" - json_file = realpath(json_file) - filename = basename(json_file) + json_file = path.realpath(json_file) + filename = path.basename(json_file) if theme: theme = pywal.theme.file(filename) diff --git a/wpgtk/gui/color_grid.py b/wpgtk/gui/color_grid.py index bc9d2744..2c61e095 100644 --- a/wpgtk/gui/color_grid.py +++ b/wpgtk/gui/color_grid.py @@ -202,13 +202,6 @@ def render_sample(self): height=300) self.sample.set_from_pixbuf(self.pixbuf_sample) - def update_combo(self, option_list): - self.option_combo.set_model(option_list) - self.option_combo.set_entry_text_column(0) - - def set_edit_combo(self, x): - self.option_combo.set_active(x) - def on_ok_click(self, widget): current_walls = files.get_file_list() if len(current_walls) > 0: diff --git a/wpgtk/gui/keyword_dialog.py b/wpgtk/gui/keyword_dialog.py new file mode 100644 index 00000000..35b6af0a --- /dev/null +++ b/wpgtk/gui/keyword_dialog.py @@ -0,0 +1,29 @@ +from gi import require_version +from gi.repository import Gtk +require_version("Gtk", "3.0") + + +class KeywordDialog(Gtk.Dialog): + + def __init__(self, parent): + Gtk.Dialog.__init__(self, "Name you keyword/value set", parent, 0, + (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, + Gtk.STOCK_OK, Gtk.ResponseType.OK)) + + self.set_default_size(150, 100) + self.name_text_input = Gtk.Entry() + self.error_lbl = Gtk.Label() + + box = self.get_content_area() + box.set_border_width(10) + box.set_spacing(10) + box.add(self.name_text_input) + box.add(self.error_lbl) + + self.show_all() + + def get_section_name(self): + if len(self.name_text_input.get_text()) <= 0: + raise Exception('Empty name not allowed') + + return self.name_text_input.get_text() diff --git a/wpgtk/gui/keyword_grid.py b/wpgtk/gui/keyword_grid.py index d1071ba0..05ab3482 100644 --- a/wpgtk/gui/keyword_grid.py +++ b/wpgtk/gui/keyword_grid.py @@ -1,11 +1,14 @@ -from ..data.config import user_keywords, write_conf +import logging from ..data import keywords +from ..data.config import user_keywords, settings, write_conf from gi import require_version from gi.repository import Gtk +from .keyword_dialog import KeywordDialog require_version("Gtk", "3.0") PAD = 10 +# TODO: if create section, select the new valid section class KeywordGrid(Gtk.Grid): def __init__(self, parent): @@ -18,31 +21,51 @@ def __init__(self, parent): self.set_column_spacing(PAD) self.liststore = Gtk.ListStore(str, str) - self.reload_keyword_list() - self.save_btn = Gtk.Button('Save') - self.save_btn.connect('clicked', self.save_keywords) + self.remove_button = Gtk.Button('Remove Keyword') + self.remove_button.connect('clicked', self.remove_keyword) - self.del_btn = Gtk.Button('Remove') - self.del_btn.connect('clicked', self.remove_keyword) + self.add_button = Gtk.Button('Add Keyword') + self.add_button.connect('clicked', self.append_new_keyword) - self.add_btn = Gtk.Button('Add') - self.add_btn.connect('clicked', self.append_new_keyword) + self.choose_button = Gtk.Button('Choose Set') + self.choose_button.connect('clicked', self.choose_keywords_section) - self.status_lbl = Gtk.Label('') + self.create_button = Gtk.Button('Create Set') + self.create_button.connect('clicked', self.create_keywords_section) + + self.delete_button = Gtk.Button('Delete Set') + self.delete_button.connect('clicked', self.delete_keywords_section) + + self.sections_combo = Gtk.ComboBoxText() + self.sections_combo.connect("changed", self.on_section_change) + self.reload_section_list() + + self.selected_file = settings.get("keywords", "default") + idx = list(user_keywords.sections()).index(self.selected_file) + self.sections_combo.set_active(idx) + self.delete_button.set_sensitive(self.selected_file != 'default') + self.choose_button.set_sensitive(False) + + self.reload_keyword_list() + self.status_lbl = Gtk.Label('') self.keyword_tree = Gtk.TreeView(model=self.liststore) scroll = Gtk.ScrolledWindow() scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) - scroll.set_min_content_height(400) + scroll.set_min_content_height(320) + scroll.set_propagate_natural_height(True) scroll.add(self.keyword_tree) - self.attach(self.add_btn, 0, 0, 2, 1) - self.attach(self.save_btn, 0, 1, 1, 1) - self.attach(self.del_btn, 1, 1, 1, 1) - self.attach(scroll, 0, 2, 2, 1) - self.attach(self.status_lbl, 0, 3, 2, 1) + self.attach(self.sections_combo, 0, 0, 2, 1) + self.attach(self.choose_button, 2, 0, 1, 1) + self.attach(self.delete_button, 3, 0, 1, 1) + self.attach(self.create_button, 0, 1, 4, 1) + self.attach(scroll, 0, 2, 4, 1) + self.attach(self.add_button, 0, 3, 2, 1) + self.attach(self.remove_button, 2, 3, 2, 1) + self.attach(self.status_lbl, 0, 4, 4, 1) key_renderer = Gtk.CellRendererText() key_renderer.set_property('editable', True) @@ -61,36 +84,85 @@ def __init__(self, parent): def remove_keyword(self, widget): self.status_lbl.set_text('') (m, pathlist) = self.keyword_tree.get_selection().get_selected_rows() + for path in pathlist: tree_iter = m.get_iter(path) value = m.get_value(tree_iter, 0) - user_keywords.pop(value, None) + keywords.remove_pair(value, self.selected_file) self.reload_keyword_list() def text_edited(self, widget, path, text, col): self.status_lbl.set_text('') - if(col == 0): + if (col == 0): try: - keywords.update_key(self.liststore[path][col], text) + keywords.update_key(self.liststore[path][col], text, + self.selected_file) except Exception as e: self.status_lbl.set_text(str(e)) else: try: - keywords.update_value(self.liststore[path][0], text) + keywords.update_value(self.liststore[path][0], text, + self.selected_file) except Exception as e: self.status_lbl.set_text(str(e)) self.reload_keyword_list() + def reload_section_list(self, active='default'): + sections = list(user_keywords.sections()) + self.sections_combo.remove_all() + + for item in sections: + self.sections_combo.append_text(item) + + self.sections_combo.set_active(sections.index(active)) + def reload_keyword_list(self): + keyword_section = keywords.get_keywords_section(self.selected_file) + self.liststore.clear() - for k, v in user_keywords.items(): + for k, v in keyword_section.items(): self.liststore.append([k, v]) - def save_keywords(self, widget): - write_conf() - self.status_lbl.set_text('Saved') + def on_section_change(self, widget): + self.selected_file = widget.get_active_text() + + if self.selected_file is not None: + self.reload_keyword_list() + self.choose_button.set_sensitive( + settings.get('keywords', 'default') != self.selected_file + ) + settings['keywords'] = self.selected_file + self.delete_button.set_sensitive(self.selected_file != 'default') def append_new_keyword(self, widget): self.status_lbl.set_text('') - keywords.create_pair('keyword' + str(len(self.liststore)), 'value') + keywords.create_pair( + 'keyword' + str(len(self.liststore)), + 'value', + self.selected_file, + ) self.reload_keyword_list() + + def delete_keywords_section(self, widget): + if self.selected_file: + keywords.delete_keywords_section(self.selected_file) + self.reload_section_list() + + def choose_keywords_section(self, widget): + write_conf() + self.choose_button.set_sensitive(False) + + def create_keywords_section(self, widget): + dialog = KeywordDialog(self.parent) + response = dialog.run() + + if response == Gtk.ResponseType.OK: + try: + section = dialog.get_section_name() + keywords.create_keywords_section(section) + self.reload_section_list(section) + except Exception as e: + logging.error(str(e)) + dialog.destroy() + if response == Gtk.ResponseType.CANCEL: + dialog.destroy() diff --git a/wpgtk/gui/option_grid.py b/wpgtk/gui/option_grid.py index eebedbe6..08f7faaa 100644 --- a/wpgtk/gui/option_grid.py +++ b/wpgtk/gui/option_grid.py @@ -33,36 +33,23 @@ def __init__(self, parent): # Setting up ComboBox color_list = ['Random'] + [str(x) for x in range(1, 16)] - option_list = Gtk.ListStore(str) + self.color_combo = Gtk.ComboBoxText() for elem in list(color_list): - option_list.append([elem]) - - # ComboBox - self.color_combo = Gtk.ComboBox.new_with_model(option_list) - self.renderer_text = Gtk.CellRendererText() - self.color_combo.pack_start(self.renderer_text, True) - self.color_combo.add_attribute(self.renderer_text, 'text', 0) - self.color_combo.set_entry_text_column(0) + self.color_combo.append_text(elem) self.color_combo.connect("changed", self.combo_box_change, "active") # Button self.color_button = Gtk.Button("Active/Inactive Color") self.save_button = Gtk.Button("Save") self.save_button.connect("pressed", self.on_save_button) - self.lbl_save = Gtk.Label("") # Backend Combo - self.backend_list = colors.list_backends() self.backend_lbl = Gtk.Label("Select your backend:") + self.backend_combo = Gtk.ComboBoxText() + self.backend_list = colors.list_backends() - 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) - self.backend_combo.set_entry_text_column(0) + self.backend_combo.append_text(elem) self.backend_combo.connect("changed", self.combo_box_change, "backend") # Switches @@ -183,21 +170,22 @@ def __init__(self, parent): self.active_grid.attach(self.alpha_txt, 2, 5, 1, 1) self.active_grid.attach(self.save_button, 1, 6, 2, 1) - self.active_grid.attach(self.lbl_save, 1, 7, 2, 1) self.attach(self.switch_grid, 1, 1, 1, 1) self.attach(self.active_grid, 1, 2, 1, 1) + self.save_button.set_sensitive(False) + def on_activate(self, switch, *gparam): if(gparam[1] == 'execute_cmd'): self.command_txt.set_editable(switch.get_active()) settings[gparam[1]] = str(switch.get_active()).lower() - self.lbl_save.set_text('') + self.save_button.set_sensitive(True) def load_opt_list(self): current_backend = settings.get("backend", "wal") - i = self.backend_list.index(current_backend) - self.backend_combo.set_active(i) + idx = self.backend_list.index(current_backend) + self.backend_combo.set_active(idx) self.color_combo\ .set_active(settings.getint("active", 0)) @@ -227,18 +215,19 @@ def load_opt_list(self): def combo_box_change(self, combo, *gparam): x = combo.get_active() - if(gparam[0] == "active"): + item = combo.get_active_text() + + if gparam[0] == "active": settings[gparam[0]] = str(x) color = Gdk.color_parse(self.parent.cpage.color_list[x]) self.color_button.modify_bg(Gtk.StateType.NORMAL, color) - else: - settings[gparam[0]] = self.backend_list[x] - self.lbl_save.set_text("") + if gparam[0] == "backend": + settings[gparam[0]] = item + self.save_button.set_sensitive(True) def on_txt_change(self, gtk_entry, *gparam): settings[gparam[0]] = gtk_entry.get_text() - self.lbl_save.set_text("") def on_save_button(self, button): write_conf() - self.lbl_save.set_text("Saved") + self.save_button.set_sensitive(False) diff --git a/wpgtk/gui/template_grid.py b/wpgtk/gui/template_grid.py index 5cea2642..8b2f72a6 100644 --- a/wpgtk/gui/template_grid.py +++ b/wpgtk/gui/template_grid.py @@ -39,8 +39,8 @@ def __init__(self, parent): self.button_add.connect('clicked', self.on_add_clicked) self.button_rm = Gtk.Button('Remove') self.button_rm.connect('clicked', self.on_rm_clicked) - self.button_open = Gtk.Button('Edit') - self.button_open.connect('clicked', self.on_open_clicked) + self.button_edit = Gtk.Button('Edit') + self.button_edit.connect('clicked', self.on_open_clicked) self.liststore = Gtk.ListStore(Pixbuf, str) self.file_view = Gtk.IconView.new() @@ -55,17 +55,15 @@ def __init__(self, parent): self.scroll.set_min_content_height(400) self.scroll.add(self.file_view) - self.item_names = [filen for filen in - files.get_file_list(OPT_DIR, False) - if '.base' in filen] + self.item_names = files.get_file_list(OPT_DIR, r".*\.base$") for filen in self.item_names: pixbuf = Gtk.IconTheme.get_default().load_icon(icon, 64, 0) self.liststore.append([pixbuf, filen]) self.grid_edit.attach(self.button_add, 0, 0, 2, 1) - self.grid_edit.attach(self.button_rm, 0, 1, 1, 1) - self.grid_edit.attach(self.button_open, 1, 1, 1, 1) + self.grid_edit.attach(self.button_edit, 0, 1, 1, 1) + self.grid_edit.attach(self.button_rm, 1, 1, 1, 1) self.grid_edit.attach(self.scroll, 0, 2, 2, 1) self.attach(self.grid_edit, 0, 0, 1, 1) @@ -87,9 +85,7 @@ def on_add_clicked(self, widget): if response == Gtk.ResponseType.OK: for f in filechooser.get_filenames(): files.add_template(f) - self.item_names = [f for f in - files.get_file_list(OPT_DIR, False) - if '.base' in f] + self.item_names = files.get_file_list(OPT_DIR, r".*\.base$") self.liststore = Gtk.ListStore(Pixbuf, str) for filen in self.item_names: pixbuf = Gtk.IconTheme.get_default().load_icon(icon, 64, 0) diff --git a/wpgtk/gui/theme_picker.py b/wpgtk/gui/theme_picker.py index c760e75d..bc5062a8 100755 --- a/wpgtk/gui/theme_picker.py +++ b/wpgtk/gui/theme_picker.py @@ -132,16 +132,21 @@ def on_add_clicked(self, widget): response = filechooser.run() if response == Gtk.ResponseType.OK: + option_list = Gtk.ListStore(str) + for f in filechooser.get_filenames(): themer.create_theme(f) - option_list = Gtk.ListStore(str) + for elem in list(files.get_file_list()): option_list.append([elem]) + self.option_combo.set_model(option_list) self.option_combo.set_entry_text_column(0) self.colorscheme.set_model(option_list) self.colorscheme.set_entry_text_column(0) - self.cpage.update_combo(option_list) + + self.cpage.option_combo.set_model(option_list) + filechooser.destroy() def on_set_clicked(self, widget): @@ -165,8 +170,8 @@ def on_rm_clicked(self, widget): self.option_combo.set_model(option_list) self.option_combo.set_entry_text_column(0) self.colorscheme.set_model(option_list) - self.colorscheme.set_entry_text_column(0) - self.cpage.update_combo(option_list) + + self.cpage.option_combo.set_model(option_list) def combo_box_change(self, widget): self.set_button.set_sensitive(True) @@ -184,9 +189,7 @@ def combo_box_change(self, widget): def colorscheme_box_change(self, widget): x = self.colorscheme.get_active() - - # set the ComboBox in color_grid - self.cpage.set_edit_combo(x) + self.cpage.option_combo.set_active(x) def run(args): @@ -194,7 +197,3 @@ def run(args): win.connect('delete-event', Gtk.main_quit) win.show_all() Gtk.main() - - -if __name__ == '__main__': - run()