Skip to content

Commit 38411b0

Browse files
committed
Error handler for OpenCV effect not compiled with library
1 parent d5e9786 commit 38411b0

File tree

3 files changed

+23
-22
lines changed

3 files changed

+23
-22
lines changed

src/classes/effect_init.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
# solution to providing the pre-processing params needed for these special effects.
3131

3232
effect_options = {
33-
# TODO: Remove Bars example options
34-
"Bars": [
33+
# TODO: Remove Example example options
34+
"Example": [
3535
{
3636
"title": "Region",
3737
"setting": "region",
@@ -124,10 +124,6 @@
124124
"value": "MEDIANFLOW",
125125
"name": "MEDIANFLOW"
126126
},
127-
{
128-
"value": "GOTURN",
129-
"name": "GOTURN"
130-
},
131127
{
132128
"value": "MOSSE",
133129
"name": "MOSSE"

src/windows/process_effect.py

+7-11
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ class ProcessEffect(QDialog):
5151
ui_path = os.path.join(info.PATH, 'windows', 'ui', 'process-effect.ui')
5252

5353
def __init__(self, clip_id, effect_name, effect_params):
54+
55+
if not openshot.Clip().COMPILED_WITH_CV:
56+
raise ModuleNotFoundError("Openshot not compiled with OpenCV")
5457

5558
# Create dialog class
5659
QDialog.__init__(self)
@@ -59,6 +62,7 @@ def __init__(self, clip_id, effect_name, effect_params):
5962
self.effect_name = effect_name
6063
self.context = {}
6164

65+
# Access C++ timeline and find the Clip instance which this effect should be applied to
6266
timeline_instance = get_app().window.timeline_sync.timeline
6367
for clip_instance in timeline_instance.Clips():
6468
if clip_instance.Id() == self.clip_id:
@@ -195,7 +199,7 @@ def __init__(self, clip_id, effect_name, effect_params):
195199
# flag to close the clip processing thread
196200
self.cancel_clip_processing = False
197201
self.effect = None
198-
202+
199203
def spinner_value_changed(self, widget, param, value):
200204
"""Spinner value change callback"""
201205
self.context[param["setting"]] = value
@@ -293,19 +297,11 @@ def accept(self):
293297
# Print effect settings
294298
log.info(self.context)
295299

296-
# DO WORK HERE, and periodically set progressBar value
297-
# Access C++ timeline and find the Clip instance which this effect should be applied to
298-
299300
# Create effect Id and protobuf data path
300301
ID = get_app().project.generate_id()
301302

302-
protobufFolderPath = os.path.join(info.PATH, '..', 'protobuf_data')
303-
# Check if protobuf data folder exists, otherwise it will create one
304-
if not os.path.exists(protobufFolderPath):
305-
os.mkdir(protobufFolderPath)
306-
307303
# Create protobuf data path
308-
protobufPath = os.path.join(protobufFolderPath, ID + '.data')
304+
protobufPath = os.path.join(info.PROTOBUF_DATA_PATH, ID + '.data')
309305

310306
# Load into JSON string info abou protobuf data path
311307
jsonString = self.generateJson(protobufPath)
@@ -359,7 +355,7 @@ def generateJson(self, protobufPath):
359355
if self.effect_name == "Tracker":
360356

361357
# Set tracker info in JSON string
362-
# Get selected tracker [KCF, MIL, TLD, BOOSTING, MEDIANFLOW, GOTURN, MOOSE, CSRT]
358+
# Get selected tracker [KCF, MIL, TLD, BOOSTING, MEDIANFLOW, MOOSE, CSRT]
363359
trackerType = self.context["tracker-type"]
364360
jsonString += ',"tracker_type": "%s"' % trackerType
365361

src/windows/views/timeline_webview.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -1915,6 +1915,7 @@ def Slice_Triggered(self, action, clip_ids, trans_ids, playhead_position=0):
19151915
right_clip.data.pop('id')
19161916
right_clip.key.pop(1)
19171917

1918+
# Generate new ID to effects on the right (so they become new ones)
19181919
for clip_propertie_name, propertie_value in right_clip.data.items() :
19191920
if clip_propertie_name == "effects":
19201921
for item in propertie_value:
@@ -2962,18 +2963,25 @@ def addEffect(self, effect_names, position):
29622963
for clip in possible_clips:
29632964
if js_position == 0 or (clip.data["position"] <= js_position <= clip.data["position"] + (clip.data["end"] - clip.data["start"])):
29642965
log.info("Applying effect to clip")
2965-
log.info(clip)
2966-
print(name)
2967-
print(effect_options)
29682966
# Handle custom effect dialogs
29692967
if name in effect_options:
2970-
2968+
29712969
# Get effect options
29722970
effect_params = effect_options.get(name)
29732971

29742972
# Show effect pre-processing window
29752973
from windows.process_effect import ProcessEffect
2976-
win = ProcessEffect(clip.id, name, effect_params)
2974+
2975+
try:
2976+
win = ProcessEffect(clip.id, name, effect_params)
2977+
2978+
except ModuleNotFoundError as e:
2979+
print("[ERROR]: " + str(e))
2980+
return
2981+
2982+
print("Effect %s" % name)
2983+
print("Effect options: %s" % effect_options)
2984+
29772985
# Run the dialog event loop - blocking interaction on this window during this time
29782986
result = win.exec_()
29792987

@@ -2985,6 +2993,7 @@ def addEffect(self, effect_names, position):
29852993

29862994
# Create Effect
29872995
effect = win.effect # effect.Id already set
2996+
29882997
if effect is None:
29892998
break
29902999
else:

0 commit comments

Comments
 (0)