Commit 0d90f83e authored by Flavio TARSETTI's avatar Flavio TARSETTI
Browse files

[widgets][toolchaineditor] adding colors for blocks/connection channels

parent 180d795e
...@@ -16,6 +16,9 @@ ...@@ -16,6 +16,9 @@
"pin_font_size": 10, "pin_font_size": 10,
"pin_color": [255, 155, 0, 255], "pin_color": [255, 155, 0, 255],
"background_color": [80, 80, 80, 255], "background_color": [80, 80, 80, 255],
"background_color_datasets": [255, 254, 200, 255],
"background_color_blocks": [204, 204, 204, 255],
"background_color_analyzers": [136, 150, 216, 255],
"border_color": [50, 50, 50, 255], "border_color": [50, 50, 50, 255],
"selection_border_color": [170, 80, 80, 255], "selection_border_color": [170, 80, 80, 255],
"text_color": [0, 0, 0, 255] "text_color": [0, 0, 0, 255]
......
...@@ -143,7 +143,7 @@ class OutputPin(BasePin): ...@@ -143,7 +143,7 @@ class OutputPin(BasePin):
class Connection(QGraphicsPathItem): class Connection(QGraphicsPathItem):
def __init__(self, toolchain, connection_details, style): def __init__(self, toolchain, connection_details, style, channel_colors):
super().__init__() super().__init__()
...@@ -153,6 +153,13 @@ class Connection(QGraphicsPathItem): ...@@ -153,6 +153,13 @@ class Connection(QGraphicsPathItem):
self.end_pin_name = connection_details["to"].split(".")[1] self.end_pin_name = connection_details["to"].split(".")[1]
self.channel = connection_details["channel"] self.channel = connection_details["channel"]
hexadecimal = channel_colors[self.channel].lstrip("#")
hlen = len(hexadecimal)
self.connection_color = list(
int(hexadecimal[i : i + hlen // 3], 16) for i in range(0, hlen, hlen // 3)
)
self.connection_color.append(255)
self.blocks = toolchain.blocks self.blocks = toolchain.blocks
for block in self.blocks: for block in self.blocks:
...@@ -183,7 +190,7 @@ class Connection(QGraphicsPathItem): ...@@ -183,7 +190,7 @@ class Connection(QGraphicsPathItem):
self.color = config["color"] self.color = config["color"]
self.connection_pen = QPen() self.connection_pen = QPen()
self.connection_pen.setColor(QColor(*config["color"])) self.connection_pen.setColor(QColor(*self.connection_color))
self.connection_pen.setWidth(config["width"]) self.connection_pen.setWidth(config["width"])
def drawCubicBezierCurve(self): def drawCubicBezierCurve(self):
...@@ -320,7 +327,12 @@ class Block(QGraphicsObject): ...@@ -320,7 +327,12 @@ class Block(QGraphicsObject):
self.background_brush = QBrush() self.background_brush = QBrush()
self.background_brush.setStyle(Qt.SolidPattern) self.background_brush.setStyle(Qt.SolidPattern)
self.background_brush.setColor(QColor(*config["background_color"]))
self.background_color_datasets = QColor(*config["background_color_datasets"])
self.background_color_analyzers = QColor(*config["background_color_analyzers"])
self.background_color_blocks = QColor(*config["background_color_blocks"])
self.background_brush.setColor(self.background_color_blocks)
self.background_pen = QPen() self.background_pen = QPen()
self.background_pen.setStyle(Qt.SolidLine) self.background_pen.setStyle(Qt.SolidLine)
...@@ -422,6 +434,11 @@ class Block(QGraphicsObject): ...@@ -422,6 +434,11 @@ class Block(QGraphicsObject):
"""Paint the block""" """Paint the block"""
# Design tools # Design tools
if self.type == BlockType.DATASETS.name:
self.background_brush.setColor(self.background_color_datasets)
elif self.type == BlockType.ANALYZERS.name:
self.background_brush.setColor(self.background_color_analyzers)
painter.setBrush(self.background_brush) painter.setBrush(self.background_brush)
painter.setPen(self.border_pen) painter.setPen(self.border_pen)
...@@ -490,6 +507,7 @@ class Toolchain(QWidget): ...@@ -490,6 +507,7 @@ class Toolchain(QWidget):
self.scene.items().clear() self.scene.items().clear()
self.blocks = [] self.blocks = []
self.connections = [] self.connections = []
self.channels = []
def load(self, json_object): def load(self, json_object):
"""Parse the json in parameter and generates a graph""" """Parse the json in parameter and generates a graph"""
...@@ -501,20 +519,37 @@ class Toolchain(QWidget): ...@@ -501,20 +519,37 @@ class Toolchain(QWidget):
else: else:
self.web_representation = None self.web_representation = None
if "editor_gui" in self.json_object:
self.editor_gui = self.json_object["editor_gui"]
else:
self.editor_gui = None
self.clear_space() self.clear_space()
# Get datasets, blocks, analyzers # Get datasets, blocks, analyzers
for block_type in BlockType: for block_type in BlockType:
for block_item in self.json_object[block_type.value]: for block_item in self.json_object[block_type.value]:
block = Block(block_item, block_type.name, self.block_config) block = Block(block_item, block_type.name, self.block_config)
# Place blocks (x,y) if information is given
if self.editor_gui is not None:
if block.name in self.editor_gui:
block.setPos(
self.editor_gui[block.name]["x"],
self.editor_gui[block.name]["y"],
)
block.position = block.scenePos()
block.dataChanged.connect(self.dataChanged) block.dataChanged.connect(self.dataChanged)
self.blocks.append(block) self.blocks.append(block)
self.scene.addItem(block) self.scene.addItem(block)
# Display connections # Display connections
connections = self.json_object["connections"] connections = self.json_object["connections"]
channel_colors = self.json_object["representation"]["channel_colors"]
for connection_item in connections: for connection_item in connections:
connection = Connection(self, connection_item, self.connection_config) connection = Connection(
self, connection_item, self.connection_config, channel_colors
)
self.connections.append(connection) self.connections.append(connection)
self.scene.addItem(connection) self.scene.addItem(connection)
......
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