10
10
import structlog
11
11
from PIL import Image , UnidentifiedImageError
12
12
from PySide6 .QtCore import QBuffer , QByteArray , QSize , Qt
13
- from PySide6 .QtGui import QAction , QMovie , QResizeEvent
14
- from PySide6 .QtWidgets import QHBoxLayout , QLabel , QStackedLayout , QWidget
13
+ from PySide6 .QtGui import QAction , QMovie , QPixmap , QResizeEvent
14
+ from PySide6 .QtWidgets import QHBoxLayout , QLabel , QPushButton , QStackedLayout , QWidget
15
15
16
16
from tagstudio .core .library .alchemy .library import Library
17
17
from tagstudio .core .media_types import MediaType
18
- from tagstudio .qt .helpers .qbutton_wrapper import QPushButtonWrapper
19
18
from tagstudio .qt .helpers .rounded_pixmap_style import RoundedPixmapStyle
20
19
from tagstudio .qt .platform_strings import open_file_str , trash_term
21
20
from tagstudio .qt .translations import Translations
@@ -56,7 +55,7 @@ def __init__(self, library: Library, driver: "QtDriver") -> None:
56
55
)
57
56
self .__delete_action .triggered .connect (self ._delete_action_callback )
58
57
59
- self .__button_wrapper = QPushButtonWrapper ()
58
+ self .__button_wrapper = QPushButton ()
60
59
self .__button_wrapper .setMinimumSize (* self .__img_button_size )
61
60
self .__button_wrapper .setFlat (True )
62
61
self .__button_wrapper .setContextMenuPolicy (Qt .ContextMenuPolicy .ActionsContextMenu )
@@ -88,32 +87,18 @@ def __init__(self, library: Library, driver: "QtDriver") -> None:
88
87
self .__media_player .addAction (self .__delete_action )
89
88
90
89
# Need to watch for this to resize the player appropriately.
91
- self .__media_player .player .hasVideoChanged .connect (self .__has_video_changed )
90
+ self .__media_player .player .hasVideoChanged .connect (
91
+ self .__media_player_video_changed_callback
92
+ )
92
93
93
94
self .__mp_max_size = QSize (* self .__img_button_size )
94
95
95
96
self .__media_player_page = QWidget ()
96
97
self .__stacked_page_setup (self .__media_player_page , self .__media_player )
97
98
98
99
self .__thumb_renderer = ThumbRenderer (self .lib )
99
- self .__thumb_renderer .updated .connect (
100
- lambda ts , i , s : (
101
- self .__button_wrapper .setIcon (i ),
102
- self .__set_mp_max_size (i .size ()),
103
- )
104
- )
105
- self .__thumb_renderer .updated_ratio .connect (
106
- lambda ratio : (
107
- self .__set_image_ratio (ratio ),
108
- self .__update_image_size (
109
- (
110
- self .size ().width (),
111
- self .size ().height (),
112
- ),
113
- ratio ,
114
- ),
115
- )
116
- )
100
+ self .__thumb_renderer .updated .connect (self .__thumb_renderer_updated_callback )
101
+ self .__thumb_renderer .updated_ratio .connect (self .__thumb_renderer_updated_ratio_callback )
117
102
118
103
self .__image_layout .addWidget (self .preview_img_page )
119
104
self .__image_layout .addWidget (self .__preview_gif_page )
@@ -135,26 +120,32 @@ def _delete_action_callback(self):
135
120
def _button_wrapper_callback (self ):
136
121
raise NotImplementedError
137
122
138
- def __set_mp_max_size (self , size : QSize ) -> None :
139
- self .__mp_max_size = size
140
-
141
- def __has_video_changed (self , video : bool ) -> None :
123
+ def __media_player_video_changed_callback (self , video : bool ) -> None :
142
124
self .__update_image_size ((self .size ().width (), self .size ().height ()))
143
125
126
+ def __thumb_renderer_updated_callback (
127
+ self , _timestamp : float , img : QPixmap , _size : QSize , _path : Path
128
+ ) -> None :
129
+ self .__button_wrapper .setIcon (img )
130
+ self .__mp_max_size = img .size ()
131
+
132
+ def __thumb_renderer_updated_ratio_callback (self , ratio : float ) -> None :
133
+ self .__image_ratio = ratio
134
+ self .__update_image_size (
135
+ (
136
+ self .size ().width (),
137
+ self .size ().height (),
138
+ )
139
+ )
140
+
144
141
def __stacked_page_setup (self , page : QWidget , widget : QWidget ) -> None :
145
142
layout = QHBoxLayout (page )
146
143
layout .addWidget (widget )
147
144
layout .setAlignment (widget , Qt .AlignmentFlag .AlignCenter )
148
145
layout .setContentsMargins (0 , 0 , 0 , 0 )
149
146
page .setLayout (layout )
150
147
151
- def __set_image_ratio (self , ratio : float ) -> None :
152
- self .__image_ratio = ratio
153
-
154
- def __update_image_size (self , size : tuple [int , int ], ratio : float | None = None ) -> None :
155
- if ratio :
156
- self .__set_image_ratio (ratio )
157
-
148
+ def __update_image_size (self , size : tuple [int , int ]) -> None :
158
149
adj_width : float = size [0 ]
159
150
adj_height : float = size [1 ]
160
151
# Landscape
@@ -253,9 +244,7 @@ def _display_video(self, filepath: Path) -> dict[str, int]:
253
244
try :
254
245
success , size = self .__get_video_res (str (filepath ))
255
246
if success :
256
- self .__update_image_size (
257
- (size .width (), size .height ()), size .width () / size .height ()
258
- )
247
+ self .__image_ratio = size .width () / size .height ()
259
248
self .resizeEvent (
260
249
QResizeEvent (
261
250
QSize (size .width (), size .height ()),
@@ -296,7 +285,7 @@ def _display_animated_image(self, filepath: Path) -> dict[str, int] | None:
296
285
stats ["width" ] = image .width
297
286
stats ["height" ] = image .height
298
287
299
- self .__update_image_size (( image . width , image . height ), image .width / image .height )
288
+ self .__image_ratio = image .width / image .height
300
289
if ext == ".apng" :
301
290
image_bytes_io = io .BytesIO ()
302
291
image .save (
0 commit comments