Skip to content

Commit

Permalink
Fixed plotter storing correct tab when switching plot types
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas-el committed Jan 2, 2025
1 parent 855c517 commit 80acf00
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/ert/gui/tools/plot/plot_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ def __init__(self, config_file: str, parent: QWidget | None):
self.addPlotWidget(CROSS_ENSEMBLE_STATISTICS, CrossEnsembleStatisticsPlot())
self.addPlotWidget(STD_DEV, StdDevPlot())
self._central_tab.currentChanged.connect(self.currentTabChanged)
self._prev_tab_widget: QWidget | None = None

self._prev_tab_widget_index = -1
self._current_tab_index = -1
self._prev_key_dimensionality = -1
self._prev_tab_widget_index_map: dict[int, int] = {2: 0, 1: 2, 3: 6}

QApplication.setOverrideCursor(Qt.CursorShape.WaitCursor)
try:
Expand Down Expand Up @@ -166,6 +170,7 @@ def __init__(self, config_file: str, parent: QWidget | None):

@Slot(int)
def currentTabChanged(self, index: Any) -> None:
self._current_tab_index = index
self.updatePlot()

@Slot(int)
Expand Down Expand Up @@ -334,7 +339,6 @@ def keySelected(self) -> None:
for widget in self._plot_widgets
if widget._plotter.dimensionality == key_def.dimensionality
]

current_widget = self._central_tab.currentWidget()

# Enabling/disabling tab triggers the
Expand All @@ -350,17 +354,20 @@ def keySelected(self) -> None:
)
self._central_tab.currentChanged.connect(self.currentTabChanged)

# Remember which tab widget was selected when switching between
# both same and different data-types.
if current_widget in available_widgets:
self._central_tab.setCurrentWidget(current_widget)
else:
if self._prev_tab_widget is None:
self._central_tab.setCurrentWidget(available_widgets[0])
else:
self._central_tab.setCurrentWidget(self._prev_tab_widget)
self._prev_tab_widget = current_widget
if 0 < self._prev_key_dimensionality != key_def.dimensionality:
if self._current_tab_index == -1:
self._current_tab_index = self._prev_tab_widget_index
self._prev_tab_widget_index_map[self._prev_key_dimensionality] = (
self._current_tab_index
)
current_widget = self._central_tab.widget(
self._prev_tab_widget_index_map[key_def.dimensionality]
)
self._current_tab_index = -1

self._central_tab.setCurrentWidget(current_widget)
self._prev_tab_widget_index = self._central_tab.currentIndex()
self._prev_key_dimensionality = key_def.dimensionality
self.updatePlot()

def toggleCustomizeDialog(self) -> None:
Expand Down

0 comments on commit 80acf00

Please sign in to comment.