9 Commits

Author SHA1 Message Date
8f222f1cb8 Merge pull request 'Update dependency pylint to v2.17.7' (#1) from renovate/pylint-2.x into master
All checks were successful
Tests / test (3.10) (push) Successful in 1m23s
Tests / test (3.11) (push) Successful in 1m22s
Tests / test (3.8) (push) Successful in 1m23s
Tests / test (3.9) (push) Successful in 1m23s
Reviewed-on: #1
2024-01-21 18:31:05 +02:00
0a395afd24 Merge pull request 'Update dependency pytest to v7.4.4' (#2) from renovate/pytest-7.x into master
Some checks failed
Tests / test (3.11) (push) Waiting to run
Tests / test (3.8) (push) Waiting to run
Tests / test (3.9) (push) Waiting to run
Tests / test (3.10) (push) Has been cancelled
Reviewed-on: #2
2024-01-21 18:30:57 +02:00
e7a098bdf5 RGB mode fixed
Some checks failed
Tests / test (3.8) (push) Waiting to run
Tests / test (3.9) (push) Waiting to run
Tests / test (3.10) (push) Successful in 1m26s
Tests / test (3.11) (push) Has been cancelled
2024-01-21 17:28:57 +01:00
b67b23036d Image mode won't be attempted to be set
Some checks failed
Tests / test (3.10) (push) Failing after 1m23s
Tests / test (3.11) (push) Failing after 1m26s
Tests / test (3.8) (push) Failing after 1m22s
Tests / test (3.9) (push) Failing after 1m23s
2024-01-21 17:05:48 +01:00
d5f4bd79be Update dependency pytest to v7.4.4
Some checks failed
Tests / test (3.11) (pull_request) Has been cancelled
Tests / test (3.8) (pull_request) Has been cancelled
Tests / test (3.9) (pull_request) Has been cancelled
Tests / test (3.10) (pull_request) Has been cancelled
2024-01-21 18:00:43 +02:00
9aed62189d Update dependency pylint to v2.17.7
Some checks failed
Tests / test (3.10) (pull_request) Failing after 1m28s
Tests / test (3.11) (pull_request) Failing after 1m24s
Tests / test (3.8) (pull_request) Failing after 1m24s
Tests / test (3.9) (pull_request) Failing after 1m23s
2024-01-21 18:00:38 +02:00
67b5be094c Add .renovaterc
Some checks failed
Tests / test (3.10) (push) Failing after 1m21s
Tests / test (3.11) (push) Failing after 1m24s
Tests / test (3.8) (push) Failing after 1m21s
Tests / test (3.9) (push) Failing after 1m23s
2024-01-21 17:34:57 +02:00
7afb325ebd Update src/huepaper/__init__.py
Some checks failed
Tests / test (3.10) (push) Failing after 1m23s
Tests / test (3.11) (push) Failing after 1m25s
Tests / test (3.8) (push) Failing after 1m25s
Tests / test (3.9) (push) Has been cancelled
2024-01-21 17:30:36 +02:00
95ed004805 Update requirements/_.txt
Some checks failed
Tests / test (3.11) (push) Waiting to run
Tests / test (3.8) (push) Waiting to run
Tests / test (3.9) (push) Waiting to run
Tests / test (3.10) (push) Has been cancelled
2024-01-21 17:30:16 +02:00
7 changed files with 52 additions and 25 deletions

24
.renovaterc Normal file
View File

@@ -0,0 +1,24 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:base"
],
"pip_requirements": {
"fileMatch": [
"requirements/.*\\.txt$"
],
"enabled": true
},
"packageRules": [
{
"matchUpdateTypes": [
"minor",
"patch",
"pin",
"digest"
],
"automerge": true
}
]
}

View File

@@ -10,5 +10,7 @@
}, },
"[toml]": { "[toml]": {
"editor.defaultFormatter": "tamasfe.even-better-toml" "editor.defaultFormatter": "tamasfe.even-better-toml"
} },
"python.analysis.typeCheckingMode": "basic",
"python.analysis.autoImportCompletions": true
} }

View File

@@ -1,3 +1,3 @@
colour==0.1.5 colour==0.1.5
numpy~=1.24.0,<1.25.0 numpy~=1.24.0,<1.25.0
pillow~=10.0.0 pillow~=10.2.0

View File

@@ -2,8 +2,8 @@ black==23.7.0
build==0.10.0 build==0.10.0
isort==5.12.0 isort==5.12.0
mypy==1.4.1 mypy==1.4.1
pylint==2.17.5 pylint==2.17.7
pytest-cov==4.1.0 pytest-cov==4.1.0
pytest==7.4.0 pytest==7.4.4
tox==4.7.0 tox==4.7.0
twine==4.0.2 twine==4.0.2

View File

@@ -1,4 +1,4 @@
__version__ = "0.0.4" __version__ = "0.0.5"
from . import utils from . import utils
from .generator import generate from .generator import generate

View File

