Commented and minimize.

This commit is contained in:
Amit Prasad 2019-12-18 13:28:13 -05:00
parent 0a4f2e6dae
commit f0692c31eb
3 changed files with 25 additions and 28 deletions

View File

@ -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. 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. 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. Pywal also supports predefined themes and has over 250 themes built-in. You can also create your own theme files to share with others.

View File

@ -17,33 +17,34 @@ def template(colors, input_file, output_file=None):
line = template_data[i] line = template_data[i]
matches = re.finditer(r"(?<=(?<!\{))(\{([^{}]+)\})(?=(?!\}))", line) matches = re.finditer(r"(?<=(?<!\{))(\{([^{}]+)\})(?=(?!\}))", line)
for match in matches: for match in matches:
# Check that this color doesn't already exist # Get the color, and the functions associated with it
color, _, funcs = match.group(2).partition(".") color, _, funcs = match.group(2).partition(".")
#Check that functions are needed for this color
if len(funcs) != 0: if len(funcs) != 0:
to_replace = color #Build up a string which will be replaced when the color is done processing
new_color = None replace_str = color
for func in funcs.split(")"): #The modified color
if len(func) == 0: new_color = colors[color]
continue #Execute each function to be done
for func in filter(None,funcs.split(")")):
### Get function name and arguments
func_split = func.split("(") func_split = func.split("(")
if len(func_split) > 1:
args = func_split[1].split(",")
else:
args = [] args = []
name = func_split[0] if len(func_split) > 1: args = func_split[1].split(",")
if name[0] == '.': fname = func_split[0]
name = name[1:] if fname[0] == '.': fname = fname[1:]
x = getattr(colors[color], name) f = getattr(new_color, fname)
if callable(x):
new_color = x(*args) # If the function is callable, call it
if func[0] != '.': if callable(f):
to_replace += "." new_color = f(*args)
to_replace += func + ")" #add to the string that will replace the function calls with the generated function.
else: if func[0] != '.': replace_str += "."
pass replace_str += func + ")"
if not new_color is None: #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 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 colors[cname] = new_color
try: try:
template_data = "".join(template_data).format(**colors) template_data = "".join(template_data).format(**colors)

1
pywal/templates/functest Normal file
View File

@ -0,0 +1 @@
{color0.lighten(10).darken(10).rgb}