Skip to content

Commit

Permalink
feat(ui): add thumbnail caching
Browse files Browse the repository at this point in the history
  • Loading branch information
CyanVoxel committed Jan 11, 2025
1 parent fce9785 commit f126036
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 98 deletions.
1 change: 1 addition & 0 deletions tagstudio/src/core/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
TS_FOLDER_NAME: str = ".TagStudio"
BACKUP_FOLDER_NAME: str = "backups"
COLLAGE_FOLDER_NAME: str = "collages"
THUMB_CACHE_NAME: str = "thumbs"

FONT_SAMPLE_TEXT: str = (
"""ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!?@$%(){}[]"""
Expand Down
2 changes: 1 addition & 1 deletion tagstudio/src/core/library/alchemy/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class Library:
def close(self):
if self.engine:
self.engine.dispose()
self.library_dir = None
self.library_dir: Path | None = None
self.storage_path = None
self.folder = None
self.included_files = set()
Expand Down
12 changes: 9 additions & 3 deletions tagstudio/src/qt/helpers/gradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


def four_corner_gradient(
image: Image.Image, size: tuple[int, int], mask: Image.Image
image: Image.Image, size: tuple[int, int], mask: Image.Image | None = None
) -> Image.Image:
if image.size != size:
# Four-Corner Gradient Background.
Expand All @@ -29,11 +29,17 @@ def four_corner_gradient(
)

final = Image.new("RGBA", bg.size, (0, 0, 0, 0))
final.paste(bg, mask=mask.getchannel(0))
if mask:
final.paste(bg, mask=mask.getchannel(0))
else:
final = bg

else:
final = Image.new("RGBA", size, (0, 0, 0, 0))
final.paste(image, mask=mask.getchannel(0))
if mask:
final.paste(image, mask=mask.getchannel(0))
else:
final = image

if final.mode != "RGBA":
final = final.convert("RGBA")
Expand Down
2 changes: 1 addition & 1 deletion tagstudio/src/qt/widgets/item_thumb.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def __init__(
self.thumb_layout.addWidget(self.bottom_container)

self.thumb_button = ThumbButton(self.thumb_container, thumb_size)
self.renderer = ThumbRenderer()
self.renderer = ThumbRenderer(self.lib)
self.renderer.updated.connect(
lambda timestamp, image, size, filename, ext: (
self.update_thumb(timestamp, image=image),
Expand Down
2 changes: 1 addition & 1 deletion tagstudio/src/qt/widgets/preview/preview_thumb.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def __init__(self, library: Library, driver: "QtDriver"):

self.preview_vid = VideoPlayer(driver)
self.preview_vid.hide()
self.thumb_renderer = ThumbRenderer()
self.thumb_renderer = ThumbRenderer(self.lib)
self.thumb_renderer.updated.connect(lambda ts, i, s: (self.preview_img.setIcon(i)))
self.thumb_renderer.updated_ratio.connect(
lambda ratio: (
Expand Down
Loading

0 comments on commit f126036

Please sign in to comment.