Skip to content

Commit e0af3c5

Browse files
committed
Refactor some logic in Parent / Child property context menus - to be simpler, and more efficient. This solves a bug on Windows also, where file paths were not matching correctly.
1 parent 954d868 commit e0af3c5

File tree

1 file changed

+36
-47
lines changed

1 file changed

+36
-47
lines changed

src/windows/views/properties_tableview.py

+36-47
Original file line numberDiff line numberDiff line change
@@ -456,45 +456,40 @@ def contextMenuEvent(self, event):
456456

457457
# Handle parent effect options
458458
if property_key == "parent_effect_id" and not self.choices:
459-
# Instantiate the timeline
460-
timeline_instance = get_app().window.timeline_sync.timeline
461459
# Instantiate this effect
462-
effect = timeline_instance.GetClipEffect(clip_id)
463-
effect_json = json.loads(effect.Json())
460+
effect = Effect.get(id=clip_id)
464461

465462
# Loop through timeline's clips
466463
clip_choices = []
467-
for clip_instance in timeline_instance.Clips():
468-
clip_instance_id = clip_instance.Id()
469-
# Avoid parent a clip effect to it's own effect
470-
if clip_instance_id != effect.ParentClipId():
471-
# Clip's propertyJSON data
472-
clip_instance_data = Clip.get(id=clip_instance_id).data
473-
# Path to the clip file
474-
clip_instance_path = clip_instance_data["reader"]["path"]
475-
# Iterate through all clip files on the timeline
476-
for clip_number in range(self.files_model.rowCount()):
477-
clip_index = self.files_model.index(clip_number, 0)
478-
clip_name = clip_index.sibling(clip_number, 1).data()
479-
clip_path = os.path.join(clip_index.sibling(clip_number, 4).data(), clip_name)
480-
# Check if the timeline's clip file name matches the clip the user selected
481-
if clip_path == clip_instance_path:
482-
# Generate the clip icon to show in the selection menu
483-
clip_instance_icon = clip_index.data(Qt.DecorationRole)
464+
for clip in Clip.filter():
465+
file_id = clip.data.get("file_id")
466+
467+
# Look up parent clip id (if effect)
468+
parent_clip_id = effect.parent.get("id")
469+
470+
# Avoid attach a clip to it's own object
471+
if clip.id != parent_clip_id:
472+
# Iterate through all project files (to find matching QIcon)
473+
for file_index in range(self.files_model.rowCount()):
474+
file_row = self.files_model.index(file_index, 0)
475+
project_file_id = file_row.sibling(file_index, 5).data()
476+
if file_id == project_file_id:
477+
clip_instance_icon = file_row.data(Qt.DecorationRole)
478+
break
479+
484480
effect_choices = []
485481
# Iterate through clip's effects
486-
for effect_data in clip_instance_data["effects"]:
482+
for clip_effect_data in clip.data["effects"]:
487483
# Make sure the user can only set a parent effect of the same type as this effect
488-
if effect_data['class_name'] == effect_json['class_name']:
489-
effect_id = effect_data["id"]
490-
effect_name = effect_data['class_name']
491-
effect_icon = QIcon(QPixmap(os.path.join(info.PATH, "effects", "icons", "%s.png" % effect_data['class_name'].lower())))
484+
if clip_effect_data['class_name'] == effect.data['class_name']:
485+
effect_id = clip_effect_data["id"]
486+
effect_icon = QIcon(QPixmap(os.path.join(info.PATH, "effects", "icons", "%s.png" % clip_effect_data['class_name'].lower())))
492487
effect_choices.append({"name": effect_id,
493488
"value": effect_id,
494489
"selected": False,
495490
"icon": effect_icon})
496491
if effect_choices:
497-
clip_choices.append({"name": _(clip_instance_data["title"]),
492+
clip_choices.append({"name": _(clip.data["title"]),
498493
"value": effect_choices,
499494
"selected": False,
500495
"icon": clip_instance_icon})
@@ -531,39 +526,33 @@ def contextMenuEvent(self, event):
531526
# Instantiate the timeline
532527
timeline_instance = get_app().window.timeline_sync.timeline
533528
# Loop through timeline's clips
534-
for clip_instance in timeline_instance.Clips():
535-
clip_instance_id = clip_instance.Id()
529+
for clip in Clip.filter():
530+
file_id = clip.data.get("file_id")
531+
536532
# Look up parent clip id (if effect)
537533
parent_clip_id = clip_id
538534
if item_type == "effect":
539535
parent_clip_id = Effect.get(id=clip_id).parent.get("id")
540536
log.debug(f"Lookup parent clip ID for effect: '{clip_id}' = '{parent_clip_id}'")
541537

542538
# Avoid attach a clip to it's own object
543-
if clip_instance_id != parent_clip_id:
544-
# Clip's propertyJSON data
545-
clip_instance_data = Clip.get(id=clip_instance_id).data
546-
# Path to the clip file
547-
clip_instance_path = clip_instance_data["reader"]["path"]
548-
# Iterate through all clip files on the timeline
549-
for clip_number in range(self.files_model.rowCount()):
550-
clip_index = self.files_model.index(clip_number, 0)
551-
clip_name = clip_index.sibling(clip_number, 1).data()
552-
clip_path = os.path.join(clip_index.sibling(clip_number, 4).data(), clip_name)
553-
# Check if the timeline's clip file name matches the clip the user selected
554-
if clip_path == clip_instance_path:
555-
# Generate the clip icon to show in the selection menu
556-
clip_instance_icon = clip_index.data(Qt.DecorationRole)
557-
clip_choices.append({"name": clip_instance_data["title"],
558-
"value": clip_instance_id,
539+
if clip.id != parent_clip_id:
540+
# Iterate through all project files (to find matching QIcon)
541+
for file_index in range(self.files_model.rowCount()):
542+
file_row = self.files_model.index(file_index, 0)
543+
project_file_id = file_row.sibling(file_index, 5).data()
544+
if file_id == project_file_id:
545+
clip_instance_icon = file_row.data(Qt.DecorationRole)
546+
clip_choices.append({"name": clip.data["title"],
547+
"value": clip.id,
559548
"selected": False,
560549
"icon": clip_instance_icon})
561550
# Get the pixmap of the clip icon
562551
icon_size = 72
563552
icon_pixmap = clip_instance_icon.pixmap(icon_size, icon_size)
564553
# Add tracked objects to the selection menu
565554
tracked_objects = []
566-
for effect in clip_instance_data["effects"]:
555+
for effect in clip.data["effects"]:
567556
# Check if effect has a tracked object
568557
if effect.get("has_tracked_object"):
569558
# Instantiate the effect
@@ -583,7 +572,7 @@ def contextMenuEvent(self, event):
583572
"value": str(object_id),
584573
"selected": False,
585574
"icon": QIcon(tracked_object_icon)})
586-
tracked_choices.append({"name": clip_instance_data["title"],
575+
tracked_choices.append({"name": clip.data["title"],
587576
"value": tracked_objects,
588577
"selected": False,
589578
"icon": clip_instance_icon})

0 commit comments

Comments
 (0)