Commit 9efd122d authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[widgets][experimenteditor] Refactor DatasetModel handling

parent cf44d58c
......@@ -48,7 +48,6 @@ from ..widgets.experimenteditor import AlgorithmParametersEditor
from ..widgets.experimenteditor import AnalyzerBlockEditor
from ..widgets.experimenteditor import BlockEditor
from ..widgets.experimenteditor import DatasetEditor
from ..widgets.experimenteditor import DatasetModel
from ..widgets.experimenteditor import EnvironmentModel
from ..widgets.experimenteditor import ExecutionPropertiesEditor
from ..widgets.experimenteditor import ExperimentEditor
......@@ -379,15 +378,8 @@ class TestDatasetEditor:
return datasets[dataset]
@pytest.fixture()
def dataset_model(self, test_prefix):
dataset_model = DatasetModel()
dataset_model.setPrefixPath(test_prefix)
return dataset_model
@pytest.fixture()
def editor(self, qtbot, test_prefix, datasets, dataset_model):
def editor(self, qtbot, test_prefix, datasets):
editor = DatasetEditor("test_block", test_prefix)
editor.setDatasetModel(dataset_model)
qtbot.addWidget(editor)
return editor
......
......@@ -331,12 +331,17 @@ class IOMapperDialog(QDialog):
class DatasetEditor(AbstractBaseEditor):
"""Widget allowing the setup of the various datasets used"""
datasetChanged = pyqtSignal(str)
def __init__(self, block_name, prefix_path, parent=None):
super().__init__(prefix_path, parent)
self.json_object = {}
self.block_name = block_name
self.dataset_model = DatasetModel()
self.dataset_model.setPrefixPath(prefix_path)
self.dataset_combobox = QComboBox()
self.dataset_combobox.setModel(self.dataset_model)
self.reset_button = QPushButton(
self.style().standardIcon(QStyle.SP_DialogResetButton), ""
)
......@@ -350,6 +355,7 @@ class DatasetEditor(AbstractBaseEditor):
layout.addRow(self.block_name, row_layout)
self.dataset_combobox.currentTextChanged.connect(self.dataChanged)
self.dataset_combobox.currentTextChanged.connect(self.datasetChanged)
self.reset_button.clicked.connect(self.reset)
def reset(self):
......@@ -363,8 +369,20 @@ class DatasetEditor(AbstractBaseEditor):
if self.dataset_combobox.currentText() != dataset_name:
self.dataset_combobox.setCurrentIndex(-1)
def setDatasetModel(self, dataset_model):
self.dataset_combobox.setModel(dataset_model)
def loadToolchainData(self, toolchain):
asset = AssetType.TOOLCHAIN.klass(self.prefix_path, toolchain)
outputs = []
if asset.valid:
outputs = asset.datasets[self.block_name]["outputs"]
current_dataset = self.dataset_combobox.currentText()
# Avoid emitting signals while updating the filter as the current
# entry will be invalidated.
self.dataset_combobox.blockSignals(True)
self.dataset_model.setupOuputFilter(outputs)
self.dataset_combobox.setCurrentText(current_dataset)
self.dataset_combobox.blockSignals(False)
def currentSet(self):
_, _, _, set_ = self.dataset_combobox.currentText().split("/")
......@@ -1096,6 +1114,10 @@ class GlobalParametersEditor(AbstractBaseEditor):
@frozen
class ExperimentEditor(AbstractAssetEditor):
"""Editor for experiment configuration"""
blockChanged = pyqtSignal(str, dict)
def __init__(self, parent=None):
super().__init__(AssetType.EXPERIMENT, parent)
self.setObjectName(self.__class__.__name__)
......@@ -1103,8 +1125,6 @@ class ExperimentEditor(AbstractAssetEditor):
self.processing_env_model = EnvironmentModel()
self.dataset_model = DatasetModel()
self.algorithm_model = AssetModel()
self.algorithm_model.setLatestOnlyEnabled(False)
self.algorithm_model.asset_type = AssetType.ALGORITHM
......@@ -1144,7 +1164,6 @@ class ExperimentEditor(AbstractAssetEditor):
def __update(self):
for object_ in [
self.algorithm_model,
self.dataset_model,
self.datasets_widget,
self.blocks_widget,
self.loops_widget,
......@@ -1173,7 +1192,7 @@ class ExperimentEditor(AbstractAssetEditor):
# Here we use the fact that Python is weakly typed and reload
# the dataset model as well
return [self.algorithm_model, self.dataset_model]
return [self.algorithm_model]
def _createNewAsset(self, creation_type, asset_info):
"""Re-implement"""
......@@ -1308,7 +1327,6 @@ class ExperimentEditor(AbstractAssetEditor):
if datasets:
for name, dataset in datasets.items():
editor = DatasetEditor(name, self.prefix_path)
editor.setDatasetModel(self.dataset_model)
editor.load(dataset)
self.datasets_widget.addWidget(editor)
......@@ -1404,3 +1422,7 @@ class ExperimentEditor(AbstractAssetEditor):
data["loops"] = loops
return data
def loadToolchainData(self, toolchain):
for widget in self.datasets_widget.widget_list:
widget.loadToolchainData(toolchain)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment