Commit fbc0ff83 authored by Samuel GAIST's avatar Samuel GAIST

[widgets][assetwidget] Allow loading of invalid asset

This will allow loading of unfinished experiments.

The editor tab will show an icon when dealing with
invalid asset content.
parent 83946657
......@@ -31,6 +31,8 @@ from PyQt5.QtCore import pyqtSlot
from PyQt5.QtCore import QFileSystemWatcher
from PyQt5.QtCore import QTimer
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QLabel
from PyQt5.QtWidgets import QMenu
from PyQt5.QtWidgets import QPushButton
......@@ -41,6 +43,7 @@ from PyQt5.QtWidgets import QHBoxLayout
from PyQt5.QtWidgets import QWidget
from PyQt5.QtWidgets import QStackedWidget
from PyQt5.QtWidgets import QMessageBox
from PyQt5.QtWidgets import QStyle
from ..backend.asset import AssetType
from ..backend.asset import Asset
......@@ -226,6 +229,15 @@ class AssetWidget(QWidget):
self.asset_name_label.setText(self.current_asset.name)
self.save_button.setEnabled(False)
def __update_editors_icon(self, is_valid):
tab_index = self.tab_widget.indexOf(self.editors)
tab_icon = (
self.style().standardIcon(QStyle.SP_MessageBoxCritical)
if not is_valid
else QIcon()
)
self.tab_widget.setTabIcon(tab_index, tab_icon)
def __clear_watcher(self):
"""Clears the content of the file system watcher"""
......@@ -397,13 +409,28 @@ class AssetWidget(QWidget):
self.__clear_watcher()
is_valid, errors = asset.is_valid()
do_load = False
if not is_valid:
QMessageBox.critical(
self,
message_box = QMessageBox(
QMessageBox.Critical,
self.tr("Invalid asset"),
self.tr(f"The asset you are trying to load is invalid\n{errors}"),
self.tr(f"The asset you are trying to load is invalid."),
)
message_box.setDetailedText(f"{errors}")
message_box.addButton(QMessageBox.Cancel)
load_button = message_box.addButton(QMessageBox.Ignore)
load_button.setText(self.tr("Load anyway"))
result = message_box.exec_()
do_load = result == QMessageBox.Ignore
else:
do_load = True
if do_load:
self.__update_editors_icon(is_valid)
declaration = asset.declaration
if asset.type == AssetType.ALGORITHM:
if declaration.get("api_version", 0) < 2:
......@@ -455,6 +482,9 @@ class AssetWidget(QWidget):
with FileBlocker(self.watcher, declaration_path):
self.current_asset.declaration = original
is_valid, _ = self.current_asset.is_valid()
self.__update_editors_icon(is_valid)
if self.current_asset.type == AssetType.ALGORITHM:
update_code(self.current_asset)
......
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