Commit 358e4230 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[widgets][editor] Add validation method to editor

This method will allow to check whether the content of the editor
is valid and continue further.
parent 4bd0bdfd
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
# # # #
############################################################################### ###############################################################################
from ..backend.assetmodel import AssetType
from ..utils import frozen from ..utils import frozen
from .editor import AbstractAssetEditor from .editor import AbstractAssetEditor
...@@ -31,7 +32,7 @@ from .editor import AbstractAssetEditor ...@@ -31,7 +32,7 @@ from .editor import AbstractAssetEditor
@frozen @frozen
class AlgorithmEditor(AbstractAssetEditor): class AlgorithmEditor(AbstractAssetEditor):
def __init__(self, parent=None): def __init__(self, parent=None):
super(AlgorithmEditor, self).__init__(parent) super(AlgorithmEditor, self).__init__(AssetType.ALGORITHM, parent)
self.setObjectName(self.__class__.__name__) self.setObjectName(self.__class__.__name__)
self.set_title(self.tr("Algorithm")) self.set_title(self.tr("Algorithm"))
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
# # # #
############################################################################### ###############################################################################
from ..backend.assetmodel import AssetType
from ..utils import frozen from ..utils import frozen
from .editor import AbstractAssetEditor from .editor import AbstractAssetEditor
...@@ -31,7 +32,7 @@ from .editor import AbstractAssetEditor ...@@ -31,7 +32,7 @@ from .editor import AbstractAssetEditor
@frozen @frozen
class DatabaseEditor(AbstractAssetEditor): class DatabaseEditor(AbstractAssetEditor):
def __init__(self, parent=None): def __init__(self, parent=None):
super(DatabaseEditor, self).__init__(parent) super(DatabaseEditor, self).__init__(AssetType.DATABASE, parent)
self.setObjectName(self.__class__.__name__) self.setObjectName(self.__class__.__name__)
self.set_title(self.tr("Database")) self.set_title(self.tr("Database"))
......
...@@ -31,7 +31,12 @@ from .editor import AbstractAssetEditor ...@@ -31,7 +31,12 @@ from .editor import AbstractAssetEditor
@frozen @frozen
class DataformatEditor(AbstractAssetEditor): class DataformatEditor(AbstractAssetEditor):
def __init__(self, parent=None): def __init__(self, parent=None):
super(DataformatEditor, self).__init__(parent) """Constructor
:param parent QWidget: parent of this widget
"""
super(DataformatEditor, self).__init__(AssetType.DATAFORMAT, parent)
self.setObjectName(self.__class__.__name__) self.setObjectName(self.__class__.__name__)
self.set_title(self.tr("Dataformat")) self.set_title(self.tr("Dataformat"))
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
# # # #
############################################################################### ###############################################################################
from ..backend.assetmodel import AssetType
import simplejson as json import simplejson as json
from PyQt5.QtCore import pyqtSignal from PyQt5.QtCore import pyqtSignal
...@@ -40,7 +41,7 @@ class AbstractAssetEditor(QWidget): ...@@ -40,7 +41,7 @@ class AbstractAssetEditor(QWidget):
dataChanged = pyqtSignal() dataChanged = pyqtSignal()
def __init__(self, title, parent=None): def __init__(self, asset_type, parent=None):
"""Constructor """Constructor
:param str title: Title of the editor :param str title: Title of the editor
...@@ -49,6 +50,8 @@ class AbstractAssetEditor(QWidget): ...@@ -49,6 +50,8 @@ class AbstractAssetEditor(QWidget):
super(AbstractAssetEditor, self).__init__(parent) super(AbstractAssetEditor, self).__init__(parent)
self.asset_type = asset_type
self.clear_dirty() self.clear_dirty()
self.title_label = QLabel(self.tr("Unknown")) self.title_label = QLabel(self.tr("Unknown"))
self.description_lineedit = QLineEdit() self.description_lineedit = QLineEdit()
...@@ -96,6 +99,11 @@ class AbstractAssetEditor(QWidget): ...@@ -96,6 +99,11 @@ class AbstractAssetEditor(QWidget):
raise NotImplementedError raise NotImplementedError
def is_valid(self):
_, errors = self.asset_type.validate(self.dump_json())
return errors == [], errors
def set_dirty(self): def set_dirty(self):
"""Flag the editor as dirty""" """Flag the editor as dirty"""
...@@ -164,8 +172,8 @@ class PlaceholderEditor(AbstractAssetEditor): ...@@ -164,8 +172,8 @@ class PlaceholderEditor(AbstractAssetEditor):
:param parent QWidget: parent of this widget :param parent QWidget: parent of this widget
""" """
super(PlaceholderEditor, self).__init__(parent) super(PlaceholderEditor, self).__init__(AssetType.UNKNOWN, parent)
self.set_title("Nothing to edit") self.set_title(self.tr("Nothing to edit"))
self.information_group_box.hide() self.information_group_box.hide()
def _load_json(self, json_object): def _load_json(self, json_object):
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
# # # #
############################################################################### ###############################################################################
from ..backend.assetmodel import AssetType
from ..utils import frozen from ..utils import frozen
from .editor import AbstractAssetEditor from .editor import AbstractAssetEditor
...@@ -31,7 +32,7 @@ from .editor import AbstractAssetEditor ...@@ -31,7 +32,7 @@ from .editor import AbstractAssetEditor
@frozen @frozen
class ExperimentEditor(AbstractAssetEditor): class ExperimentEditor(AbstractAssetEditor):
def __init__(self, parent=None): def __init__(self, parent=None):
super(ExperimentEditor, self).__init__(parent) super(ExperimentEditor, self).__init__(AssetType.EXPERIMENT, parent)
self.setObjectName(self.__class__.__name__) self.setObjectName(self.__class__.__name__)
self.set_title(self.tr("Experiment")) self.set_title(self.tr("Experiment"))
......
...@@ -42,7 +42,7 @@ class LibraryEditor(AbstractAssetEditor): ...@@ -42,7 +42,7 @@ class LibraryEditor(AbstractAssetEditor):
:param parent QWidget: parent of this widget :param parent QWidget: parent of this widget
""" """
super(LibraryEditor, self).__init__(parent) super(LibraryEditor, self).__init__(AssetType.LIBRARY, parent)
self.setObjectName(self.__class__.__name__) self.setObjectName(self.__class__.__name__)
self.set_title(self.tr("Library")) self.set_title(self.tr("Library"))
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
# # # #
############################################################################### ###############################################################################
from ..backend.assetmodel import AssetType
from ..utils import frozen from ..utils import frozen
from .editor import AbstractAssetEditor from .editor import AbstractAssetEditor
...@@ -31,7 +32,7 @@ from .editor import AbstractAssetEditor ...@@ -31,7 +32,7 @@ from .editor import AbstractAssetEditor
@frozen @frozen
class PlotterEditor(AbstractAssetEditor): class PlotterEditor(AbstractAssetEditor):
def __init__(self, parent=None): def __init__(self, parent=None):
super(PlotterEditor, self).__init__(parent) super(PlotterEditor, self).__init__(AssetType.PLOTTER, parent)
self.setObjectName(self.__class__.__name__) self.setObjectName(self.__class__.__name__)
self.set_title(self.tr("Plotter")) self.set_title(self.tr("Plotter"))
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
# # # #
############################################################################### ###############################################################################
from ..backend.assetmodel import AssetType
from ..utils import frozen from ..utils import frozen
from .editor import AbstractAssetEditor from .editor import AbstractAssetEditor
...@@ -31,7 +32,9 @@ from .editor import AbstractAssetEditor ...@@ -31,7 +32,9 @@ from .editor import AbstractAssetEditor
@frozen @frozen
class PlotterParametersEditor(AbstractAssetEditor): class PlotterParametersEditor(AbstractAssetEditor):
def __init__(self, parent=None): def __init__(self, parent=None):
super(PlotterParametersEditor, self).__init__(parent) super(PlotterParametersEditor, self).__init__(
AssetType.PLOTTERPARAMETERS, parent
)
self.setObjectName(self.__class__.__name__) self.setObjectName(self.__class__.__name__)
self.set_title(self.tr("Plotter Parameters")) self.set_title(self.tr("Plotter Parameters"))
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
# # # #
############################################################################### ###############################################################################
from ..backend.assetmodel import AssetType
from ..utils import frozen from ..utils import frozen
from .editor import AbstractAssetEditor from .editor import AbstractAssetEditor
...@@ -31,7 +32,7 @@ from .editor import AbstractAssetEditor ...@@ -31,7 +32,7 @@ from .editor import AbstractAssetEditor
@frozen @frozen
class ToolchainEditor(AbstractAssetEditor): class ToolchainEditor(AbstractAssetEditor):
def __init__(self, parent=None): def __init__(self, parent=None):
super(ToolchainEditor, self).__init__(parent) super(ToolchainEditor, self).__init__(AssetType.TOOLCHAIN, parent)
self.setObjectName(self.__class__.__name__) self.setObjectName(self.__class__.__name__)
self.set_title(self.tr("Toolchain")) self.set_title(self.tr("Toolchain"))
......
Supports Markdown
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