Commit b19fcb04 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[widgets][toolchaineditor] Improve empty loop block dialog

If any of the list shall be empty, set an disabled item stating that
nothing valid is found. This is better than the currently empty dialog.

Part of #239
parent f5cc3c39
Pipeline #40197 passed with stage
in 7 minutes and 12 seconds
......@@ -34,6 +34,7 @@ from ..backend.asset import Asset
from ..backend.asset import AssetType
from ..backend.assetmodel import AssetModel
from ..widgets.toolchaineditor import BlockType
from ..widgets.toolchaineditor import LoopWidget
from ..widgets.toolchaineditor import ToolchainEditor
from ..widgets.toolchaineditor import ToolchainView
from ..widgets.toolchainscene import ToolchainScene
......@@ -154,6 +155,22 @@ class TestBlockType:
assert "{} is not a valid block type".format(name) in str(excinfo.value)
class TestLoopWidget:
"""Test that the LoopWidget works correctly"""
def test_empty_block_list(self, qtbot, beat_context):
widget = LoopWidget()
for listwidget in [
widget.sequential_loop_processor_listwidget,
widget.autonomous_loop_processor_listwidget,
widget.sequential_loop_evaluator_listwidget,
widget.sequential_loop_evaluator_listwidget,
]:
assert listwidget.count() == 1
assert listwidget.item(0).text() == "No valid algorithm found"
class TestToolchainEditor:
"""Test that the mock editor works correctly"""
......
......@@ -56,6 +56,7 @@ from PyQt5.QtWidgets import QHBoxLayout
from PyQt5.QtWidgets import QLabel
from PyQt5.QtWidgets import QLineEdit
from PyQt5.QtWidgets import QListWidget
from PyQt5.QtWidgets import QListWidgetItem
from PyQt5.QtWidgets import QMenu
from PyQt5.QtWidgets import QMessageBox
from PyQt5.QtWidgets import QPushButton
......@@ -454,6 +455,7 @@ class LoopWidget(QDialog):
"""Class holder for the various libraries"""
dataChanged = pyqtSignal()
selectionChanged = pyqtSignal()
def __init__(self, parent=None):
"""Constructor"""
......@@ -470,60 +472,57 @@ class LoopWidget(QDialog):
self.sequential_loop_evaluator_listwidget = QListWidget()
self.autonomous_loop_evaluator_listwidget = QListWidget()
# QVBoxLayout for available lists
sequential_loop_processor_listwidget_layout = QVBoxLayout()
sequential_loop_processor_listwidget_layout.addWidget(
QLabel(self.tr("Sequential Loop Processor"))
)
sequential_loop_processor_listwidget_layout.addWidget(
self.sequential_loop_processor_listwidget
)
autonomous_loop_processor_listwidget_layout = QVBoxLayout()
autonomous_loop_processor_listwidget_layout.addWidget(
QLabel(self.tr("Autonomous Loop Processor"))
)
autonomous_loop_processor_listwidget_layout.addWidget(
self.autonomous_loop_processor_listwidget
)
for listwidget, title in [
(
self.sequential_loop_processor_listwidget,
self.tr("Sequential Loop Processor"),
),
(
self.autonomous_loop_processor_listwidget,
self.tr("Autonomous Loop Processor"),
),
(
self.sequential_loop_evaluator_listwidget,
self.tr("Sequential Loop Evaluator"),
),
(
self.autonomous_loop_evaluator_listwidget,
self.tr("Autonomous Loop Evaluator"),
),
]:
vbox_layout = QVBoxLayout()
vbox_layout.addWidget(QLabel(title))
vbox_layout.addWidget(listwidget)
layout.addLayout(vbox_layout)
sequential_loop_evaluator_listwidget_layout = QVBoxLayout()
sequential_loop_evaluator_listwidget_layout.addWidget(
QLabel(self.tr("Sequential Loop Evaluator"))
)
sequential_loop_evaluator_listwidget_layout.addWidget(
self.sequential_loop_evaluator_listwidget
)
self._setup_listwidget(listwidget, [])
autonomous_loop_evaluator_listwidget_layout = QVBoxLayout()
autonomous_loop_evaluator_listwidget_layout.addWidget(
QLabel(self.tr("Autonomous Loop Evaluator"))
)
autonomous_loop_evaluator_listwidget_layout.addWidget(
self.autonomous_loop_evaluator_listwidget
)
listwidget.itemSelectionChanged.connect(self.selectionChanged)
# Layouts Design
layout.addLayout(sequential_loop_processor_listwidget_layout)
layout.addLayout(autonomous_loop_processor_listwidget_layout)
layout.addLayout(sequential_loop_evaluator_listwidget_layout)
layout.addLayout(autonomous_loop_evaluator_listwidget_layout)
def _setup_listwidget(self, listwidget, algorithms):
listwidget.clear()
if algorithms:
listwidget.addItems(algorithms)
else:
invalid_item = QListWidgetItem(self.tr("No valid algorithm found"))
invalid_item.setFlags(Qt.NoItemFlags)
listwidget.addItem(invalid_item)
def set_sequential_loop_processor_list(self, _list):
self.sequential_loop_processor_list = _list
self.sequential_loop_processor_listwidget.addItems(_list)
def set_sequential_loop_processor_list(self, algorithms):
self.sequential_loop_processor_list = algorithms
self._setup_listwidget(self.sequential_loop_processor_listwidget, algorithms)
def set_autonomous_loop_processor_list(self, _list):
self.autonomous_loop_processor_list = _list
self.autonomous_loop_processor_listwidget.addItems(_list)
def set_autonomous_loop_processor_list(self, algorithms):
self.autonomous_loop_processor_list = algorithms
self._setup_listwidget(self.autonomous_loop_processor_listwidget, algorithms)
def set_sequential_loop_evaluator_list(self, _list):
self.sequential_loop_evaluator_list = _list
self.sequential_loop_evaluator_listwidget.addItems(_list)
def set_sequential_loop_evaluator_list(self, algorithms):
self.sequential_loop_evaluator_list = algorithms
self._setup_listwidget(self.sequential_loop_evaluator_listwidget, algorithms)
def set_autonomous_loop_evaluator_list(self, _list):
self.autonomous_loop_evaluator_list = _list
self.autonomous_loop_evaluator_listwidget.addItems(_list)
def set_autonomous_loop_evaluator_list(self, algorithms):
self.sequential_loop_evaluator_list = algorithms
self._setup_listwidget(self.autonomous_loop_evaluator_listwidget, algorithms)
def get_processor_evaluator_loops(self):
selected_loops = {}
......@@ -588,12 +587,18 @@ class LoopDialog(QDialog):
self.buttons = QDialogButtonBox(
QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Horizontal, self
)
self.buttons.button(QDialogButtonBox.Ok).setEnabled(False)
layout.addWidget(self.buttons)
# Signals/Slots connection
self.buttons.accepted.connect(self.accept)
self.buttons.rejected.connect(self.reject)
self.loop_widget.selectionChanged.connect(self.__updateUi)
@pyqtSlot()
def __updateUi(self):
loops_dict = self.value()
self.buttons.button(QDialogButtonBox.Ok).setEnabled(all(loops_dict.values()))
def value(self):
"""Returns the value selected"""
......
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