Skip to content

Commit 2a934ee

Browse files
committed
Improved error handling for effect pre-processing
Also made Json parser more generic by passing the context directly to clipProcessingJob The dialog window when an error occur still need to be improved
1 parent f371121 commit 2a934ee

File tree

2 files changed

+29
-65
lines changed

2 files changed

+29
-65
lines changed

src/windows/process_effect.py

+28-64
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import os
2929
import sys
3030
import time
31+
import json
3132
import operator
3233
import functools
3334

@@ -190,6 +191,11 @@ def __init__(self, clip_id, effect_name, effect_params):
190191

191192
row_count += 1
192193

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+
193199
# Add buttons
194200
self.cancel_button = QPushButton(_('Cancel'))
195201
self.process_button = QPushButton(_('Process Effect'))
@@ -288,8 +294,8 @@ def rect_select_clicked(self, widget, param):
288294
def accept(self):
289295
""" Start processing effect """
290296
# 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)
293299

294300
# Enable ProgressBar
295301
self.progressBar.setEnabled(True)
@@ -304,13 +310,29 @@ def accept(self):
304310
protobufPath = os.path.join(info.PROTOBUF_DATA_PATH, ID + '.data')
305311
if os.name == 'nt' : protobufPath = protobufPath.replace("\\", "/")
306312

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)
309317

310318
# Generate processed data
311319
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+
314336
# get processing status
315337
while(not processing.IsDone() ):
316338
# update progressbar
@@ -340,61 +362,3 @@ def reject(self):
340362
self.exporting = False
341363
self.cancel_clip_processing = True
342364
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

src/windows/ui/process-effect.ui

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>410</width>
10-
<height>217</height>
10+
<height>250</height>
1111
</rect>
1212
</property>
1313
<property name="minimumSize">

0 commit comments

Comments
 (0)