From 56446a1f97e1c0c3b1553be2c572aa8872e2dcad Mon Sep 17 00:00:00 2001
From: Oscar Gustafsson <oscar.gustafsson@gmail.com>
Date: Wed, 25 Jan 2023 12:34:55 +0100
Subject: [PATCH] Refactor for easier modification

---
 .../scheduler_gui/graphics_component_item.py  | 33 +++++++++----------
 1 file changed, 16 insertions(+), 17 deletions(-)

diff --git a/b_asic/scheduler_gui/graphics_component_item.py b/b_asic/scheduler_gui/graphics_component_item.py
index fb919326..2f5c18d8 100644
--- a/b_asic/scheduler_gui/graphics_component_item.py
+++ b/b_asic/scheduler_gui/graphics_component_item.py
@@ -158,12 +158,27 @@ class GraphicsComponentItem(QGraphicsItemGroup):
         pen3.setColor(execution_time)
         pen3.setWidthF(3 / self._scale)
 
+        # make lists of sorted keys. reverse output port list.
+        input_keys = [
+            key for key in self._ports.keys() if key.lower().startswith("in")
+        ]
+        input_keys = sorted(input_keys)
+        output_keys = [
+            key for key in self._ports.keys() if key.lower().startswith("out")
+        ]
+        output_keys = sorted(output_keys, reverse=True)
+
+        # Set the starting position
+
+        x = old_x = self._ports[input_keys[0]]["latency"] if input_keys else 0
+        y = old_y = 0
+        component_path = QPainterPath(QPointF(x, y))  # starting point
+
         # component path
         def draw_component_path(keys: List[str], reversed: bool) -> None:
             """
             Draws component path and also register port positions in self._ports dictionary.
             """
-            nonlocal x
             nonlocal y
             nonlocal old_x
             nonlocal old_y
@@ -185,22 +200,6 @@ class GraphicsComponentItem(QGraphicsItemGroup):
                 old_x = x
                 old_y = y
 
-        # make lists of sorted keys. reverse output port list.
-        input_keys = [
-            key for key in self._ports.keys() if key.lower().startswith("in")
-        ]
-        input_keys = sorted(input_keys)
-        output_keys = [
-            key for key in self._ports.keys() if key.lower().startswith("out")
-        ]
-        output_keys = sorted(output_keys, reverse=True)
-
-        # Set the starting position
-
-        x = old_x = self._ports[input_keys[0]]["latency"] if input_keys else 0
-        y = old_y = 0
-        component_path = QPainterPath(QPointF(x, y))  # starting point
-
         # draw the path
         if input_keys:
             draw_component_path(input_keys, False)  # draw input side
-- 
GitLab