From f0692c31eb91f0c6e5f2f5c8fdf4737808784362 Mon Sep 17 00:00:00 2001 From: Amit Prasad <17amitprasad@gmail.com> Date: Wed, 18 Dec 2019 13:28:13 -0500 Subject: Commented and minimize. --- README.md | 5 ----- pywal/export.py | 47 ++++++++++++++++++++++++----------------------- pywal/templates/functest | 1 + 3 files changed, 25 insertions(+), 28 deletions(-) create mode 100644 pywal/templates/functest diff --git a/README.md b/README.md index 5be06a9..f263c2f 100644 --- a/README.md +++ b/README.md @@ -13,11 +13,6 @@ Pywal is a tool that generates a color palette from the dominant colors in an image. It then applies the colors system-wide and on-the-fly in all of your favourite programs. -This fork of Pywal aims to create a more versatile system, by being able to modify colors in templates. Currently supported functions include: -* `lighten` -* `darken` -* `saturate` - There are currently 5 supported color generation backends, each providing a different palette of colors from each image. You're bound to find an appealing color-scheme. Pywal also supports predefined themes and has over 250 themes built-in. You can also create your own theme files to share with others. diff --git a/pywal/export.py b/pywal/export.py index ae619cd..f7b9de8 100644 --- a/pywal/export.py +++ b/pywal/export.py @@ -17,33 +17,34 @@ def template(colors, input_file, output_file=None): line = template_data[i] matches = re.finditer(r"(?<=(? 1: - args = func_split[1].split(",") - else: - args = [] - name = func_split[0] - if name[0] == '.': - name = name[1:] - x = getattr(colors[color], name) - if callable(x): - new_color = x(*args) - if func[0] != '.': - to_replace += "." - to_replace += func + ")" - else: - pass - if not new_color is None: + args = [] + if len(func_split) > 1: args = func_split[1].split(",") + fname = func_split[0] + if fname[0] == '.': fname = fname[1:] + f = getattr(new_color, fname) + + # If the function is callable, call it + if callable(f): + new_color = f(*args) + #add to the string that will replace the function calls with the generated function. + if func[0] != '.': replace_str += "." + replace_str += func + ")" + #If the color was changed, replace the template with a unique identifier for the new color. + if not new_color is colors[color]: cname = "color" + new_color.strip - template_data[i] = line.replace(to_replace, cname) + template_data[i] = line.replace(replace_str, cname) colors[cname] = new_color try: template_data = "".join(template_data).format(**colors) diff --git a/pywal/templates/functest b/pywal/templates/functest new file mode 100644 index 0000000..b82d4fc --- /dev/null +++ b/pywal/templates/functest @@ -0,0 +1 @@ +{color0.lighten(10).darken(10).rgb} -- cgit v1.2.3