0

When using a GUI design software, an instance variable cannot be accessed outside after being modified inside a nested function triggered by mouse events like on_motion.

enter image description here The instance attribute stores the Bezier curve in the figure, but because the updated value is not passed, the graph on the right is plotting the initial value, while the graph on the left plots correctly. I tried using the signal mechanism for passing values, but it was unsuccessful.

As shown in the code, the saved data indicates that hub1 and hub3 are identical, while hub2 has been modified through a mouse event. What I want is for the matrix passed to hub3 to be the same as hub2, rather than the initial value.

class MainWindow(QtWidgets.QMainWindow):
    def __init__(self):
        super().__init__()
        uic.loadUi('Bezier_fit.ui', self)

        self.shroud_bezier_line, self.hub_bezier_line = bezier_point(self.inter_point, self.ctr_point)
        # np.savetxt("hub1",self.hub_bezier_line)
        self.bezier_line.clicked.connect(lambda: self.set_ctr_point()) 

    def set_ctr_point(self):
        def on_motion(event):
            if dragging and event.inaxes == self.plotCanvas_bezier.ax:                        
                self.ctr_point = renew_data(self.ctr_point, event.xdata, event.ydata, current_index)
                self.shroud_bezier_line,self.hub_bezier_line=bezier_point(self.inter_point,
                                                                            self.ctr_point)
                # np.savetxt("hub2",self.hub_bezier_line)

        cid_motion = self.plotCanvas_bezier.ax.figure.canvas.mpl_connect('motion_notify_event', on_motion)

class SecondWindow(MainWindow):
    def __init__(self):
        super().__init__()
        uic.loadUi('streamline.ui', self)

        # np.savetxt("hub3",self.hub_bezier_line)
3
  • Are you sure they're the same instances? You haven't shown how you're using these classes. Commented Nov 7, 2024 at 17:09
  • The class name SecondWindow suggests that you'll have two different windows. They don't share instance attributes. Commented Nov 7, 2024 at 17:10
  • I might not have fully understood the underlying principles of the interface transition function, but I have found relevant learning materials and implemented the function. Thank you! Commented Nov 11, 2024 at 3:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.