Commit 88276d59 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[widgets][dialogs] Add support to create new experiment

parent 66b47f8d
......@@ -77,6 +77,11 @@ class AssetType(Enum):
return self not in [self.UNKNOWN, self.EXPERIMENT]
def has_versions(self):
"""Returns whether a new version of this asset can be created"""
return self not in [self.UNKNOWN, self.EXPERIMENT]
def can_fork(self):
"""Returns whether a new asset can be forked"""
......
......@@ -40,8 +40,7 @@ class TestAssetCreationDialog:
dialog.show()
qtbot.addWidget(dialog)
assert dialog.new_radio_button.isVisible() == asset_type.can_create()
assert dialog.new_version_radio_button.isVisible() == asset_type.can_create()
assert dialog.new_version_radio_button.isVisible() == asset_type.has_versions()
assert dialog.fork_radio_button.isVisible() == asset_type.can_fork()
def test_input_disabling(self, qtbot, beat_context):
......@@ -83,10 +82,15 @@ class TestAssetCreationDialog:
)
assert dialog.creationType() == AssetCreationDialog.NEW
assert dialog.assetInfo() == asset_name
if asset_type == AssetType.EXPERIMENT:
asset_info = dialog.assetInfo()
assert isinstance(asset_info, tuple)
assert asset_info[1] == asset_name
else:
assert dialog.assetInfo() == asset_name
@pytest.mark.parametrize(
"asset_type", [item for item in AssetType if item.can_create()]
"asset_type", [item for item in AssetType if item.has_versions()]
)
def test_create_new_version(self, qtbot, beat_context, asset_type):
dialog = AssetCreationDialog(beat_context, asset_type)
......
......@@ -23,6 +23,8 @@
# #
###############################################################################
import os
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtCore import QCoreApplication
......@@ -64,6 +66,8 @@ class AssetCreationDialog(QDialog, CreationType):
def __init__(self, context, asset_type, parent=None):
super().__init__(parent)
self.asset_type = asset_type
config = context.meta["config"]
user = config.user
prefix_path = config.path
......@@ -88,6 +92,13 @@ class AssetCreationDialog(QDialog, CreationType):
self.name_lineedit = QLineEdit()
self.new_radio_button = QRadioButton(self.tr("New"))
self.new_radio_button.setChecked(True)
self.toolchain_combobox = None
if asset_type == AssetType.EXPERIMENT:
self.toolchain_combobox = QComboBox()
toolchain_model = AssetModel()
toolchain_model.asset_type = AssetType.TOOLCHAIN
toolchain_model.prefix_path = prefix_path
self.toolchain_combobox.setModel(toolchain_model)
# New version
self.new_version_combobox = QComboBox()
......@@ -117,9 +128,13 @@ class AssetCreationDialog(QDialog, CreationType):
fork_layout.addWidget(self.fork_lineedit)
form_layout = QFormLayout(self)
if asset_type.can_create():
form_layout.addRow(self.new_radio_button, self.name_lineedit)
form_layout.addRow(self.new_radio_button, self.name_lineedit)
if asset_type == AssetType.EXPERIMENT:
form_layout.addRow(self.tr("Toolchain"), self.toolchain_combobox)
if asset_type.has_versions():
form_layout.addRow(self.new_version_radio_button, self.new_version_combobox)
if asset_type.can_fork():
form_layout.addRow(self.fork_radio_button, fork_layout)
......@@ -127,6 +142,9 @@ class AssetCreationDialog(QDialog, CreationType):
self.name_lineedit.textChanged.connect(self.__validateName)
self.new_radio_button.toggled.connect(self.name_lineedit.setEnabled)
if asset_type == AssetType.EXPERIMENT:
self.new_radio_button.toggled.connect(self.toolchain_combobox.setEnabled)
self.toolchain_combobox.currentIndexChanged.connect(self.__updateUi)
self.new_radio_button.toggled.connect(self.__updateUi)
self.fork_lineedit.textChanged.connect(self.__validateName)
......@@ -156,7 +174,14 @@ class AssetCreationDialog(QDialog, CreationType):
ok_button = self.buttonbox.button(QDialogButtonBox.Ok)
if name:
used_names = [asset.split("/")[-2] for asset in self.fork_asset_list]
if self.asset_type == AssetType.EXPERIMENT:
name = os.path.join(self.toolchain_combobox.currentText(), name)
used_names = [
asset[asset.find("/") + 1 :] for asset in self.fork_asset_list
]
else:
used_names = [asset.split("/")[-2] for asset in self.fork_asset_list]
ok_button.setEnabled(name not in used_names)
else:
ok_button.setEnabled(False)
......@@ -172,6 +197,11 @@ class AssetCreationDialog(QDialog, CreationType):
def assetInfo(self):
if self.isNew():
if self.asset_type == AssetType.EXPERIMENT:
return (
self.toolchain_combobox.currentText(),
self.name_lineedit.text(),
)
return self.name_lineedit.text()
elif self.isNewVersion():
return self.new_version_combobox.currentText()
......
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