Skip to content

Commit

Permalink
Add columns to Manage Cases overview
Browse files Browse the repository at this point in the history
  • Loading branch information
pinkwah committed Mar 4, 2024
1 parent d45b784 commit 7f656ef
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 15 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ dependencies=[
"resdata",
"fastapi",
"filelock",
"humanize",
"importlib_resources;python_version <= '3.8'",
"iterative_ensemble_smoother>=0.2.3",
"typing_extensions>=4.5",
Expand Down
6 changes: 2 additions & 4 deletions src/ert/gui/ertwidgets/closabledialog.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from qtpy.QtCore import Qt
from qtpy.QtWidgets import QDialog, QHBoxLayout, QLayout, QPushButton, QVBoxLayout
from qtpy.QtWidgets import QDialog, QHBoxLayout, QPushButton, QVBoxLayout


class ClosableDialog(QDialog):
Expand All @@ -12,8 +12,7 @@ def __init__(self, title, widget, parent=None):
self.setWindowFlags(self.windowFlags() & ~Qt.WindowCloseButtonHint)

layout = QVBoxLayout()
layout.setSizeConstraint(QLayout.SetFixedSize) # not resizable!!!
layout.addWidget(widget)
layout.addWidget(widget, stretch=1)

self.__button_layout = QHBoxLayout()
self.close_button = QPushButton("Close")
Expand All @@ -23,7 +22,6 @@ def __init__(self, title, widget, parent=None):
self.__button_layout.addStretch()
self.__button_layout.addWidget(self.close_button)

layout.addStretch()
layout.addLayout(self.__button_layout)

self.setLayout(layout)
Expand Down
58 changes: 51 additions & 7 deletions src/ert/gui/ertwidgets/models/storage_model.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
from enum import IntEnum
from typing import Any, List

import humanize
from qtpy.QtCore import (
QAbstractItemModel,
QModelIndex,
Qt,
Slot,
)
from qtpy.QtWidgets import QApplication

from ert.storage import EnsembleReader, ExperimentReader, StorageReader


class _Column(IntEnum):
NAME = 0
TIME = 1
TYPE = 2
UUID = 3


_NUM_COLUMNS = max(_Column).value + 1
_COLUMN_TEXT = {
0: "Name",
1: "Created at",
2: "Type",
3: "ID",
}


class Ensemble:
def __init__(self, ensemble: EnsembleReader, parent: Any):
self._parent = parent
Expand All @@ -22,12 +41,21 @@ def row(self) -> int:
return self._parent._children.index(self)
return 0

def data(self, index: QModelIndex, role=Qt.ItemDataRole.DisplayRole) -> Any:
def data(self, index: QModelIndex, role) -> Any:
if not index.isValid():
return None

col = index.column()
if role == Qt.ItemDataRole.DisplayRole:
return f"{self._name} - {self._start_time} ({self._id})"
if col == _Column.NAME:
return self._name
if col == _Column.TIME:
return humanize.naturaltime(self._start_time)
if col == _Column.UUID:
return str(self._id)
elif role == Qt.ItemDataRole.ToolTipRole:
if col == _Column.TIME:
return str(self._start_time)

return None

Expand All @@ -37,9 +65,7 @@ def __init__(self, experiment: ExperimentReader, parent: Any):
self._parent = parent
self._id = experiment.id
self._name = experiment.name
self._experiment_type = experiment.simulation_arguments.get(
"analysis_module", ""
)
self._experiment_type = experiment.simulation_arguments.get("ensemble_type")
self._children: List[Ensemble] = []

def add_ensemble(self, ensemble: Ensemble) -> None:
Expand All @@ -54,13 +80,25 @@ def data(self, index: QModelIndex, role=Qt.ItemDataRole.DisplayRole) -> Any:
if not index.isValid():
return None

col = index.column()
if role == Qt.ItemDataRole.DisplayRole:
return f"{self._name} - {self._experiment_type} ({self._id})"
if col == _Column.NAME:
return self._name
if col == _Column.TYPE:
return self._experiment_type or "None"
if col == _Column.UUID:
return str(self._id)
elif role == Qt.ItemDataRole.ForegroundRole:
if col == _Column.TYPE and not self._experiment_type:
qapp = QApplication.instance()
assert isinstance(qapp, QApplication)
return qapp.palette().mid()

return None


class StorageModel(QAbstractItemModel):

def __init__(self, storage: StorageReader):
super().__init__(None)
self._children: List[Experiment] = []
Expand Down Expand Up @@ -89,7 +127,7 @@ def _load_storage(self, storage: StorageReader) -> None:
self._children.append(ex)

def columnCount(self, parent: QModelIndex) -> int:
return 1
return _NUM_COLUMNS

def rowCount(self, parent: QModelIndex) -> int:
if parent.isValid():
Expand All @@ -111,6 +149,12 @@ def parent(self, index: QModelIndex) -> QModelIndex:

return self.createIndex(parentItem.row(), 0, parentItem)

def headerData(self, section: int, orientation: int, role: int) -> Any:
if role != Qt.ItemDataRole.DisplayRole:
return None

return _COLUMN_TEXT[_Column(section)]

def data(self, index: QModelIndex, role=Qt.ItemDataRole.DisplayRole) -> Any:
if not index.isValid():
return None
Expand Down
4 changes: 0 additions & 4 deletions src/ert/gui/ertwidgets/storage_widget.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from qtpy.QtCore import QSortFilterProxyModel, Qt
from qtpy.QtWidgets import (
QHeaderView,
QLineEdit,
QTreeView,
QVBoxLayout,
Expand Down Expand Up @@ -31,9 +30,6 @@ def __init__(
lambda: storage_model.reloadStorage(self._notifier.storage)
)

if isinstance(tree_view.header(), QHeaderView):
tree_view.header().hide()

search_bar = QLineEdit(self)
search_bar.setPlaceholderText("Filter")
proxy_model = QSortFilterProxyModel()
Expand Down

0 comments on commit 7f656ef

Please sign in to comment.