Commit 0933ef9b authored by Flavio TARSETTI's avatar Flavio TARSETTI
Browse files

Merge branch '262_propagate_asset_change' into 'master'

Propagate prefix changes

See merge request !131
parents 01383740 312e4ac9
Pipeline #40296 passed with stages
in 8 minutes and 8 seconds
......@@ -23,6 +23,7 @@
# #
###############################################################################
import logging
import simplejson as json
from PyQt5.QtSql import QSqlDatabase
......@@ -39,6 +40,8 @@ PARAMETER_TYPE_KEY = "parameter_type"
DEFAULT_VALUE_KEY = "default_value"
EDITED_KEY = "edited"
logger = logging.getLogger(__name__)
# ------------------------------------------------------------------------------
......@@ -109,11 +112,10 @@ class ExperimentResources:
for algorithm in model.stringList():
asset = Asset(prefix_path, AssetType.ALGORITHM, algorithm)
try:
declaration = asset.declaration
except json.JSONDecodeError:
if not asset.is_valid:
continue
declaration = asset.declaration
inputs = {}
outputs = {}
for group in declaration["groups"]:
......@@ -173,7 +175,7 @@ class ExperimentResources:
for database_name in model.stringList():
database = Database(prefix_path, database_name)
if not database.valid:
print("Skipping invalid database:", database_name)
logger.debug("Skipping invalid database: {}".format(database_name))
continue
protocols = database.protocol_names
for protocol_name in protocols:
......@@ -191,6 +193,9 @@ class ExperimentResources:
)
experiment_resources = ExperimentResources()
class AlgorithmResourceModel(QSqlTableModel):
def __init__(self, parent=None):
super().__init__(parent=parent)
......
......@@ -769,6 +769,11 @@ class AlgorithmEditor(AbstractAssetEditor):
editor.deletionRequested.connect(self.__onRemoveResult)
self.result_list_widget.addWidget(editor)
def _asset_models(self):
"""Reimpl"""
return [self.dataformat_model, self.full_dataformat_model, self.library_model]
def _load_json(self, json_object):
"""Load the json object passed as parameter"""
......
......@@ -46,6 +46,7 @@ from PyQt5.QtWidgets import QWidget
from ..backend.asset import Asset
from ..backend.asset import AssetType
from ..backend.resourcemodels import experiment_resources
from ..decorators import frozen
from .algorithmeditor import AlgorithmEditor
from .algorithmeditor import migrate_to_api_v2
......@@ -347,6 +348,8 @@ class AssetWidget(QWidget):
self.context = context
experiment_resources.setContext(self.context)
for i in range(0, self.editors.count()):
self.editors.widget(i).set_context(context)
......
......@@ -708,6 +708,11 @@ class DatabaseWidget(QWidget):
"protocols": [widget.dump() for widget in self.scroll_widget.widget_list],
}
def asset_models(self):
"""Returns the models used"""
return [self.protocoltemplate_model]
@frozen
class DatabaseEditor(AbstractAssetEditor):
......@@ -730,6 +735,11 @@ class DatabaseEditor(AbstractAssetEditor):
lambda: self.database_widget.setPrefixPath(self.prefix_path)
)
def _asset_models(self):
"""Reimpl"""
return self.database_widget.asset_models()
def _load_json(self, json_object):
"""Load the json object passed as parameter"""
......
......@@ -628,6 +628,11 @@ class DataformatEditor(AbstractAssetEditor):
self.scroll_widget.removeWidget(widget)
def _asset_models(self):
"""Reimpl"""
return [self.dataformat_model]
def _load_json(self, json_object):
"""Re-impl Load the json object passed as parameter"""
......
......@@ -99,6 +99,18 @@ class AbstractAssetEditor(QWidget):
def description_max_length(self):
return self.description_lineedit.maxLength()
@pyqtSlot()
def refresh(self):
"""Reload the editor models"""
for model in self._asset_models():
model.reload()
def _asset_models(self):
"""Returns a list of all asset models used"""
return []
def _add_information_widget(self, label, widget):
"""Add field to information widget
......@@ -259,6 +271,7 @@ class AbstractAssetEditor(QWidget):
self.schema_version = json_object.get("schema_version")
self.blockSignals(True)
self.refresh()
self.description_lineedit.setText(json_object.get("description"))
self._load_json(json_object)
self.blockSignals(False)
......
......@@ -59,8 +59,8 @@ from ..backend.asset import Asset
from ..backend.asset import AssetType
from ..backend.assetmodel import AssetModel
from ..backend.resourcemodels import AlgorithmResourceModel
from ..backend.resourcemodels import ExperimentResources
from ..backend.resourcemodels import QueueResourceModel
from ..backend.resourcemodels import experiment_resources
from ..decorators import frozen
from ..utils import is_Qt_equal_or_higher
from .dialogs import AssetCreationDialog
......@@ -205,7 +205,7 @@ class DatasetModel(QStringListModel):
def __init__(self, parent=None):
super().__init__(parent)
def update(self):
def reload(self):
asset_model = AssetModel()
asset_model.asset_type = AssetType.DATABASE
asset_model.prefix_path = self.prefix_path
......@@ -227,7 +227,7 @@ class DatasetModel(QStringListModel):
def setPrefixPath(self, prefix_path):
self.prefix_path = prefix_path
self.update()
self.reload()
# ------------------------------------------------------------------------------
......@@ -1088,8 +1088,6 @@ class ExperimentEditor(AbstractAssetEditor):
self.setObjectName(self.__class__.__name__)
self.set_title(self.tr("Experiment"))
self.resource_model = ExperimentResources()
self.processing_env_model = EnvironmentModel()
self.dataset_model = DatasetModel()
......@@ -1131,8 +1129,6 @@ class ExperimentEditor(AbstractAssetEditor):
@pyqtSlot()
def __update(self):
self.resource_model.setContext(self.context)
for object_ in [
self.algorithm_model,
self.dataset_model,
......@@ -1159,6 +1155,13 @@ class ExperimentEditor(AbstractAssetEditor):
algorithms.add(editor.evaluator_properties_editor.algorithm)
self.globalparameters_widget.setup(algorithms)
def _asset_models(self):
"""Reimpl"""
# Here we use the fact that Python is weakly typed and reload
# the dataset model as well
return [self.algorithm_model, self.dataset_model]
def _createNewAsset(self, creation_type, asset_info):
"""Re-implement"""
......@@ -1277,7 +1280,7 @@ class ExperimentEditor(AbstractAssetEditor):
def _load_json(self, json_object):
"""Load the json object passed as parameter"""
self.resource_model.refresh()
experiment_resources.refresh()
for widget in [
self.datasets_widget,
......
......@@ -57,6 +57,11 @@ class LibraryEditor(AbstractAssetEditor):
lambda: self.library_model.setPrefixPath(self.prefix_path)
)
def _asset_models(self):
"""Reimpl"""
return [self.library_model]
def _load_json(self, json_object):
"""Load the json object passed as parameter"""
......
......@@ -223,6 +223,11 @@ class PlotterEditor(AbstractAssetEditor):
if self.parameter_viewers:
QTimer.singleShot(100, self.__showLatestParameter)
def _asset_models(self):
"""Returns a list of all asset models used"""
return [self.plotter_model, self.dataformat_model, self.library_model]
def _createNewAsset(self, creation_type, asset_info):
"""Re-implement to ensure we"""
......
......@@ -464,6 +464,11 @@ class PlotterParametersEditor(AbstractAssetEditor):
if self.parameter_viewers:
QTimer.singleShot(100, self.__showLatestParameter)
def _asset_models(self):
"""Returns a list of all asset models used"""
return [self.plotter_model, self.plotterparameter_model]
def _createNewAsset(self, creation_type, asset_info):
"""Re-implement to ensure we"""
......
......@@ -266,6 +266,11 @@ class ProtocolTemplateEditor(AbstractAssetEditor):
if self.set_widgets:
QTimer.singleShot(100, self.__showLatestSet)
def _asset_models(self):
"""Returns a list of all asset models used"""
return [self.dataformat_model]
def _load_json(self, json_object):
"""Load the json object passed as parameter"""
......
......@@ -71,6 +71,7 @@ from ..backend.asset import AssetType
from ..backend.assetmodel import AssetModel
from ..backend.resourcemodels import AlgorithmResourceModel
from ..backend.resourcemodels import DatasetResourceModel
from ..backend.resourcemodels import experiment_resources
from ..decorators import frozen
from .editor import AbstractAssetEditor
from .toolchainscene import ToolchainScene
......@@ -1854,10 +1855,13 @@ class ToolchainEditor(AbstractAssetEditor):
self.autonomous_loop_evaluator_list = []
self.toolchain.dataChanged.connect(self.dataChanged)
self.contextChanged.connect(self.__onContextChanged)
self.contextChanged.connect(self.__reloadData)
@pyqtSlot()
def __onContextChanged(self):
def __reloadData(self):
# ensure the experiments related data are up to date
experiment_resources.refresh()
algorithm_model = AlgorithmResourceModel()
algorithm_model.setAnalyzerEnabled(False)
algorithm_model.setTypes([Algorithm.SEQUENTIAL, Algorithm.AUTONOMOUS])
......@@ -1913,6 +1917,17 @@ class ToolchainEditor(AbstractAssetEditor):
self.analyzer_list,
)
def refresh(self):
"""Reimpl"""
super().refresh()
self.__reloadData()
def _asset_models(self):
"""Returns a list of all asset models used"""
return [self.toolchain_model]
def _load_json(self, json_object):
"""Load the json object passed as parameter"""
......
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