mirror of
https://github.com/TagStudioDev/TagStudio.git
synced 2026-01-31 23:29:10 +00:00
feat(ui): show stems for extension-less files (#899)
* feat(ui): show stems for extension-less files * chore: remove unnecessary call and comment * fix: only access filepath if not none
This commit is contained in:
committed by
GitHub
parent
702ecd4118
commit
ee56f3e2bc
@@ -205,11 +205,11 @@ class ItemThumb(FlowWidget):
|
||||
self.thumb_button = ThumbButton(self.thumb_container, thumb_size)
|
||||
self.renderer = ThumbRenderer(self.lib)
|
||||
self.renderer.updated.connect(
|
||||
lambda timestamp, image, size, filename, ext: (
|
||||
lambda timestamp, image, size, filename: (
|
||||
self.update_thumb(timestamp, image=image),
|
||||
self.update_size(timestamp, size=size),
|
||||
self.set_filename_text(filename),
|
||||
self.set_extension(ext), # type: ignore
|
||||
self.set_extension(filename),
|
||||
)
|
||||
)
|
||||
self.thumb_button.setFlat(True)
|
||||
@@ -365,13 +365,13 @@ class ItemThumb(FlowWidget):
|
||||
self.item_type_badge.setHidden(False)
|
||||
self.mode = mode
|
||||
|
||||
def set_extension(self, ext: str) -> None:
|
||||
def set_extension(self, filename: Path) -> None:
|
||||
ext = filename.suffix
|
||||
if ext and ext.startswith(".") is False:
|
||||
ext = "." + ext
|
||||
media_types: set[MediaType] = MediaCategories.get_types(ext)
|
||||
if (
|
||||
ext
|
||||
and not MediaCategories.is_ext_in_category(ext, MediaCategories.IMAGE_TYPES)
|
||||
not MediaCategories.is_ext_in_category(ext, MediaCategories.IMAGE_TYPES)
|
||||
or MediaCategories.is_ext_in_category(ext, MediaCategories.IMAGE_RAW_TYPES)
|
||||
or MediaCategories.is_ext_in_category(ext, MediaCategories.IMAGE_VECTOR_TYPES)
|
||||
or MediaCategories.is_ext_in_category(ext, MediaCategories.ADOBE_PHOTOSHOP_TYPES)
|
||||
@@ -386,7 +386,7 @@ class ItemThumb(FlowWidget):
|
||||
]
|
||||
):
|
||||
self.ext_badge.setHidden(False)
|
||||
self.ext_badge.setText(ext.upper()[1:])
|
||||
self.ext_badge.setText(ext.upper()[1:] or filename.stem.upper())
|
||||
if MediaType.VIDEO in media_types or MediaType.AUDIO in media_types:
|
||||
self.count_badge.setHidden(False)
|
||||
else:
|
||||
|
||||
@@ -131,7 +131,7 @@ class FileAttributes(QWidget):
|
||||
self.date_created_label.setHidden(True)
|
||||
self.date_modified_label.setHidden(True)
|
||||
|
||||
def update_stats(self, filepath: Path | None = None, ext: str = ".", stats: dict | None = None):
|
||||
def update_stats(self, filepath: Path | None = None, stats: dict | None = None):
|
||||
"""Render the panel widgets with the newest data from the Library."""
|
||||
if not stats:
|
||||
stats = {}
|
||||
@@ -145,6 +145,7 @@ class FileAttributes(QWidget):
|
||||
self.dimensions_label.setText("")
|
||||
self.dimensions_label.setHidden(True)
|
||||
else:
|
||||
ext = filepath.suffix.lower()
|
||||
self.library_path = self.library.library_dir
|
||||
display_path = filepath
|
||||
if self.driver.settings.show_filepath == ShowFilepathOption.SHOW_FULL_PATHS:
|
||||
@@ -188,8 +189,7 @@ class FileAttributes(QWidget):
|
||||
height_px_text = stats.get("height", "")
|
||||
duration_text = stats.get("duration", "")
|
||||
font_family = stats.get("font_family", "")
|
||||
if ext:
|
||||
ext_display = ext.upper()[1:]
|
||||
ext_display = ext.upper()[1:] or filepath.stem.upper()
|
||||
if filepath:
|
||||
try:
|
||||
file_size = format_size(filepath.stat().st_size)
|
||||
|
||||
@@ -242,11 +242,12 @@ class PreviewThumb(QWidget):
|
||||
self.devicePixelRatio(),
|
||||
update_on_ratio_change=True,
|
||||
)
|
||||
return self._update_image(filepath, ext)
|
||||
return self._update_image(filepath)
|
||||
|
||||
def _update_image(self, filepath: Path, ext: str) -> dict[str, int]:
|
||||
def _update_image(self, filepath: Path) -> dict[str, int]:
|
||||
"""Update the static image preview from a filepath."""
|
||||
stats: dict[str, int] = {}
|
||||
ext = filepath.suffix.lower()
|
||||
self.switch_preview("image")
|
||||
|
||||
image: Image.Image | None = None
|
||||
@@ -380,8 +381,9 @@ class PreviewThumb(QWidget):
|
||||
stats["duration"] = self.media_player.player.duration() * 1000
|
||||
return stats
|
||||
|
||||
def update_preview(self, filepath: Path, ext: str) -> dict[str, int]:
|
||||
def update_preview(self, filepath: Path) -> dict[str, int]:
|
||||
"""Render a single file preview."""
|
||||
ext = filepath.suffix.lower()
|
||||
stats: dict[str, int] = {}
|
||||
|
||||
# Video
|
||||
@@ -394,7 +396,7 @@ class PreviewThumb(QWidget):
|
||||
elif MediaCategories.is_ext_in_category(
|
||||
ext, MediaCategories.AUDIO_TYPES, mime_fallback=True
|
||||
):
|
||||
self._update_image(filepath, ext)
|
||||
self._update_image(filepath)
|
||||
stats = self._update_media(filepath, MediaType.AUDIO)
|
||||
self.thumb_renderer.render(
|
||||
time.time(),
|
||||
@@ -413,7 +415,7 @@ class PreviewThumb(QWidget):
|
||||
# Other Types (Including Images)
|
||||
else:
|
||||
# TODO: Get thumb renderer to return this stuff to pass on
|
||||
stats = self._update_image(filepath, ext)
|
||||
stats = self._update_image(filepath)
|
||||
|
||||
self.thumb_renderer.render(
|
||||
time.time(),
|
||||
|
||||
@@ -145,11 +145,10 @@ class PreviewPanel(QWidget):
|
||||
entry: Entry = self.lib.get_entry(self.driver.selected[0])
|
||||
entry_id = self.driver.selected[0]
|
||||
filepath: Path = self.lib.library_dir / entry.path
|
||||
ext: str = filepath.suffix.lower()
|
||||
|
||||
if update_preview:
|
||||
stats: dict = self.thumb.update_preview(filepath, ext)
|
||||
self.file_attrs.update_stats(filepath, ext, stats)
|
||||
stats: dict = self.thumb.update_preview(filepath)
|
||||
self.file_attrs.update_stats(filepath, stats)
|
||||
self.file_attrs.update_date_label(filepath)
|
||||
self.fields.update_from_entry(entry_id)
|
||||
self.update_add_tag_button(entry_id)
|
||||
|
||||
@@ -89,7 +89,7 @@ class ThumbRenderer(QObject):
|
||||
|
||||
rm: ResourceManager = ResourceManager()
|
||||
cache: CacheManager = CacheManager()
|
||||
updated = Signal(float, QPixmap, QSize, Path, str)
|
||||
updated = Signal(float, QPixmap, QSize, Path)
|
||||
updated_ratio = Signal(float)
|
||||
|
||||
cached_img_res: int = 256 # TODO: Pull this from config
|
||||
@@ -1300,7 +1300,6 @@ class ThumbRenderer(QObject):
|
||||
math.ceil(image.size[1] / pixel_ratio),
|
||||
),
|
||||
filepath,
|
||||
filepath.suffix.lower(),
|
||||
)
|
||||
else:
|
||||
self.updated.emit(
|
||||
@@ -1308,7 +1307,6 @@ class ThumbRenderer(QObject):
|
||||
QPixmap(),
|
||||
QSize(*base_size),
|
||||
filepath,
|
||||
filepath.suffix.lower(),
|
||||
)
|
||||
|
||||
def _render(
|
||||
|
||||
Reference in New Issue
Block a user