-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve handling of missing responses.json #9589
base: main
Are you sure you want to change the base?
Changes from all commits
c206503
f1d779c
2fe1d74
f073d13
cce2001
869f845
cfd7dcb
96589e2
5553bdc
e4b16cc
9665ce0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,7 @@ | |
self._id = ensemble.id | ||
self._start_time = ensemble.started_at | ||
self._children: list[RealizationModel] = [] | ||
self._error = ensemble.experiment.error_message | ||
|
||
def add_realization(self, realization: RealizationModel) -> None: | ||
self._children.append(realization) | ||
|
@@ -75,25 +76,29 @@ | |
def data(self, index: QModelIndex, role: Qt.ItemDataRole) -> Any: | ||
if not index.isValid(): | ||
return None | ||
|
||
col = index.column() | ||
if role == Qt.ItemDataRole.DisplayRole: | ||
if col == _Column.NAME: | ||
return self._name | ||
if col == _Column.TIME: | ||
return humanize.naturaltime(self._start_time) | ||
elif role == Qt.ItemDataRole.ToolTipRole: | ||
if self._error: | ||
print("FOUND ERROR TOOLTIP") | ||
return self._error | ||
if col == _Column.TIME: | ||
return str(self._start_time) | ||
|
||
return None | ||
|
||
|
||
class ExperimentModel: | ||
def __init__(self, experiment: Experiment, parent: Any): | ||
class ExperimentModel(QAbstractItemModel): | ||
def __init__(self, experiment: Experiment, parent: "StorageModel"): | ||
self._parent = parent | ||
self._id = experiment.id | ||
self._name = experiment.name | ||
self._is_valid = experiment.is_valid() | ||
self._error = experiment.error_message | ||
print(f"{self._is_valid=}") | ||
self._experiment_type = experiment.metadata.get("ensemble_type") | ||
self._children: list[EnsembleModel] = [] | ||
|
||
|
@@ -106,7 +111,7 @@ | |
return 0 | ||
|
||
def data( | ||
self, index: QModelIndex, role: Qt.ItemDataRole = Qt.ItemDataRole.DisplayRole | ||
) -> Any: | ||
if not index.isValid(): | ||
return None | ||
|
@@ -128,7 +133,11 @@ | |
qapp = QApplication.instance() | ||
assert isinstance(qapp, QApplication) | ||
return qapp.palette().mid() | ||
|
||
if role == Qt.ItemDataRole.ToolTipRole: | ||
print("TRYING TO GET TOOLTIP") | ||
if self._error: | ||
print("FOUND ERROR TOOLTIP") | ||
return self._error | ||
return None | ||
|
||
|
||
|
@@ -140,6 +149,7 @@ | |
|
||
@Slot(Storage) | ||
def reloadStorage(self, storage: Storage) -> None: | ||
print("RELOADED STORAGE") | ||
self.beginResetModel() | ||
self._load_storage(storage) | ||
self.endResetModel() | ||
|
@@ -211,9 +221,31 @@ | |
def data(self, index: QModelIndex, role: int = Qt.ItemDataRole.DisplayRole) -> Any: | ||
if not index.isValid(): | ||
return None | ||
|
||
return index.internalPointer().data(index, role) | ||
|
||
@override | ||
def flags(self, index: QModelIndex) -> Qt.ItemFlag: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suspect this should return multiple flags instead (the c++ function does that) |
||
default_flags = super().flags(index) | ||
|
||
if not index.isValid(): | ||
return default_flags | ||
item = index.internalPointer() | ||
if isinstance(item, ExperimentModel) and not item._is_valid: | ||
return default_flags & ~Qt.ItemFlag.ItemIsEnabled | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could the be resolved if you create a typed variable and apply the flag change? |
||
return default_flags | ||
|
||
@override | ||
def hasChildren(self, parent: QModelIndex | None = None) -> bool: | ||
if parent is None or not parent.isValid(): | ||
return True | ||
|
||
flags = self.flags(parent) | ||
# hide children if disabled | ||
if not (flags & Qt.ItemFlag.ItemIsEnabled): | ||
return False | ||
|
||
return super().hasChildren(parent) | ||
|
||
@override | ||
def index( | ||
self, row: int, column: int, parent: QModelIndex | None = None | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work? Not itemData(index) ?
https://doc.qt.io/qtforpython-5/PySide2/QtCore/QAbstractItemModel.html#PySide2.QtCore.PySide2.QtCore.QAbstractItemModel.itemData
https://doc.qt.io/qt-6/qabstractitemmodel.html#itemData