@@ -114,6 +114,9 @@ def changed(self, action):
114
114
elif action .type == "delete" and action .key [0 ].lower () == "files" :
115
115
# Don't clear the existing items if only deleting things
116
116
self .update_model (clear = False , delete_file_id = action .key [1 ].get ('id' , '' ))
117
+ elif action .type == "update" and action .key [0 ].lower () == "files" :
118
+ # Do nothing for file updates
119
+ pass
117
120
else :
118
121
# Clear existing items
119
122
self .update_model (clear = True )
@@ -122,6 +125,8 @@ def update_model(self, clear=True, delete_file_id=None):
122
125
log .info ("updating files model." )
123
126
app = get_app ()
124
127
128
+ self .ignore_updates = True
129
+
125
130
# Get window to check filters
126
131
win = app .window
127
132
_ = app ._tr
@@ -139,10 +144,6 @@ def update_model(self, clear=True, delete_file_id=None):
139
144
self .model_ids .pop (delete_file_id )
140
145
break
141
146
142
- # Skip updates (if needed)
143
- if self .ignore_update_signal :
144
- return
145
-
146
147
# Clear all items
147
148
if clear :
148
149
self .model_ids = {}
@@ -178,16 +179,8 @@ def update_model(self, clear=True, delete_file_id=None):
178
179
fps_float = float (fps ["num" ]) / float (fps ["den" ])
179
180
thumbnail_frame = round (float (file .data ['start' ]) * fps_float ) + 1
180
181
181
- # Determine thumb path (default value... a guess)
182
- thumb_path = os .path .join (info .THUMBNAIL_PATH , "%s-%s.png" % (file .id , thumbnail_frame ))
183
-
184
- # Connect to thumbnail server and get image
185
- thumb_server_details = get_app ().window .http_server_thread .server_address
186
- thumb_address = "http://%s:%s/thumbnails/%s/%s/path/" % (thumb_server_details [0 ], thumb_server_details [1 ], file .id , thumbnail_frame )
187
- r = get (thumb_address )
188
- if r .ok :
189
- # Update thumbnail path to real one
190
- thumb_path = r .text
182
+ # Get thumb path
183
+ thumb_path = self .get_thumb_path (file .id , thumbnail_frame )
191
184
else :
192
185
# Audio file
193
186
thumb_path = os .path .join (info .PATH , "images" , "AudioThumbnail.png" )
@@ -250,9 +243,56 @@ def update_model(self, clear=True, delete_file_id=None):
250
243
# Refresh view and filters (to hide or show this new item)
251
244
get_app ().window .resize_contents ()
252
245
246
+ self .ignore_updates = False
247
+
253
248
# Emit signal when model is updated
254
249
self .model .ModelRefreshed .emit ()
255
250
251
+ def get_thumb_path (self , file_id , thumbnail_frame , clear_cache = False ):
252
+ """Get thumbnail path by invoking HTTP thumbnail request"""
253
+
254
+ # Clear thumb cache (if requested)
255
+ thumb_cache = ""
256
+ if clear_cache :
257
+ thumb_cache = "no-cache/"
258
+
259
+ # Connect to thumbnail server and get image
260
+ thumb_server_details = get_app ().window .http_server_thread .server_address
261
+ thumb_address = "http://%s:%s/thumbnails/%s/%s/path/%s" % (
262
+ thumb_server_details [0 ], thumb_server_details [1 ], file_id , thumbnail_frame , thumb_cache )
263
+ r = get (thumb_address )
264
+ if r .ok :
265
+ # Update thumbnail path to real one
266
+ return r .text
267
+ else :
268
+ return ''
269
+
270
+ def update_file_thumbnail (self , file_id ):
271
+ """Update/re-generate the thumbnail of a specific file"""
272
+ file = File .get (id = file_id )
273
+ path , filename = os .path .split (file .data ["path" ])
274
+ name = filename
275
+ if "name" in file .data .keys ():
276
+ name = file .data ["name" ]
277
+
278
+ # Refresh thumbnail for updated file
279
+ self .ignore_updates = True
280
+ if file_id in self .model_ids :
281
+ for row_num in range (self .model .rowCount ()):
282
+ id_index = self .model .index (row_num , 5 )
283
+ if file_id == self .model .data (id_index ):
284
+ # Update thumb for file
285
+ thumb_index = self .model .index (row_num , 0 )
286
+ thumb_path = self .get_thumb_path (file_id , 1 , clear_cache = True )
287
+ item = self .model .itemFromIndex (thumb_index )
288
+ item .setIcon (QIcon (thumb_path ))
289
+ item .setText (name )
290
+
291
+ # Emit signal when model is updated
292
+ self .model .ModelRefreshed .emit ()
293
+ break
294
+ self .ignore_updates = False
295
+
256
296
def __init__ (self , * args ):
257
297
258
298
# Add self as listener to project data updates (undo/redo, as well as normal actions handled within this class all update the tree model)
@@ -263,7 +303,7 @@ def __init__(self, *args):
263
303
self .model = FileStandardItemModel ()
264
304
self .model .setColumnCount (6 )
265
305
self .model_ids = {}
266
- self .ignore_update_signal = False
306
+ self .ignore_updates = False
267
307
268
308
# Create proxy model (for sorting and filtering)
269
309
self .proxy_model = FileFilterProxyModel ()
@@ -272,3 +312,6 @@ def __init__(self, *args):
272
312
self .proxy_model .setSortCaseSensitivity (Qt .CaseSensitive )
273
313
self .proxy_model .setSourceModel (self .model )
274
314
self .proxy_model .setSortLocaleAware (True )
315
+
316
+ # Connect signal
317
+ app .window .FileUpdated .connect (self .update_file_thumbnail )
0 commit comments