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.
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)
SecondWindowsuggests that you'll have two different windows. They don't share instance attributes.