@@ -44,10 +44,10 @@ def generate(
raise ValueError("Pixelation value must be set in form: 42x42") raise ValueError("Pixelation value must be set in form: 42x42")
try: try:
random_color = False if color else True random_color = not color
base_color = get_base_color(color, sat_min, sat_max, lum_min, lum_max) base_color = get_base_color(color, sat_min, sat_max, lum_min, lum_max)
if random_color: if random_color:
print("Selected random base color: {}".format(base_color.hex)) print(f"Selected random base color: {base_color.hex}")
c1, c2, c3, c4 = create_colors( c1, c2, c3, c4 = create_colors(
base_color, hue_max, sat_min, sat_max, lum_min, lum_max base_color, hue_max, sat_min, sat_max, lum_min, lum_max
@@ -68,7 +68,7 @@ def generate(
if emblem: if emblem:
image = add_emblem(image, emblem) image = add_emblem(image, emblem)
image.mode = "RGB" image = image.convert(mode="RGB")
if _output: if _output:
save_image(image, _output) save_image(image, _output)
@@ -77,5 +77,5 @@ def generate(
return image return image
except Exception as e: except Exception as e:
print(str(e)) print(e)
exit(1) exit(1)

View File

@@ -4,6 +4,7 @@ import random
import numpy as np import numpy as np
from colour import Color from colour import Color
from PIL import Image, ImageDraw, ImageOps from PIL import Image, ImageDraw, ImageOps
from typing import Tuple, Union
def get_base_color( def get_base_color(
@@ -23,9 +24,9 @@ def get_base_color(
base_color = Color(color_string) base_color = Color(color_string)
except: except:
try: try:
base_color = Color("#{}".format(color_string)) base_color = Color(f"#{color_string}")
except: except:
raise Exception("Invalid color expression: {}".format(color_string)) raise Exception(f"Invalid color expression: {color_string}")
return base_color return base_color
@@ -43,7 +44,7 @@ def create_colors(
max_lum_diff = 0.1 max_lum_diff = 0.1
# Create four random colors similar to the given base_color # Create four random colors similar to the given base_color
for i in range(0, 4): for _ in range(4):
tmp_hue = base_color.hue + random.uniform(-hue_max / 2.0, hue_max / 2.0) tmp_hue = base_color.hue + random.uniform(-hue_max / 2.0, hue_max / 2.0)
if tmp_hue > 1.0: if tmp_hue > 1.0:
tmp_hue -= 1 tmp_hue -= 1
@@ -60,7 +61,7 @@ def create_colors(
return tuple(colors) return tuple(colors)
def create_base_image(c1, c2, c3, c4, width=1920, height=1080): def create_base_image(c1, c2, c3, c4, width=1920, height=1080) -> Image:
"""Create a base huepaper by four corner colors. """Create a base huepaper by four corner colors.
c1 - top left c1 - top left
@@ -79,12 +80,11 @@ def create_base_image(c1, c2, c3, c4, width=1920, height=1080):
) )
im_arr = np.array([r, g, b]).T im_arr = np.array([r, g, b]).T
image = Image.fromarray(np.uint8(im_arr * 255)).convert("RGBA")
return Image.fromarray(np.uint8(im_arr * 255)).convert("RGBA")
return image
def add_lines(image, color): def add_lines(image: Image, color: Tuple[float, float, float, Union[float, None]]) -> Image:
"""Add one to three random lines to an image with given color.""" """Add one to three random lines to an image with given color."""
width, height = image.size width, height = image.size
@@ -103,7 +103,8 @@ def add_lines(image, color):
) )
space = rand_width() // 2 space = rand_width() // 2
offset = random.randint(0, space) offset = random.randint(0, space)
for i in range(0, number_of_lines):
for _ in range(number_of_lines):
line_width = rand_width() line_width = rand_width()
x = offset + space + (line_width // 2) x = offset + space + (line_width // 2)
draw.line((x, 0, x, height), fill=color, width=line_width) draw.line((x, 0, x, height), fill=color, width=line_width)
@@ -138,7 +139,7 @@ def add_emblem(image, filepath):
try: try:
emblem_image = Image.open(filepath) emblem_image = Image.open(filepath)
except Exception as e: except Exception as e:
raise Exception("Failed to load emblem: {}".format(e)) raise Exception(f"Failed to load emblem: {e}")
# Exit if emblem is too big # Exit if emblem is too big
if emblem_image.size[0] > width or emblem_image.size[1] > height: if emblem_image.size[0] > width or emblem_image.size[1] > height:
@@ -161,11 +162,10 @@ def save_image(image, filepath):
# Check whether file exists # Check whether file exists
if os.path.isfile(filepath): if os.path.isfile(filepath):
overwrite = input( overwrite = input(
"The file {} already exists. Do you want to overwrite it? [y/N] ".format( f"The file {filepath} already exists. Do you want to overwrite it? [y/N] "
filepath
)
) )
if overwrite != "y" and overwrite != "Y":
if overwrite not in ["y", "Y"]:
save = False save = False
if save: if save:
@@ -175,9 +175,10 @@ def save_image(image, filepath):
image.save(filepath) image.save(filepath)
stop = True stop = True
except Exception as e: except Exception as e:
print("Failed to save wallpaper: {}".format(e)) print(f"Failed to save wallpaper: {e}")
again = input("Do you want to try again? [Y/n] ") again = input("Do you want to try again? [Y/n] ")
if again == "n" or again == "N":
if again in ["n", "N"]:
stop = True stop = True
else: else:
filepath = input( filepath = input(