mirror of
https://github.com/TagStudioDev/TagStudio.git
synced 2026-02-01 07:39:10 +00:00
fix: pyright errors in blender_renderer.py (#1236)
This commit is contained in:
@@ -790,25 +790,17 @@ class ThumbRenderer(QObject):
|
||||
)
|
||||
im: Image.Image | None = None
|
||||
try:
|
||||
blend_image = blend_thumb(str(filepath))
|
||||
|
||||
bg = Image.new("RGB", blend_image.size, color=bg_color)
|
||||
bg.paste(blend_image, mask=blend_image.getchannel(3))
|
||||
im = bg
|
||||
|
||||
except (
|
||||
AttributeError,
|
||||
UnidentifiedImageError,
|
||||
TypeError,
|
||||
) as e:
|
||||
if str(e) == "expected string or buffer":
|
||||
if (blend_image := blend_thumb(str(filepath))) is not None:
|
||||
bg = Image.new("RGB", blend_image.size, color=bg_color)
|
||||
bg.paste(blend_image, mask=blend_image.getchannel(3))
|
||||
im = bg
|
||||
else:
|
||||
logger.info(
|
||||
f"[ThumbRenderer][BLENDER][INFO] {filepath.name} "
|
||||
f"Doesn't have an embedded thumbnail. ({type(e).__name__})"
|
||||
"Doesn't have an embedded thumbnail."
|
||||
)
|
||||
|
||||
else:
|
||||
logger.error("Couldn't render thumbnail", filepath=filepath, error=type(e).__name__)
|
||||
except Exception as e:
|
||||
logger.error("Couldn't render thumbnail", filepath=filepath, error=type(e).__name__)
|
||||
return im
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -32,7 +32,7 @@ from io import BufferedReader
|
||||
from PIL import Image, ImageOps
|
||||
|
||||
|
||||
def blend_extract_thumb(path):
|
||||
def blend_extract_thumb(path) -> tuple[bytes | None, int, int]:
|
||||
rend = b"REND"
|
||||
test = b"TEST"
|
||||
|
||||
@@ -97,8 +97,10 @@ def blend_extract_thumb(path):
|
||||
return image_buffer, x, y
|
||||
|
||||
|
||||
def blend_thumb(file_in):
|
||||
def blend_thumb(file_in) -> Image.Image | None:
|
||||
buf, width, height = blend_extract_thumb(file_in)
|
||||
if buf is None:
|
||||
return None
|
||||
image = Image.frombuffer(
|
||||
"RGBA",
|
||||
(width, height),
|
||||
|
||||
@@ -383,7 +383,7 @@ class ThumbGridLayout(QLayout):
|
||||
@override
|
||||
def itemAt(self, index: int) -> QLayoutItem:
|
||||
if index >= len(self._items):
|
||||
return None
|
||||
return None # pyright: ignore[reportReturnType]
|
||||
return self._items[index]
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user