Skip to content

Commit 08761d5

Browse files
authored
Add Landing Page When No Library Is Opened (#258)
* Add landing page when no library is open - Add landing page when no library is open - Add linear_gradient method - Reformat main_window.py with spaces instead of tabs because apparently it wasn't formatted already? * Add color_overlay methods, ClickableLabel widget - Add color_overlay helper methods - Add clickable_label widget - Add docstrings to landing.py methods - Add logo easter egg - Refactor landing.py content * Fix redefinition * Fix macOS shortcut text
1 parent 6a680ad commit 08761d5

File tree

7 files changed

+506
-262
lines changed

7 files changed

+506
-262
lines changed
42.3 KB
Loading
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Copyright (C) 2024 Travis Abendshien (CyanVoxel).
2+
# Licensed under the GPL-3.0 License.
3+
# Created for TagStudio: https://github.com/CyanVoxel/TagStudio
4+
5+
6+
from PIL import Image
7+
from PySide6.QtCore import Qt
8+
from PySide6.QtGui import QGuiApplication
9+
from src.qt.helpers.gradient import linear_gradient
10+
11+
# TODO: Consolidate the built-in QT theme values with the values
12+
# here, in enums.py, and in palette.py.
13+
_THEME_DARK_FG: str = "#FFFFFF55"
14+
_THEME_LIGHT_FG: str = "#000000DD"
15+
16+
17+
def theme_fg_overlay(image: Image.Image) -> Image.Image:
18+
"""
19+
Overlay the foreground theme color onto an image.
20+
21+
Args:
22+
image (Image): The PIL Image object to apply an overlay to.
23+
"""
24+
25+
overlay_color = (
26+
_THEME_DARK_FG
27+
if QGuiApplication.styleHints().colorScheme() is Qt.ColorScheme.Dark
28+
else _THEME_LIGHT_FG
29+
)
30+
im = Image.new(mode="RGBA", size=image.size, color=overlay_color)
31+
return _apply_overlay(image, im)
32+
33+
34+
def gradient_overlay(image: Image.Image, gradient=list[str]) -> Image.Image:
35+
"""
36+
Overlay a color gradient onto an image.
37+
38+
Args:
39+
image (Image): The PIL Image object to apply an overlay to.
40+
gradient (list[str): A list of string hex color codes for use as
41+
the colors of the gradient.
42+
"""
43+
44+
im: Image.Image = _apply_overlay(image, linear_gradient(image.size, gradient))
45+
return im
46+
47+
48+
def _apply_overlay(image: Image.Image, overlay: Image.Image) -> Image.Image:
49+
"""
50+
Internal method to apply an overlay on top of an image, using
51+
the image's alpha channel as a mask.
52+
53+
Args:
54+
image (Image): The PIL Image object to apply an overlay to.
55+
overlay (Image): The PIL Image object to act as the overlay contents.
56+
"""
57+
im: Image.Image = Image.new(mode="RGBA", size=image.size, color="#00000000")
58+
im.paste(overlay, (0, 0), mask=image)
59+
return im

tagstudio/src/qt/helpers/gradient.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
from PIL import Image, ImageEnhance, ImageChops
66

77

8-
def four_corner_gradient_background(image: Image.Image, adj_size, mask, hl):
8+
def four_corner_gradient_background(
9+
image: Image.Image, adj_size, mask, hl
10+
) -> Image.Image:
911
if image.size != (adj_size, adj_size):
1012
# Old 1 color method.
1113
# bg_col = image.copy().resize((1, 1)).getpixel((0,0))
@@ -48,3 +50,16 @@ def four_corner_gradient_background(image: Image.Image, adj_size, mask, hl):
4850
hl_soft.putalpha(ImageEnhance.Brightness(hl.getchannel(3)).enhance(0.5))
4951
final.paste(ImageChops.soft_light(final, hl_soft), mask=hl_soft.getchannel(3))
5052
return final
53+
54+
55+
def linear_gradient(
56+
size=tuple[int, int],
57+
colors=list[str],
58+
interpolation: Image.Resampling = Image.Resampling.BICUBIC,
59+
) -> Image.Image:
60+
seed: Image.Image = Image.new(mode="RGBA", size=(len(colors), 1), color="#000000")
61+
for i, color in enumerate(colors):
62+
c_im: Image.Image = Image.new(mode="RGBA", size=(1, 1), color=color)
63+
seed.paste(c_im, (i, 0))
64+
gradient: Image.Image = seed.resize(size, resample=interpolation)
65+
return gradient

0 commit comments

Comments
 (0)