check each tab if connected figure exists; maybe closes #150

This commit is contained in:
Dominik Demuth 2023-11-29 18:13:20 +01:00
parent 386bc5a371
commit bb5c6a5491

View File

@ -373,6 +373,7 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow):
_remove_pts = False
_remove_t1 = False
_move_to_data_tab = False
w = None
for w in self.area.subWindowList():
@ -390,8 +391,8 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow):
if self.t1tauwidget.connected_figure == gid:
self.t1tauwidget.connected_figure = None
self.current_graph_widget.add_external(self.t1tauwidget.min_pos)
self.current_graph_widget.add_external(self.t1tauwidget.parabola)
self.current_graph_widget.remove_external(self.t1tauwidget.min_pos)
self.current_graph_widget.remove_external(self.t1tauwidget.parabola)
_remove_t1 = True
if self.fit_dialog.connected_figure == gid:
@ -400,10 +401,10 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow):
self.current_graph_widget.remove_external(item)
if val_figure == gid:
self.valuewidget.connected_figure = None
self.current_graph_widget.remove_external(self.valuewidget.selection_real)
self.current_graph_widget.remove_external(self.valuewidget.selection_imag)
self.tabWidget.setCurrentIndex(0)
self.valuewidget.connected_figure = None
_move_to_data_tab = True
self.current_graph_widget.enable_picking(False)
@ -423,6 +424,8 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow):
self.tabWidget.removeTab(self.tabWidget.indexOf(self.t1tauwidget))
if _remove_pts:
self.tabWidget.removeTab(self.tabWidget.indexOf(self.ptsselectwidget))
if _move_to_data_tab:
self.tabWidget.setCurrentIndex(0)
if w is not None:
self.area.removeSubWindow(w)
@ -573,10 +576,12 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow):
self.ptsselectwidget.connected_figure = self.management.current_graph
pick_required = True
else:
if self.ptsselectwidget.connected_figure:
if self.ptsselectwidget.connected_figure in self.management.graphs:
g = self.management.graphs[self.ptsselectwidget.connected_figure]
for line in self.ptsselectwidget.pts_lines:
g.remove_external(line)
else:
self.ptsselectwidget.connected_figure = None
# self.ptsselectwidget.clear()
return pick_required, block_window
@ -589,10 +594,12 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow):
self.management.graphs[current_graph].add_external(self.valuewidget.selection_real)
self.management.graphs[current_graph].add_external(self.valuewidget.selection_imag)
else:
if self.valuewidget.connected_figure is not None:
if self.valuewidget.connected_figure in self.management.graphs:
conn_fig = self.valuewidget.connected_figure
self.management.graphs[conn_fig].remove_external(self.valuewidget.selection_real)
self.management.graphs[conn_fig].remove_external(self.valuewidget.selection_imag)
else:
self.valuewidget.connected_figure = None
def _select_integralwidget(self, onoff: bool, pick_required: bool, block_window: bool) -> tuple[bool, bool]:
if self.current_graph_widget is None:
@ -606,11 +613,13 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow):
pick_required = True
block_window = True
else:
if self.integralwidget.connected_figure:
if self.integralwidget.connected_figure in self.management.graphs:
g = self.management.graphs[self.integralwidget.connected_figure]
for line in self.integralwidget.lines:
g.remove_external(line[0])
g.remove_external(line[1])
else:
self.integralwidget.connected_figure = None
self.integralwidget.clear()
return pick_required, block_window
@ -639,10 +648,12 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow):
pick_required = True
block_window = True
else:
if self.t1tauwidget.connected_figure:
if self.t1tauwidget.connected_figure in self.management.graphs:
g = self.management.graphs[self.t1tauwidget.connected_figure]
g.remove_external(self.t1tauwidget.min_pos)
g.remove_external(self.t1tauwidget.parabola)
else:
self.t1tauwidget.connected_figure = None
return pick_required, block_window