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