28
28
import os
29
29
import sys
30
30
import time
31
+ import json
31
32
import operator
32
33
import functools
33
34
@@ -190,6 +191,11 @@ def __init__(self, clip_id, effect_name, effect_params):
190
191
191
192
row_count += 1
192
193
194
+ # Add error field
195
+ self .error_label = QLabel ("" , self )
196
+ self .error_label .setStyleSheet ("color: red;" )
197
+ self .scrollAreaWidgetContents .layout ().insertRow (row_count , self .error_label )
198
+
193
199
# Add buttons
194
200
self .cancel_button = QPushButton (_ ('Cancel' ))
195
201
self .process_button = QPushButton (_ ('Process Effect' ))
@@ -288,8 +294,8 @@ def rect_select_clicked(self, widget, param):
288
294
def accept (self ):
289
295
""" Start processing effect """
290
296
# Disable UI
291
- for child_widget in self .scrollAreaWidgetContents .children ():
292
- child_widget .setEnabled (False )
297
+ # for child_widget in self.scrollAreaWidgetContents.children():
298
+ # child_widget.setEnabled(False)
293
299
294
300
# Enable ProgressBar
295
301
self .progressBar .setEnabled (True )
@@ -304,13 +310,29 @@ def accept(self):
304
310
protobufPath = os .path .join (info .PROTOBUF_DATA_PATH , ID + '.data' )
305
311
if os .name == 'nt' : protobufPath = protobufPath .replace ("\\ " , "/" )
306
312
307
- # Load into JSON string info abou protobuf data path
308
- jsonString = self .generateJson (protobufPath )
313
+ self .context ["protobuf_data_path" ] = protobufPath
314
+
315
+ # Load into JSON string info about protobuf data path
316
+ jsonString = json .dumps (self .context )
309
317
310
318
# Generate processed data
311
319
processing = openshot .ClipProcessingJobs (self .effect_name , jsonString )
312
- processing .processClip (self .clip_instance )
313
-
320
+ processing .processClip (self .clip_instance , jsonString )
321
+
322
+ # TODO: This is just a temporary fix. We need to find a better way to allow the user to fix the error
323
+ # The while loop is handling the error message. If pre-processing returns an error, a message
324
+ # will be displayed for 3 seconds and the effect will be closed.
325
+ start = time .time ()
326
+ while processing .GetError ():
327
+ self .error_label .setText (processing .GetErrorMessage ())
328
+ self .error_label .repaint ()
329
+ if (time .time ()- start )> 3 :
330
+ self .exporting = False
331
+ processing .CancelProcessing ()
332
+ while (not processing .IsDone () ):
333
+ continue
334
+ super (ProcessEffect , self ).reject ()
335
+
314
336
# get processing status
315
337
while (not processing .IsDone () ):
316
338
# update progressbar
@@ -340,61 +362,3 @@ def reject(self):
340
362
self .exporting = False
341
363
self .cancel_clip_processing = True
342
364
super (ProcessEffect , self ).reject ()
343
-
344
- def generateJson (self , protobufPath ):
345
- # Start JSON string with the protobuf data path, necessary for all pre-processing effects
346
- jsonString = '{"protobuf_data_path": "%s"' % protobufPath
347
-
348
- # Obs: Following redundant variables were created for better code visualization (e.g. smoothingWindow)
349
-
350
- # Special case where more info is needed for the JSON string
351
- if self .effect_name == "Stabilizer" :
352
- smoothingWindow = self .context ["smoothing-window" ]
353
- jsonString += ', "smoothing_window": %d' % (smoothingWindow )
354
-
355
- # Special case where more info is needed for the JSON string
356
- if self .effect_name == "Tracker" :
357
-
358
- # Set tracker info in JSON string
359
- # Get selected tracker [KCF, MIL, TLD, BOOSTING, MEDIANFLOW, MOOSE, CSRT]
360
- trackerType = self .context ["tracker-type" ]
361
- jsonString += ',"tracker_type": "%s"' % trackerType
362
-
363
- # Get bounding box coordinates
364
- tracker_dict = self .context ["region" ]
365
- bbox = (tracker_dict ["x" ],tracker_dict ["y" ],tracker_dict ["width" ],tracker_dict ["height" ])
366
- jsonString += ',"bbox": {"x": %d, "y": %d, "w": %d, "h": %d}' % (bbox )
367
-
368
- # Get processing start frame
369
- print (self .context ["region" ])
370
- jsonString += ',"first_frame": %d' % (self .context ["region" ]["first-frame" ])
371
-
372
- # Special case where more info is needed for the JSON string
373
- if self .effect_name == "Object Detector" :
374
-
375
- # Get model weights path
376
- modelweightsPath = self .context ["model-weights" ]
377
- if not os .path .exists (modelweightsPath ):
378
- modelweightsPath = ""
379
- jsonString += ', "model_weights": "%s"' % modelweightsPath
380
-
381
- # Get model configuration path
382
- modelConfigPath = self .context ["model-config" ]
383
- if not os .path .exists (modelConfigPath ):
384
- modelConfigPath = ""
385
- jsonString += ', "model_configuration": "%s"' % modelConfigPath
386
-
387
- # Get class names file path
388
- classNamesPath = self .context ["class-names" ]
389
- if not os .path .exists (classNamesPath ):
390
- classNamesPath = ""
391
- jsonString += ', "classes_file": "%s"' % classNamesPath
392
-
393
- # Get processing device
394
- processingDevice = self .context ["processing-device" ]
395
- jsonString += ', "processing_device": "%s"' % processingDevice
396
-
397
- # Finish JSON string
398
- jsonString += '}'
399
- if os .name == 'nt' : jsonString = jsonString .replace ("\\ " , "/" )
400
- return jsonString
0 commit comments