Skip to content

Commit

Permalink
Have manage experiment panel disable invalid experiments
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-eq committed Dec 20, 2024
1 parent cce2001 commit 869f845
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions src/ert/gui/tools/manage_experiments/storage_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def row(self) -> int:
def data(self, index: QModelIndex, role: Qt.ItemDataRole) -> Any:
if not index.isValid():
return None
print(f"{self=}")
col = index.column()
if role == Qt.ItemDataRole.DisplayRole:
if col == _Column.NAME:
Expand All @@ -98,6 +97,7 @@ def __init__(self, experiment: Experiment, parent: "StorageModel"):
self._id = experiment.id
self._name = experiment.name
self._is_valid = experiment.is_valid()
print(f"{self._is_valid=}")
self._experiment_type = experiment.metadata.get("ensemble_type")
self._children: list[EnsembleModel] = []

Expand All @@ -109,28 +109,6 @@ def row(self) -> int:
return self._parent._children.index(self)
return 0

@override
def hasChildren(self, index):
print("CALLED HAS_CHILDREN")
if not index.isValid():
return True

flags = self.flags(index)
# hide children if disabled
if not (flags & Qt.ItemFlag.ItemIsEnabled):
return False

return super().hasChildren(index)

@override
def flags(self, index: QModelIndex) -> Qt.ItemFlag:
default_flags = super().flags(index)
if not self._is_valid:
print("FLAGS WAS INVALID")
return default_flags & ~Qt.ItemFlag.ItemIsEnabled
print("FLAGS WAS VALID")
return default_flags

def data(
self, index: QModelIndex, role: Qt.ItemDataRole = Qt.ItemDataRole.DisplayRole

Check failure on line 113 in src/ert/gui/tools/manage_experiments/storage_model.py

View workflow job for this annotation

GitHub Actions / type-checking (3.12)

Argument 2 of "data" is incompatible with supertype "QAbstractItemModel"; supertype defines the argument type as "int"
) -> Any:
Expand Down Expand Up @@ -236,9 +214,32 @@ def headerData(
def data(self, index: QModelIndex, role: int = Qt.ItemDataRole.DisplayRole) -> Any:
if not index.isValid():
return None

print("CALLED DATA")
return index.internalPointer().data(index, role)

@override
def flags(self, index: QModelIndex) -> Qt.ItemFlag:

Check failure on line 221 in src/ert/gui/tools/manage_experiments/storage_model.py

View workflow job for this annotation

GitHub Actions / type-checking (3.12)

Return type "ItemFlag" of "flags" incompatible with return type "ItemFlags" in supertype "QAbstractItemModel"
default_flags = super().flags(index)
if not index.isValid():
return default_flags
item = index.internalPointer()
print("CALLED FLAGS")
if isinstance(item, ExperimentModel) and not item._is_valid:
return default_flags & ~Qt.ItemFlag.ItemIsEnabled

Check failure on line 228 in src/ert/gui/tools/manage_experiments/storage_model.py

View workflow job for this annotation

GitHub Actions / type-checking (3.12)

Incompatible return value type (got "int", expected "ItemFlag")
return default_flags

@override
def hasChildren(self, index):

Check failure on line 232 in src/ert/gui/tools/manage_experiments/storage_model.py

View workflow job for this annotation

GitHub Actions / type-checking (3.12)

Function is missing a type annotation
if not index.isValid():
return True

flags = self.flags(index)
# hide children if disabled
if not (flags & Qt.ItemFlag.ItemIsEnabled):
return False

return super().hasChildren(index)

@override
def index(
self, row: int, column: int, parent: QModelIndex | None = None
Expand Down

0 comments on commit 869f845

Please sign in to comment.