Skip to content

Commit

Permalink
Emit signal when tab changes to select realization
Browse files Browse the repository at this point in the history
Co-authored-by: Jonathan Karlsen <[email protected]>
  • Loading branch information
andreas-el and jonathan-eq committed Dec 13, 2024
1 parent dc9defd commit 6dcfda8
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/ert/gui/simulation/run_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@ def is_simulation_done(self) -> bool:

def _current_tab_changed(self, index: int) -> None:
widget = self._tab_widget.widget(index)
if isinstance(widget, RealizationWidget):
widget.refresh_current_selection()

self.fm_step_frame.setHidden(isinstance(widget, UpdateWidget))

@Slot(QModelIndex, int, int)
Expand Down
4 changes: 4 additions & 0 deletions src/ert/gui/simulation/view/realization.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ def setSnapshotModel(self, model: QAbstractItemModel) -> None:
def clearSelection(self) -> None:
self._real_view.clearSelection()

def refresh_current_selection(self) -> None:
selected_reals = self._real_view.selectedIndexes()
self._item_clicked(selected_reals[0])


class RealizationDelegate(QStyledItemDelegate):
def __init__(self, size: QSize, parent: QObject) -> None:
Expand Down
95 changes: 95 additions & 0 deletions tests/ert/unit_tests/gui/simulation/test_run_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,3 +762,98 @@ def test_that_design_matrix_show_parameters_button_is_visible(
assert isinstance(show_dm_parameters, QPushButton)
else:
assert show_dm_parameters is None


@pytest.mark.parametrize(
"events,tab_widget_count",
[
pytest.param(
[
FullSnapshotEvent(
snapshot=(
SnapshotBuilder()
.add_fm_step(
fm_step_id="0",
index="0",
name="fm_step_0",
status=state.FORWARD_MODEL_STATE_START,
)
.build(["0", "1"], state.REALIZATION_STATE_UNKNOWN)
),
iteration_label="Foo",
total_iterations=1,
progress=0.5,
realization_count=2,
status_count={"Finished": 1, "Pending": 1},
iteration=0,
),
FullSnapshotEvent(
snapshot=(
SnapshotBuilder()
.add_fm_step(
fm_step_id="0",
index="0",
name="fm_step_0",
status=state.FORWARD_MODEL_STATE_START,
)
.build(["0", "1"], state.REALIZATION_STATE_FINISHED)
),
iteration_label="Foo",
total_iterations=1,
progress=0.5,
realization_count=2,
status_count={"Finished": 1, "Pending": 1},
iteration=1,
),
EndEvent(failed=False, msg=""),
],
2,
id="changing from between tabs",
),
],
)
def test_forward_model_overview_label_selected_on_tab_change(
events, tab_widget_count, qtbot: QtBot, event_queue, run_dialog
):
run_dialog.run_experiment()
for event in events:
event_queue.put(event)

def qt_bot_click_realization(realization_index: int, iteration: int) -> None:
view = run_dialog._tab_widget.widget(iteration)._real_view
model_index = view.model().index(realization_index, 0)
view.scrollTo(model_index)
rect = view.visualRect(model_index)
click_pos = rect.center()
qtbot.mouseClick(view.viewport(), Qt.LeftButton, pos=click_pos)

def qt_bot_click_tab_index(tab_index: int) -> None:
tab_bar = run_dialog._tab_widget.tabBar()
tab_rect = tab_bar.tabRect(tab_index)
click_pos = tab_rect.center()
qtbot.mouseClick(tab_bar, Qt.LeftButton, pos=click_pos)

# verify two tabs present
qtbot.waitUntil(
lambda: run_dialog._tab_widget.count() == tab_widget_count, timeout=5000
)
qtbot.waitUntil(lambda: run_dialog.is_simulation_done() == True, timeout=5000)

qt_bot_click_tab_index(0)
fm_step_label = run_dialog.findChild(QLabel, name="fm_step_label")
assert "Realization id 0 in iteration 0" in fm_step_label.text()

qt_bot_click_realization(1, 0)
assert "Realization id 1 in iteration 0" in fm_step_label.text()

qt_bot_click_tab_index(1)
assert "Realization id 0 in iteration 1" in fm_step_label.text()

qt_bot_click_realization(1, 1)
assert "Realization id 1 in iteration 1" in fm_step_label.text()

qt_bot_click_tab_index(0)
assert "Realization id 1 in iteration 0" in fm_step_label.text()

qt_bot_click_tab_index(1)
assert "Realization id 1 in iteration 1" in fm_step_label.text()

0 comments on commit 6dcfda8

Please sign in to comment.