From 9116ef3620e3e5e52de85584f88c9c4ba3bd440d Mon Sep 17 00:00:00 2001 From: 7174Andy Date: Thu, 19 Dec 2024 19:15:40 -0800 Subject: [PATCH] used commands from the context --- sleap/gui/widgets/video.py | 35 +++++++---------------------------- 1 file changed, 7 insertions(+), 28 deletions(-) diff --git a/sleap/gui/widgets/video.py b/sleap/gui/widgets/video.py index bbf16db4c..635b4af22 100644 --- a/sleap/gui/widgets/video.py +++ b/sleap/gui/widgets/video.py @@ -2135,39 +2135,18 @@ def _duplicate_instance(self, event): """Duplicate the instance and add it to the scene.""" scene = self.scene() - # Create a new instance by copying this one - new_instance = Instance.from_numpy( - self.instance.numpy(), skeleton=self.skeleton - ) - new_instance.track = None - # Add instance to the context context = self.player.context - current_frame = self.player.state["labeled_frame"] - if context: - context.labels.labeled_frames.insert( - self.player.state["frame_idx"], new_instance - ) - context.labels.add_instance(current_frame, new_instance) - - # Create a new QtInstance object for the new instance - new_instance_gui = QtInstance( - instance=new_instance, - player=self.player, - markerRadius=self.markerRadius, - nodeLabelSize=self.nodeLabelSize, - show_non_visible=self.show_non_visible, - ) - scene.addItem(new_instance_gui) - self.player.update_plot() + context.newInstance(copy_instance=self.instance) + + lf = context.labels.find( + context.state["video"], context.state["frame_idx"], return_new=True + )[0] + new_instance = lf.instances[-1] # Select the duplicated QtInstance object - new_instance_gui.setFlag(QGraphicsItem.ItemIsMovable) - new_instance_gui.setTransformOriginPoint(self.pos()) - new_instance_gui.setSelected(True) - new_instance_gui.setCursor(Qt.ClosedHandCursor) - new_instance_gui.grabMouse() self.player.state["instance"] = new_instance + self.player.plot() def mouseMoveEvent(self, event): """Custom event handler to emit signal on event."""