优化X轴联动功能,增强同步处理逻辑,避免回调冲突
This commit is contained in:
@ -494,18 +494,25 @@ class MainWindow_precisely_align(QMainWindow):
|
||||
self.ax0.set_title("JJIV")
|
||||
self.ax1.set_title("RRIV")
|
||||
|
||||
def on_xlim_changed(ax):
|
||||
if ax is self.ax0:
|
||||
x0, x1 = ax.get_xlim()
|
||||
self.ax1.callbacks.disconnect('xlim_changed')
|
||||
self.ax1.set_xlim(x0, x1)
|
||||
self.ax1.callbacks.connect('xlim_changed', on_xlim_changed)
|
||||
elif ax is self.ax1:
|
||||
x0, x1 = ax.get_xlim()
|
||||
self.ax0.callbacks.disconnect('xlim_changed')
|
||||
self.ax0.set_xlim(x0, x1)
|
||||
self.ax0.callbacks.connect('xlim_changed', on_xlim_changed)
|
||||
self._syncing_xlim_change = False
|
||||
|
||||
def on_ax0_xlim_changed(ax):
|
||||
if self._syncing_xlim_change:
|
||||
return
|
||||
if ax is self.ax0:
|
||||
self._syncing_xlim_change = True
|
||||
x0, x1 = ax.get_xlim()
|
||||
self.ax1.set_xlim(x0, x1)
|
||||
self._syncing_xlim_change = False
|
||||
|
||||
def on_ax1_xlim_changed(ax):
|
||||
if self._syncing_xlim_change:
|
||||
return
|
||||
if ax is self.ax1:
|
||||
self._syncing_xlim_change = True
|
||||
x0, x1 = ax.get_xlim()
|
||||
self.ax0.set_xlim(x0, x1)
|
||||
self._syncing_xlim_change = False
|
||||
|
||||
if self.data.BCG_early:
|
||||
Jpeak = Jpeak - self.data.approximately_align_pos
|
||||
@ -556,8 +563,8 @@ class MainWindow_precisely_align(QMainWindow):
|
||||
label=Constants.PRECISELY_ALIGN_PLOT_LABEL_RRIV)
|
||||
self.ax1.xaxis.set_major_formatter(Params.FORMATTER)
|
||||
|
||||
self.ax0.callbacks.connect('xlim_changed', on_xlim_changed)
|
||||
self.ax1.callbacks.connect('xlim_changed', on_xlim_changed)
|
||||
self.ax0.callbacks.connect('xlim_changed', on_ax0_xlim_changed)
|
||||
self.ax1.callbacks.connect('xlim_changed', on_ax1_xlim_changed)
|
||||
|
||||
|
||||
self.ax0.legend(loc=Constants.PLOT_UPPER_RIGHT)
|
||||
|
||||
Reference in New Issue
Block a user