4848
4949
5050class _PreviewType (Enum ):
51- """Enum for which of the Inspector's stacked pages should be shown for a file."""
51+ """Enum for which of the Inspector's stacked pages should be displayed for a file."""
5252
5353 ANIMATED = auto ()
5454 AUDIO = auto ()
@@ -159,10 +159,9 @@ def _video_probed_callback(
159159 self ._image_ratio = stats .width / stats .height
160160 self ._update_image_size ((self .size ().width (), self .size ().height ()))
161161 self .stats_updated .emit (filepath , stats )
162- elif preview == _PreviewType .AUDIO and stats is not None :
162+ elif preview == _PreviewType .AUDIO :
163163 # Display the album art/waveform and duration
164- self ._show_audio_art (filepath , is_new_file = True )
165- self .stats_updated .emit (filepath , stats )
164+ self ._display_audio (filepath , is_new_file = True , start_player = False )
166165 else :
167166 self ._display_image (filepath , is_new_file = True )
168167
@@ -172,7 +171,7 @@ def _animation_loaded_callback(
172171 if filepath != self ._current_file :
173172 return
174173
175- if not (data and self ._display_animation (* data )):
174+ if not (data and self ._play_animation (* data )):
176175 self ._display_image (filepath , is_new_file = False )
177176
178177 def _file_renderer_updated_callback (
@@ -307,7 +306,7 @@ def _render_preview(self, filepath: Path) -> None:
307306 )
308307
309308 def _render_placeholder (self , filepath : Path ) -> None :
310- """Show the file's cached thumbnail, or a loading graphic if it has none.
309+ """Display the file's cached thumbnail, or a loading graphic if it has none.
311310
312311 If a file is already known to not be renderable, it'll display the default icon for it
313312 right away instead of a loading graphic.
@@ -336,32 +335,28 @@ def _display_video(self, filepath: Path) -> None:
336335 self ._render_pool .start (lambda : self ._probe_video (filepath ))
337336
338337 def _probe_video (self , filepath : Path ) -> None :
339- """Send whether a video should show as a video, as audio, or as an image, with its stats ."""
338+ """Send whether a video should display as a video, as audio, or as an image."""
340339 if is_readable_video (filepath ):
341340 self ._video_probed .emit (filepath , _PreviewType .VIDEO , self ._get_video_stats (filepath ))
342341 elif has_audio_stream (filepath ):
343- self ._video_probed .emit (
344- filepath , _PreviewType .AUDIO , self ._get_duration_stats (filepath )
345- )
342+ self ._video_probed .emit (filepath , _PreviewType .AUDIO , None )
346343 else :
347344 self ._video_probed .emit (filepath , None , None )
348345
349- def _display_audio (self , filepath : Path , is_new_file : bool ) -> None :
346+ def _display_audio (self , filepath : Path , is_new_file : bool , start_player : bool = True ) -> None :
347+ """Display an audio file's art and duration, and play it unless `start_player` is False."""
350348 self ._render_pool .start (
351349 lambda : self .stats_updated .emit (filepath , self ._get_duration_stats (filepath ))
352350 )
353- self ._show_audio_art (filepath , is_new_file )
354- self ._update_media_player (filepath )
355-
356- def _show_audio_art (self , filepath : Path , is_new_file : bool ) -> None :
357- """Show an audio file's album art or waveform in the media player."""
358351 self ._switch_preview (_PreviewType .AUDIO )
359352 if is_new_file :
360353 self ._render_placeholder (filepath )
361354 self ._render_preview (filepath )
355+ if start_player :
356+ self ._update_media_player (filepath )
362357
363- def _display_animation (self , data : bytes , size : tuple [int , int ]) -> bool :
364- """Show an animated image, returning `False` if it's not actually animated."""
358+ def _play_animation (self , data : bytes , size : tuple [int , int ]) -> bool :
359+ """Play an animated image, returning `False` if it's not actually animated."""
365360 self ._should_render_on_resize = False
366361
367362 view = self .layout ()
@@ -388,8 +383,8 @@ def _display_animation(self, data: bytes, size: tuple[int, int]) -> bool:
388383 movie .start ()
389384 return True
390385
391- def _display_animated (self , filepath : Path , is_new_file : bool ) -> None :
392- """Show a placeholder image while its animation loads, falling back to a still image mode .
386+ def _display_animated_image (self , filepath : Path , is_new_file : bool ) -> None :
387+ """Display a placeholder while the animation loads, falling back to a still image.
393388
394389 The placeholder will be the cached first frame if it exists, or else a loading icon.
395390 """
@@ -400,7 +395,7 @@ def _display_animated(self, filepath: Path, is_new_file: bool) -> None:
400395 self ._render_pool .start (lambda : self ._load_animation (filepath ))
401396
402397 def _load_animation (self , filepath : Path ) -> None :
403- """Send an animated image to be shown , then its stats once its duration is known."""
398+ """Send an animated image to be played , then its stats once its duration is known."""
404399 animation_data = self ._get_animation_data (filepath )
405400 self ._animation_loaded .emit (filepath , animation_data )
406401 if animation_data is not None :
@@ -558,7 +553,7 @@ def display_file(self, filepath: Path, date_modified: float | None = None) -> No
558553 self ._display_audio (filepath , is_new_file )
559554 # Animated Images
560555 elif MediaTypes .contains ("image.animated" , ext , SEARCH ):
561- self ._display_animated (filepath , is_new_file )
556+ self ._display_animated_image (filepath , is_new_file )
562557 # Other Types (Including Images)
563558 else :
564559 self ._display_image (filepath , is_new_file )
0 commit comments