44
55import io
66import time
7- import typing
87from pathlib import Path
8+ from typing import TYPE_CHECKING , override
99from warnings import catch_warnings
1010
1111import cv2
2424from tagstudio .qt .helpers .qbutton_wrapper import QPushButtonWrapper
2525from tagstudio .qt .helpers .rounded_pixmap_style import RoundedPixmapStyle
2626from tagstudio .qt .platform_strings import open_file_str , trash_term
27- from tagstudio .qt .resource_manager import ResourceManager
2827from tagstudio .qt .translations import Translations
2928from tagstudio .qt .widgets .media_player import MediaPlayer
3029from tagstudio .qt .widgets .thumb_renderer import ThumbRenderer
3130
32- if typing . TYPE_CHECKING :
31+ if TYPE_CHECKING :
3332 from tagstudio .qt .ts_qt import QtDriver
3433
3534logger = structlog .get_logger (__name__ )
3938class PreviewThumb (QWidget ):
4039 """The Preview Panel Widget."""
4140
42- def __init__ (self , library : Library , driver : "QtDriver" ):
41+ def __init__ (self , library : Library , driver : "QtDriver" ) -> None :
4342 super ().__init__ ()
4443
4544 self .is_connected = False
@@ -54,6 +53,7 @@ def __init__(self, library: Library, driver: "QtDriver"):
5453 self .image_layout .setStackingMode (QStackedLayout .StackingMode .StackAll )
5554 self .image_layout .setContentsMargins (0 , 0 , 0 , 0 )
5655
56+ self .opener : FileOpenerHelper | None = None
5757 self .open_file_action = QAction (Translations ["file.open_file" ], self )
5858 self .open_explorer_action = QAction (open_file_str (), self )
5959 self .delete_action = QAction (
@@ -133,17 +133,17 @@ def _set_mp_max_size(self, size: QSize) -> None:
133133 def _has_video_changed (self , video : bool ) -> None :
134134 self .update_image_size ((self .size ().width (), self .size ().height ()))
135135
136- def _stacked_page_setup (self , page : QWidget , widget : QWidget ):
136+ def _stacked_page_setup (self , page : QWidget , widget : QWidget ) -> None :
137137 layout = QHBoxLayout (page )
138138 layout .addWidget (widget )
139139 layout .setAlignment (widget , Qt .AlignmentFlag .AlignCenter )
140140 layout .setContentsMargins (0 , 0 , 0 , 0 )
141141 page .setLayout (layout )
142142
143- def set_image_ratio (self , ratio : float ):
143+ def set_image_ratio (self , ratio : float ) -> None :
144144 self .image_ratio = ratio
145145
146- def update_image_size (self , size : tuple [int , int ], ratio : float | None = None ):
146+ def update_image_size (self , size : tuple [int , int ], ratio : float | None = None ) -> None :
147147 if ratio :
148148 self .set_image_ratio (ratio )
149149
@@ -204,7 +204,7 @@ def get_preview_size(self) -> tuple[int, int]:
204204 self .size ().height (),
205205 )
206206
207- def switch_preview (self , preview : str ):
207+ def switch_preview (self , preview : str ) -> None :
208208 if preview in ["audio" , "video" ]:
209209 self .media_player .show ()
210210 self .image_layout .setCurrentWidget (self .media_player_page )
@@ -229,7 +229,7 @@ def switch_preview(self, preview: str):
229229 self .gif_buffer .close ()
230230 self .preview_gif .hide ()
231231
232- def _display_fallback_image (self , filepath : Path , ext : str ) -> dict :
232+ def _display_fallback_image (self , filepath : Path , ext : str ) -> dict [ str , int ] :
233233 """Renders the given file as an image, no matter its media type.
234234
235235 Useful for fallback scenarios.
@@ -244,9 +244,9 @@ def _display_fallback_image(self, filepath: Path, ext: str) -> dict:
244244 )
245245 return self ._update_image (filepath , ext )
246246
247- def _update_image (self , filepath : Path , ext : str ) -> dict :
247+ def _update_image (self , filepath : Path , ext : str ) -> dict [ str , int ] :
248248 """Update the static image preview from a filepath."""
249- stats : dict = {}
249+ stats : dict [ str , int ] = {}
250250 self .switch_preview ("image" )
251251
252252 image : Image .Image | None = None
@@ -287,9 +287,9 @@ def _update_image(self, filepath: Path, ext: str) -> dict:
287287
288288 return stats
289289
290- def _update_animation (self , filepath : Path , ext : str ) -> dict :
290+ def _update_animation (self , filepath : Path , ext : str ) -> dict [ str , int ] :
291291 """Update the animated image preview from a filepath."""
292- stats : dict = {}
292+ stats : dict [ str , int ] = {}
293293
294294 # Ensure that any movie and buffer from previous animations are cleared.
295295 if self .preview_gif .movie ():
@@ -351,8 +351,8 @@ def _get_video_res(self, filepath: str) -> tuple[bool, QSize]:
351351 image = Image .fromarray (frame )
352352 return (success , QSize (image .width , image .height ))
353353
354- def _update_media (self , filepath : Path , type : MediaType ) -> dict :
355- stats : dict = {}
354+ def _update_media (self , filepath : Path , type : MediaType ) -> dict [ str , int ] :
355+ stats : dict [ str , int ] = {}
356356
357357 self .media_player .play (filepath )
358358
@@ -380,9 +380,9 @@ def _update_media(self, filepath: Path, type: MediaType) -> dict:
380380 stats ["duration" ] = self .media_player .player .duration () * 1000
381381 return stats
382382
383- def update_preview (self , filepath : Path , ext : str ) -> dict :
383+ def update_preview (self , filepath : Path , ext : str ) -> dict [ str , int ] :
384384 """Render a single file preview."""
385- stats : dict = {}
385+ stats : dict [ str , int ] = {}
386386
387387 # Video
388388 if MediaCategories .is_ext_in_category (
@@ -448,17 +448,11 @@ def update_preview(self, filepath: Path, ext: str) -> dict:
448448
449449 return stats
450450
451- def hide_preview (self ):
451+ def hide_preview (self ) -> None :
452452 """Completely hide the file preview."""
453453 self .switch_preview ("" )
454454
455- def stop_file_use (self ):
456- """Stops the use of the currently previewed file. Used to release file permissions."""
457- logger .info ("[PreviewThumb] Stopping file use in video playback..." )
458- # This swaps the video out for a placeholder so the previous video's file
459- # is no longer in use by this object.
460- self .media_player .play (ResourceManager .get_path ("placeholder_mp4" ))
461-
462- def resizeEvent (self , event : QResizeEvent ) -> None : # noqa: N802
455+ @override
456+ def resizeEvent (self , event : QResizeEvent ) -> None :
463457 self .update_image_size ((self .size ().width (), self .size ().height ()))
464458 return super ().resizeEvent (event )
0 commit comments