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

[widgets][toolchaineditor] Improve empty block menu handling

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

Part of #239
parent 243eff6d
......@@ -166,3 +166,16 @@ class TestToolchainEditor:
editor.load_json(reference_json)
assert editor.dump_json() == reference_json
def test_empty_block_list(self, qtbot):
editor = ToolchainEditor()
actions = editor.toolchain.analyzer_edit_menu.actions()
assert len(actions) == 1
assert actions[0].text() == "No valid analyzers found"
actions = editor.toolchain.block_edit_menu.actions()
assert len(actions) == 1
assert actions[0].text() == "No valid blocks found"
actions = editor.toolchain.dataset_edit_menu.actions()
assert len(actions) == 1
assert actions[0].text() == "No valid datasets found"
......@@ -763,6 +763,9 @@ class BlockType(Enum):
raise KeyError("{} is not a valid block type".format(name))
BLOCKTYPE_PROPERTY = "__block_type__"
class Block(QGraphicsObject):
"""Block item"""
......@@ -1446,16 +1449,19 @@ class ToolchainWidget(QWidget):
self.dataset_button.setToolTip("Dataset")
self.dataset_button.setIcon(QIcon(":/resources/dataset"))
self.dataset_edit_menu = QMenu(self)
self.dataset_edit_menu.setProperty(BLOCKTYPE_PROPERTY, BlockType.DATASETS)
self.block_button = QPushButton()
self.block_button.setToolTip("Block")
self.block_button.setIcon(QIcon(":/resources/block"))
self.block_edit_menu = QMenu(self)
self.block_edit_menu.setProperty(BLOCKTYPE_PROPERTY, BlockType.BLOCKS)
self.analyzer_button = QPushButton()
self.analyzer_button.setToolTip("Analyzer")
self.analyzer_button.setIcon(QIcon(":/resources/analyzer"))
self.analyzer_edit_menu = QMenu(self)
self.analyzer_edit_menu.setProperty(BLOCKTYPE_PROPERTY, BlockType.ANALYZERS)
self.toolbar.addWidget(self.dataset_button)
self.toolbar.addWidget(self.block_button)
......@@ -1468,6 +1474,27 @@ class ToolchainWidget(QWidget):
layout.addWidget(self.toolbar)
layout.addWidget(self.view)
for menu in [
self.dataset_edit_menu,
self.block_edit_menu,
self.analyzer_edit_menu,
]:
self.__setup_menu(menu, [])
def __setup_menu(self, menu, item_list):
menu.clear()
block_type = menu.property(BLOCKTYPE_PROPERTY)
if item_list:
for item in item_list:
menu.addAction(
item, partial(self.button_item_selected, block_type, item)
)
else:
action = menu.addAction(
self.tr("No valid {} found".format(block_type.name.lower()))
)
action.setEnabled(False)
def add_loop_block(self):
loops, ok = LoopDialog.getLoops(
self,
......@@ -1601,7 +1628,7 @@ class ToolchainWidget(QWidget):
inputs = []
outputs = []
if block_type == BlockType.DATASETS.name:
if block_type == BlockType.DATASETS:
inputs = None
name_split = name.split("/")
database_name = name_split[0] + "/" + name_split[1]
......@@ -1624,7 +1651,7 @@ class ToolchainWidget(QWidget):
outputs.append(key)
else:
if block_type == BlockType.ANALYZERS.name:
if block_type == BlockType.ANALYZERS:
outputs = None
asset = Asset(self.prefix_path, AssetType.ALGORITHM, name)
declaration = asset.declaration
......@@ -1671,29 +1698,12 @@ class ToolchainWidget(QWidget):
):
self.prefix_path = prefix_path
for dataset_name in dataset_list:
self.dataset_edit_menu.addAction(
self.tr(dataset_name),
partial(
self.button_item_selected, BlockType.DATASETS.name, dataset_name
),
)
for algorithm_name in algorithm_list:
self.block_edit_menu.addAction(
self.tr(algorithm_name),
partial(
self.button_item_selected, BlockType.BLOCKS.name, algorithm_name
),
)
for analyzer_name in analyzer_list:
self.analyzer_edit_menu.addAction(
self.tr(analyzer_name),
partial(
self.button_item_selected, BlockType.ANALYZERS.name, analyzer_name
),
)
for menu, item_list in [
(self.dataset_edit_menu, dataset_list),
(self.block_edit_menu, algorithm_list),
(self.analyzer_edit_menu, analyzer_list),
]:
self.__setup_menu(menu, item_list)
self.dataset_button.setMenu(self.dataset_edit_menu)
self.block_button.setMenu(self.block_edit_menu)
......
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