Commit f3146ffc authored by Flavio TARSETTI's avatar Flavio TARSETTI

[widgets][toolchaineditor] delete non-connected blocks

parent 1f7a04ff
...@@ -59,6 +59,7 @@ from PyQt5.QtWidgets import QComboBox ...@@ -59,6 +59,7 @@ from PyQt5.QtWidgets import QComboBox
from PyQt5.QtWidgets import QPushButton from PyQt5.QtWidgets import QPushButton
from PyQt5.QtWidgets import QMenu from PyQt5.QtWidgets import QMenu
from PyQt5.QtWidgets import QLineEdit from PyQt5.QtWidgets import QLineEdit
from PyQt5.QtWidgets import QMessageBox
from ..backend.asset import Asset from ..backend.asset import Asset
from ..backend.asset import AssetType from ..backend.asset import AssetType
...@@ -862,6 +863,8 @@ class ToolchainView(QGraphicsView): ...@@ -862,6 +863,8 @@ class ToolchainView(QGraphicsView):
"""Focus on the toolchain when F key pressed""" """Focus on the toolchain when F key pressed"""
if event.key() == Qt.Key_F: if event.key() == Qt.Key_F:
self.custom_focus() self.custom_focus()
if event.key() == Qt.Key_D:
self.delete_blocks()
def custom_focus(self): def custom_focus(self):
"""Custom focus on toolchain""" """Custom focus on toolchain"""
...@@ -888,6 +891,44 @@ class ToolchainView(QGraphicsView): ...@@ -888,6 +891,44 @@ class ToolchainView(QGraphicsView):
self.fitInView(toolchain_focus, Qt.KeepAspectRatio) self.fitInView(toolchain_focus, Qt.KeepAspectRatio)
def delete_blocks(self):
"""Custom deletion on toolchain"""
selected_blocks = self.scene().selectedItems()
if selected_blocks:
details = {}
for block in selected_blocks:
num_connections = 0
for connection in self.toolchain.connections:
if (
block.name == connection.start_block_name
or block.name == connection.end_block_name
):
num_connections += 1
if num_connections > 0:
details["block"] = num_connections
if len(details.keys()):
warning = QMessageBox()
warning.setIcon(QMessageBox.Warning)
warning.setWindowTitle(self.tr("Deleting connected block"))
warning.setInformativeText(
self.tr("You can't delete a connected block!")
)
warning.setStandardButtons(QMessageBox.Ok)
warning.exec_()
else:
for block in selected_blocks:
if block.type == BlockType.DATASETS.name:
if (
block.name
in self.toolchain.web_representation["channel_colors"]
):
self.toolchain.web_representation["channel_colors"].pop(
block.name
)
self.toolchain.blocks.remove(block)
self.scene().removeItem(block)
self.toolchain.dataChanged.emit()
class Toolchain(QWidget): class Toolchain(QWidget):
"""Toolchain designer""" """Toolchain designer"""
......
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