Skip to content

Commit

Permalink
Select first realizations by default in gui
Browse files Browse the repository at this point in the history
* Select first realizations by default in gui

Co-authored-by: Andreas Eknes Lie <andrli@equinor.com>
  • Loading branch information
AugustoMagalhaes and andreas-el authored Nov 27, 2024
1 parent 9a89ae3 commit 7e0f793
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
36 changes: 17 additions & 19 deletions src/ert/gui/simulation/run_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,7 @@ def on_snapshot_new_iteration(

widget = RealizationWidget(iter_row)
widget.setSnapshotModel(self._snapshot_model)
widget.itemClicked.connect(self._select_real)

self._select_real(widget._real_list_model.index(0, 0))
tab_index = self._tab_widget.addTab(
widget, f"Realizations for iteration {index.internalPointer().id_}"
)
Expand All @@ -321,23 +320,22 @@ def on_snapshot_new_iteration(

@Slot(QModelIndex)
def _select_real(self, index: QModelIndex) -> None:
real = index.row()
iter_ = index.model().get_iter() # type: ignore
exec_hosts = None

iter_node = self._snapshot_model.root.children.get(str(iter_), None)
if iter_node:
real_node = iter_node.children.get(str(real), None)
if real_node:
exec_hosts = real_node.data.exec_hosts

self._fm_step_overview.set_realization(iter_, real)
text = (
f"Realization id {index.data(RealIens)} in iteration {index.data(IterNum)}"
)
if exec_hosts and exec_hosts != "-":
text += f", assigned to host: {exec_hosts}"
self._fm_step_label.setText(text)
if index.isValid():
real = index.row()
iter_ = index.model().get_iter() # type: ignore
exec_hosts = None

iter_node = self._snapshot_model.root.children.get(str(iter_), None)
if iter_node:
real_node = iter_node.children.get(str(real), None)
if real_node:
exec_hosts = real_node.data.exec_hosts

self._fm_step_overview.set_realization(iter_, real)
text = f"Realization id {index.data(RealIens)} in iteration {index.data(IterNum)}"
if exec_hosts and exec_hosts != "-":
text += f", assigned to host: {exec_hosts}"
self._fm_step_label.setText(text)

def run_experiment(self, restart: bool = False) -> None:
self._restart = restart
Expand Down
6 changes: 6 additions & 0 deletions src/ert/gui/simulation/view/realization.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from qtpy.QtCore import (
QAbstractItemModel,
QEvent,
QItemSelectionModel,
QModelIndex,
QObject,
QPoint,
Expand Down Expand Up @@ -74,6 +75,11 @@ def setSnapshotModel(self, model: QAbstractItemModel) -> None:
self._real_view.setModel(self._real_list_model)
self._real_list_model.setIter(self._iter)

first_real = self._real_list_model.index(0, 0)
selection_model = self._real_view.selectionModel()
if first_real.isValid() and selection_model:
selection_model.select(first_real, QItemSelectionModel.SelectionFlag.Select)

def clearSelection(self) -> None:
self._real_view.clearSelection()

Expand Down
2 changes: 1 addition & 1 deletion tests/ert/unit_tests/gui/simulation/test_run_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ def test_run_dialog_fm_label_show_correct_info(
assert fm_step_model._real == 0

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

realization_box._item_clicked(run_dialog._fm_step_overview.model().index(0, 0))
assert (
Expand Down

0 comments on commit 7e0f793

Please sign in to comment.