Skip to content
Snippets Groups Projects
Commit 8829dcd0 authored by Oscar Gustafsson's avatar Oscar Gustafsson :bicyclist:
Browse files

Add active color for port and wider active signals

parent b15cb17f
No related branches found
No related tags found
1 merge request!331Add active color for port and wider active signals
Pipeline #96254 passed
from qtpy.QtGui import QColor from qtpy.QtGui import QColor
from b_asic._preferences import ( from b_asic._preferences import EXECUTION_TIME_COLOR, LATENCY_COLOR, SIGNAL_COLOR
EXECUTION_TIME_COLOR,
LATENCY_COLOR,
SIGNAL_COLOR,
)
SIGNAL_INACTIVE = QColor(*SIGNAL_COLOR) SIGNAL_INACTIVE = QColor(*SIGNAL_COLOR)
SIGNAL_ACTIVE = QColor(0, 207, 181) SIGNAL_ACTIVE = QColor(0, 207, 181)
SIGNAL_WIDTH = 0.03 SIGNAL_WIDTH = 0.03
SIGNAL_WIDTH_ACTIVE = 0.05
OPERATION_LATENCY_INACTIVE = QColor(*LATENCY_COLOR) OPERATION_LATENCY_INACTIVE = QColor(*LATENCY_COLOR)
OPERATION_LATENCY_ACTIVE = QColor(0, 207, 181) OPERATION_LATENCY_ACTIVE = QColor(0, 207, 181)
...@@ -16,8 +13,6 @@ OPERATION_EXECUTION_TIME_INACTIVE = QColor(*EXECUTION_TIME_COLOR) ...@@ -16,8 +13,6 @@ OPERATION_EXECUTION_TIME_INACTIVE = QColor(*EXECUTION_TIME_COLOR)
OPERATION_EXECUTION_TIME_ACTIVE = QColor(*EXECUTION_TIME_COLOR) OPERATION_EXECUTION_TIME_ACTIVE = QColor(*EXECUTION_TIME_COLOR)
OPERATION_HEIGHT = 0.75 OPERATION_HEIGHT = 0.75
OPERATION_GAP = ( OPERATION_GAP = 1 - OPERATION_HEIGHT # TODO: For now, should really fix the bug
1 - OPERATION_HEIGHT
) # TODO: For now, should really fix the bug
SCHEDULE_INDENT = 0.2 SCHEDULE_INDENT = 0.2
...@@ -89,6 +89,14 @@ class OperationItem(QGraphicsItemGroup): ...@@ -89,6 +89,14 @@ class OperationItem(QGraphicsItemGroup):
QCursor(Qt.CursorShape.OpenHandCursor) QCursor(Qt.CursorShape.OpenHandCursor)
) # default cursor when hovering over object ) # default cursor when hovering over object
self._port_filling_brush = QBrush(Qt.GlobalColor.black)
self._port_outline_pen = QPen(Qt.GlobalColor.black)
self._port_outline_pen.setWidthF(0)
self._port_filling_brush_active = QBrush(OPERATION_LATENCY_ACTIVE)
self._port_outline_pen_active = QPen(OPERATION_LATENCY_ACTIVE)
self._port_outline_pen_active.setWidthF(0)
self._make_component() self._make_component()
# def sceneEvent(self, event: QEvent) -> bool: # def sceneEvent(self, event: QEvent) -> bool:
...@@ -171,6 +179,16 @@ class OperationItem(QGraphicsItemGroup): ...@@ -171,6 +179,16 @@ class OperationItem(QGraphicsItemGroup):
self._set_background(OPERATION_LATENCY_INACTIVE) self._set_background(OPERATION_LATENCY_INACTIVE)
self.setCursor(QCursor(Qt.CursorShape.OpenHandCursor)) self.setCursor(QCursor(Qt.CursorShape.OpenHandCursor))
def set_port_active(self, key: str):
item = self._ports[key]["item"]
item.setBrush(self._port_filling_brush_active)
item.setPen(self._port_outline_pen_active)
def set_port_inactive(self, key: str):
item = self._ports[key]["item"]
item.setBrush(self._port_filling_brush)
item.setPen(self._port_outline_pen)
def _set_background(self, color: QColor) -> None: def _set_background(self, color: QColor) -> None:
brush = QBrush(color) brush = QBrush(color)
self._latency_item.setBrush(brush) self._latency_item.setBrush(brush)
...@@ -185,10 +203,6 @@ class OperationItem(QGraphicsItemGroup): ...@@ -185,10 +203,6 @@ class OperationItem(QGraphicsItemGroup):
Qt.RoundJoin Qt.RoundJoin
) # Qt.MiterJoin, Qt.BevelJoin (default), Qt.RoundJoin, Qt.SvgMiterJoin ) # Qt.MiterJoin, Qt.BevelJoin (default), Qt.RoundJoin, Qt.SvgMiterJoin
port_filling_brush = QBrush(Qt.GlobalColor.black) # used by port filling
port_outline_pen = QPen(Qt.GlobalColor.black) # used by port outline
port_outline_pen.setWidthF(0)
# port_outline_pen.setCosmetic(True)
port_size = 7 / self._scale # the diameter of a port port_size = 7 / self._scale # the diameter of a port
execution_time_color = QColor(OPERATION_EXECUTION_TIME_INACTIVE) execution_time_color = QColor(OPERATION_EXECUTION_TIME_INACTIVE)
...@@ -230,10 +244,10 @@ class OperationItem(QGraphicsItemGroup): ...@@ -230,10 +244,10 @@ class OperationItem(QGraphicsItemGroup):
new_port = QGraphicsEllipseItem( new_port = QGraphicsEllipseItem(
-port_size / 2, -port_size / 2, port_size, port_size -port_size / 2, -port_size / 2, port_size, port_size
) )
new_port.setPen(port_outline_pen) new_port.setPen(self._port_outline_pen)
new_port.setBrush(port_filling_brush) new_port.setBrush(self._port_filling_brush)
new_port.setPos(port_pos.x(), port_pos.y()) new_port.setPos(port_pos.x(), port_pos.y())
self._port_items.append(new_port) self._ports[key]["item"] = new_port
create_ports(self._operation.get_input_coordinates(), "in") create_ports(self._operation.get_input_coordinates(), "in")
create_ports(self._operation.get_output_coordinates(), "out") create_ports(self._operation.get_output_coordinates(), "out")
...@@ -247,8 +261,8 @@ class OperationItem(QGraphicsItemGroup): ...@@ -247,8 +261,8 @@ class OperationItem(QGraphicsItemGroup):
# item group, consist of component_item, port_items and execution_time_item # item group, consist of component_item, port_items and execution_time_item
self.addToGroup(self._latency_item) self.addToGroup(self._latency_item)
for port in self._port_items: for port in self._ports.values():
self.addToGroup(port) self.addToGroup(port["item"])
self.addToGroup(self._label_item) self.addToGroup(self._label_item)
if execution_time: if execution_time:
self.addToGroup(self._execution_time_item) self.addToGroup(self._execution_time_item)
......
...@@ -18,6 +18,7 @@ from b_asic.scheduler_gui._preferences import ( ...@@ -18,6 +18,7 @@ from b_asic.scheduler_gui._preferences import (
SIGNAL_ACTIVE, SIGNAL_ACTIVE,
SIGNAL_INACTIVE, SIGNAL_INACTIVE,
SIGNAL_WIDTH, SIGNAL_WIDTH,
SIGNAL_WIDTH_ACTIVE,
) )
from b_asic.scheduler_gui.operation_item import OperationItem from b_asic.scheduler_gui.operation_item import OperationItem
from b_asic.signal import Signal from b_asic.signal import Signal
...@@ -59,6 +60,8 @@ class SignalItem(QGraphicsPathItem): ...@@ -59,6 +60,8 @@ class SignalItem(QGraphicsPathItem):
self._src_operation = src_operation self._src_operation = src_operation
self._dest_operation = dest_operation self._dest_operation = dest_operation
self._signal = signal self._signal = signal
self._src_key = f"out{self._signal.source.index}"
self._dest_key = f"in{self._signal.destination.index}"
self._refresh_pens() self._refresh_pens()
self.set_inactive() self.set_inactive()
self.update_path() self.update_path()
...@@ -67,12 +70,8 @@ class SignalItem(QGraphicsPathItem): ...@@ -67,12 +70,8 @@ class SignalItem(QGraphicsPathItem):
""" """
Create a new path after moving connected operations. Create a new path after moving connected operations.
""" """
source_point = self._src_operation.get_port_location( source_point = self._src_operation.get_port_location(self._src_key)
f"out{self._signal.source.index}" dest_point = self._dest_operation.get_port_location(self._dest_key)
)
dest_point = self._dest_operation.get_port_location(
f"in{self._signal.destination.index}"
)
path = QPainterPath() path = QPainterPath()
path.moveTo(source_point) path.moveTo(source_point)
source_x = source_point.x() source_x = source_point.x()
...@@ -100,7 +99,7 @@ class SignalItem(QGraphicsPathItem): ...@@ -100,7 +99,7 @@ class SignalItem(QGraphicsPathItem):
def _refresh_pens(self) -> None: def _refresh_pens(self) -> None:
"""Create pens.""" """Create pens."""
pen = QPen(SIGNAL_ACTIVE) pen = QPen(SIGNAL_ACTIVE)
pen.setWidthF(SIGNAL_WIDTH) pen.setWidthF(SIGNAL_WIDTH_ACTIVE)
self._active_pen = pen self._active_pen = pen
pen = QPen(SIGNAL_INACTIVE) pen = QPen(SIGNAL_INACTIVE)
pen.setWidthF(SIGNAL_WIDTH) pen.setWidthF(SIGNAL_WIDTH)
...@@ -111,7 +110,11 @@ class SignalItem(QGraphicsPathItem): ...@@ -111,7 +110,11 @@ class SignalItem(QGraphicsPathItem):
Set the signal color to represent that a connected operation is selected. Set the signal color to represent that a connected operation is selected.
""" """
self.setPen(self._active_pen) self.setPen(self._active_pen)
self._src_operation.set_port_active(self._src_key)
self._dest_operation.set_port_active(self._dest_key)
def set_inactive(self) -> None: def set_inactive(self) -> None:
"""Set the signal color to the default color.""" """Set the signal color to the default color."""
self.setPen(self._inactive_pen) self.setPen(self._inactive_pen)
self._src_operation.set_port_inactive(self._src_key)
self._dest_operation.set_port_inactive(self._dest_key)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment