Commit 3d44bde1 authored by Flavio TARSETTI's avatar Flavio TARSETTI

[widgets][toolchaineditor] datasets color picker and channel color update

parent 707241b7
......@@ -60,6 +60,7 @@ from PyQt5.QtWidgets import QPushButton
from PyQt5.QtWidgets import QMenu
from PyQt5.QtWidgets import QLineEdit
from PyQt5.QtWidgets import QMessageBox
from PyQt5.QtWidgets import QColorDialog
from ..backend.asset import Asset
from ..backend.asset import AssetType
......@@ -395,6 +396,7 @@ class BlockEditionDialog(QDialog):
toolchain = block.toolchain
self.setWindowTitle(self.tr("Block Edition"))
self.name_lineedit = QLineEdit(block.name)
self.color = "#000000"
self.channel_combobox = QComboBox()
no_channel_label = QLabel(self.tr("No input connections yet!"))
no_dataset_channel_label = QLabel(self.tr("No synchronization for datasets"))
......@@ -403,8 +405,13 @@ class BlockEditionDialog(QDialog):
layout.addRow(self.tr("Name:"), self.name_lineedit)
channels = []
if block.type == BlockType.DATASETS.name:
channel_color_button = QPushButton("Channel color", self)
channel_color_button.setToolTip("Opens color dialog")
channel_color_button.clicked.connect(self.on_color_click)
layout.addRow(self.tr("Channel:"), no_dataset_channel_label)
layout.addRow(self.tr("Channel color:"), channel_color_button)
elif block.synchronized_channel is None:
layout.addRow(self.tr("Channel:"), no_channel_label)
else:
......@@ -432,12 +439,23 @@ class BlockEditionDialog(QDialog):
self.buttons.accepted.connect(self.accept)
self.buttons.rejected.connect(self.reject)
@pyqtSlot()
def on_color_click(self):
self.colorDialog()
def colorDialog(self):
color = QColorDialog.getColor()
if color.isValid():
self.color = color.name().capitalize()
def value(self):
"""Returns the value selected"""
return {
"name": self.name_lineedit.text(),
"channel": self.channel_combobox.currentText(),
"color": self.color,
}
@staticmethod
......@@ -715,6 +733,11 @@ class Block(QGraphicsObject):
):
self.synchronized_channel = value["channel"]
block_updated = True
if self.type == BlockType.DATASETS.name:
self.toolchain.web_representation["channel_colors"][self.name] = value[
"color"
]
block_updated = True
if block_updated:
# Update blocks
......@@ -751,6 +774,27 @@ class Block(QGraphicsObject):
if connection.channel == old_name:
connection.channel = self.name
# color update
self.toolchain.scene.removeItem(connection)
# Find the corresponding channel
connection_settings = {}
connection_settings["channel"] = connection.channel
# Create the connection
connection_settings["from"] = (
connection.start_block_name + "." + connection.start_pin_name
)
connection_settings["to"] = (
connection.end_block_name + "." + connection.end_pin_name
)
channel_colors = self.toolchain.json_object.get(
"representation", {}
).get("channel_colors")
connection.load(self.toolchain, connection_settings, channel_colors)
self.toolchain.scene.addItem(connection)
# Complete toolchain channel update from current block
if old_channel != self.synchronized_channel:
self.toolchain.update_channel_path(
......
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