From 98136d4f8bd2e8e7b44107de3e9eb3bcf25df5d4 Mon Sep 17 00:00:00 2001
From: Johannes Kung <johku144@student.liu.se>
Date: Thu, 1 Aug 2024 15:32:42 +0200
Subject: [PATCH] Fixed toggling port labels

---
 src/simudator/gui/cpu_graphics_scene.py              |  7 +++----
 src/simudator/gui/gui.py                             |  2 +-
 src/simudator/gui/menu_bar.py                        |  8 ++++----
 .../gui/module_graphics_item/module_widget.py        | 12 ++++++++++++
 src/simudator/gui/port_widget.py                     |  3 ++-
 5 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/src/simudator/gui/cpu_graphics_scene.py b/src/simudator/gui/cpu_graphics_scene.py
index 60a5072..3fd687b 100644
--- a/src/simudator/gui/cpu_graphics_scene.py
+++ b/src/simudator/gui/cpu_graphics_scene.py
@@ -132,7 +132,7 @@ class CpuGraphicsScene(QGraphicsScene):
             item.setVisible(value)
 
     @Slot(bool)
-    def show_port_names(self, value: bool) -> None:
+    def show_port_labels(self, value: bool) -> None:
         """
         Set the visibility of the names of all ports of graphical modules
         in the scene.
@@ -142,9 +142,8 @@ class CpuGraphicsScene(QGraphicsScene):
         value : bool
             ``True`` to show the port names, ``False`` to hide them.
         """
-        for item in self._modules.values():
-            for port in item.ports:
-                port.setNameVisibility(value)
+        for widget in self._modules.values():
+            widget.set_port_label_visibility(value)
 
     def toggle_layout_lock(self, value: bool) -> None:
         """
diff --git a/src/simudator/gui/gui.py b/src/simudator/gui/gui.py
index 7588570..cb49dab 100644
--- a/src/simudator/gui/gui.py
+++ b/src/simudator/gui/gui.py
@@ -96,7 +96,7 @@ class GUI(QMainWindow):
         self._menu_bar.save_layout.connect(self._graphics_scene.save_layout)
         self._menu_bar.lock_layout.connect(self._graphics_scene.toggle_layout_lock)
         self._menu_bar.show_all_signals.connect(self._graphics_scene.show_all_signals)
-        self._menu_bar.show_port_names.connect(self._graphics_scene.show_port_names)
+        self._menu_bar.show_port_labels.connect(self._graphics_scene.show_port_labels)
 
         # Connect signal for managing breakpoints
         self._menu_bar.show_breakpoints.connect(self.openBreakpointWindow)
diff --git a/src/simudator/gui/menu_bar.py b/src/simudator/gui/menu_bar.py
index 29183a9..9018b64 100644
--- a/src/simudator/gui/menu_bar.py
+++ b/src/simudator/gui/menu_bar.py
@@ -67,10 +67,10 @@ class MainMenuBar(QMenuBar):
     processor signals.
     """
 
-    show_port_names = pyqtSignal(bool)
+    show_port_labels = pyqtSignal(bool)
     """
-    QT signal emitted when the user has requested to toggle showing the names
-    of processor module ports.
+    QT signal emitted when the user has requested to toggle showing the labels
+    of signal ports of module widgets.
     """
 
     update_all_values = pyqtSignal(bool)
@@ -138,7 +138,7 @@ class MainMenuBar(QMenuBar):
         self._port_vis_action = QAction("Show port names", self, checkable=True)
         self._port_vis_action.setChecked(True)
         self._port_vis_action.setStatusTip("Toggle the visibility of port names.")
-        self._port_vis_action.triggered.connect(self.show_port_names)
+        self._port_vis_action.triggered.connect(self.show_port_labels)
 
         # Create Layout menu for layout actions
         layout_menu = self.addMenu("&Layout")
diff --git a/src/simudator/gui/module_graphics_item/module_widget.py b/src/simudator/gui/module_graphics_item/module_widget.py
index 37a6e26..c7ae14b 100644
--- a/src/simudator/gui/module_graphics_item/module_widget.py
+++ b/src/simudator/gui/module_graphics_item/module_widget.py
@@ -261,6 +261,18 @@ class ModuleWidget(QGraphicsWidget):
 
         self.locked.emit(value)
 
+    def set_port_label_visibility(self, value: bool) -> None:
+        """
+        Set the visibility of the labels of the ports of this module widget.
+
+        Parameter
+        ---------
+        value: bool
+            Sets the labels as visible if ``True``, invisible if ``False``.
+        """
+        for port in self._port_widgets:
+            port.set_label_visible(value)
+
     @Slot()
     def set_format(self, state_var: str, format: Format) -> None:
         """
diff --git a/src/simudator/gui/port_widget.py b/src/simudator/gui/port_widget.py
index d087eb3..d4bdd08 100644
--- a/src/simudator/gui/port_widget.py
+++ b/src/simudator/gui/port_widget.py
@@ -404,9 +404,10 @@ class PortWidget(QGraphicsWidget):
         Parameter
         ---------
         value: bool
-            Sets the label as visible if value is `True`, `False` otherwise.
+            Sets the label as visible if ``True``, invisible if ``False``.
         """
         self._label_visible = value
+        self.update()
 
     def orientation(self) -> Orientation:
         """
-- 
GitLab