From 14961ff09de8bd61132f2f90aed2f999fa996f4f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20H=C3=B6gstedt?= <marin.hogstedt@hotmail.com>
Date: Wed, 5 Jun 2024 15:38:35 +0200
Subject: [PATCH] started on pipeline, pivotet to fixing comments and
 documentation

---
 src/simudator/core/processor.py |  5 +++
 src/simudator/gui/gui.py        | 74 +++++++++++++++++++--------------
 src/simudator/gui/pipeline.py   | 10 +++++
 3 files changed, 58 insertions(+), 31 deletions(-)
 create mode 100644 src/simudator/gui/pipeline.py

diff --git a/src/simudator/core/processor.py b/src/simudator/core/processor.py
index 5a7be7b..ca5cb7f 100644
--- a/src/simudator/core/processor.py
+++ b/src/simudator/core/processor.py
@@ -71,6 +71,11 @@ class Processor:
             module = self.update_queue.pop(0)
             module.update_logic()
 
+    def get_current_instrution(self):
+        """
+        Return the current instruction. Useful for pipeline diagram.
+        """
+        raise NotImplemented
 
     def run_continuously(self):
         """
diff --git a/src/simudator/gui/gui.py b/src/simudator/gui/gui.py
index 2fd6d85..9dd0897 100644
--- a/src/simudator/gui/gui.py
+++ b/src/simudator/gui/gui.py
@@ -32,6 +32,7 @@ from simudator.gui.orientation import Orientation
 from simudator.gui.port_graphics_item import PortGraphicsItem
 from simudator.gui.run_continuously_thread import RunThread
 from simudator.gui.signal_graphics_item import SignalGraphicsItem
+from simudator.gui.pipeline import PipeLine
 
 
 class View(QGraphicsView):
@@ -82,7 +83,9 @@ class View(QGraphicsView):
 
 class GUI(QMainWindow):
     """
-    This is the main class for the GUI. It handles creating the widnow for
+    Main gui class. Handles gui windows, toolbar and visualizes modules.
+
+    This is the main class for the GUI. It handles creating the window for
     the gui, aswell as the toolbar for controlling the simultaion.
     It takes a processor and visualizes its modules as boxes with the signals as lines
     between them. Graphics items for the modules and signals need to be created
@@ -119,6 +122,11 @@ class GUI(QMainWindow):
         # Using the cpu's internal status directly could case problems
         self.cpu_running = False
 
+        self.pipeline = PipeLine()
+        self.pipeline.setRowCount(5)
+        self.pipeline.setColumnCount(5)
+        self.pipeline.show()
+
         # Set Style, THESE ARE TEST AND DONT WORK
         app = QApplication.instance()
         app.setStyleSheet("Qwidget.QMainWindow { background-color: yellow }")
@@ -129,6 +137,9 @@ class GUI(QMainWindow):
 
     def createToolBar(self) -> None:
         """
+        Creates the toolbar containing file, layout and toolbar buttons.
+
+
         Creates the toolbar containing the file, layout and toolbar
         buttons with their respective sub buttons.
         """
@@ -260,6 +271,8 @@ class GUI(QMainWindow):
 
     def connectModuleActions(self, action_signals: []) -> None:
         """
+        Connects modules with actions thorught ids (strings). Useful for breakpoints.
+
         This function takes a list of tuples with an
         action id (which is a predefined string) and a signal.
         It then connects the signal to a function depending on the action id.
@@ -288,6 +301,7 @@ class GUI(QMainWindow):
     def updateCpuListeners(self) -> None:
         """
         Updates the graphics items in the scene and the clock.
+
         Used after the cpu has run or when the user has edited somehting.
         """
         self.cpu_graphics_scene.updateGraphicsItems()
@@ -309,6 +323,7 @@ class GUI(QMainWindow):
         if self.breakpoint_window is not None:
             self.breakpoint_window.update()
 
+
     """
     @Slot is used to explicitly mark a python method as a Qt slot
     and specify a C++ signature for it, which is used most commonly
@@ -318,8 +333,9 @@ class GUI(QMainWindow):
     @Slot(str, str, str)
     def editModuleState(self, module_name, state, value) -> None:
         """
-        Tries to change the value of module to value given by user
-        through the dialog opened by editModuleStateDialog.
+        Tries to change the value of module to value given by user.
+
+        Does this through the dialog opened by editModuleStateDialog.
         """
         try:
             parsed_value = ast.literal_eval(value)
@@ -335,8 +351,9 @@ class GUI(QMainWindow):
     @Slot(str, str, str)
     def editMemoryContent(self, module_name: str, adress: str, value: str) -> None:
         """
-        Tries to change the value at adress to value given by user
-        through the dialog opened by editModuleStateDialog.
+        Tries to change the value at adress to value given by user.
+
+        Does this through the dialog opened by editModuleStateDialog.
         """
         try:
             parsed_adress = int(adress, 16)
@@ -357,8 +374,7 @@ class GUI(QMainWindow):
     @Slot(str, str, str)
     def addStateBreakpoint(self, module_name: str, state: str, value: str) -> None:
         """
-        Tries to add a breakpoint to the module through the dialog
-        opened by stateBreakpointDialog.
+        Tries to add a breakpoint to the module through the dialog opened by stateBreakpointDialog.
         """
         try:
             parsed_value = ast.literal_eval(value)
@@ -370,8 +386,7 @@ class GUI(QMainWindow):
     @Slot(str, str)
     def addLambdaBreakpoint(self, lambda_name, kwargs_str) -> None:
         """
-        Tries to add a breakpoint to the module through the dialog
-        opened by lambdaBreakpointDialog.
+        Tries to add a breakpoint to the module through the dialog opened by lambdaBreakpointDialog.
         """
         try:
             lambda_kwargs = {}
@@ -386,8 +401,7 @@ class GUI(QMainWindow):
     @Slot(str, str, str)
     def addMemoryBreakpoint(self, module_name: str, adress: str, value: str) -> None:
         """
-        Tries to add a breakpoint to the module through the dialog
-        opened by memoryBreakpointDialog.
+        Tries to add a breakpoint to the module through the dialog opened by memoryBreakpointDialog.
         """
         try:
             parsed_adress = int(adress)
@@ -399,8 +413,7 @@ class GUI(QMainWindow):
 
     def setDisabledWhenRunning(self, is_disable):
         """
-        This function greys out buttons for actions
-        that can't be done while cpu is running.
+        Greys out buttons for actions that can't be done while cpu is running.
         """
         self.load_action.setDisabled(is_disable)
         self.save_action.setDisabled(is_disable)
@@ -445,8 +458,7 @@ class GUI(QMainWindow):
     @Slot(int)
     def cpuHaltedFunction(self, steps: int) -> None:
         """
-        Called from other thread when cpu has halted.
-        Will inform the user and update visuals.
+        Called from other thread when cpu has halted. Will inform the user and update visuals.
         """
 
         # If a breakpoint halted the program inform thr user
@@ -468,10 +480,11 @@ class GUI(QMainWindow):
         self.cpu.stop()
         self.updateCpuListeners()
 
+
+    # TODO: What is the difference between folderSaveDialog and folderLoadDialog?
     def folderSaveDialog(self) -> str:
         """
-        Opens a file explorer in a new window. Returns the
-        absolute path to the selected file.
+        Opens a file explorer in a new window. Returns the absolute path to the selected file.
         """
         dialog = QFileDialog()
         dialog.setFileMode(QFileDialog.AnyFile)
@@ -482,8 +495,7 @@ class GUI(QMainWindow):
 
     def folderLoadDialog(self) -> str:
         """
-        Opens a file explorer in a new window. Returns the
-        absolute path to the selected file.
+        Opens a file explorer in a new window. Returns the absolute path to the selected file.
         """
         dialog = QFileDialog()
         dialog.setFileMode(QFileDialog.AnyFile)
@@ -562,9 +574,9 @@ class GUI(QMainWindow):
 
     def saveLayoutToolBarButtonClick(self) -> None:
         """
-        Saves the layout of all the modules in a (somewhat)
-        human readable format.
-        Erases the previous content of the file before saving
+        Saves the layout of all the modules in a (somewhat) human readable format.
+
+        This also erases the previous content of the file before saving
         the data.
         """
         path = self.folderSaveDialog()
@@ -605,8 +617,7 @@ class GUI(QMainWindow):
 
     def loadDefaultLayoutToolBarButtonClick(self) -> None:
         """
-        Places all the module_graphic objects in a diagonal going
-        down to the right.
+        Places all the module_graphic objects in a diagonal going down to the right.
         """
         counter = 0
         for key in self.cpu_graphics_scene.module_graphics_items:
@@ -621,6 +632,7 @@ class GUI(QMainWindow):
     def loadLayoutFromFile(self, file) -> None:
         """
         Loads a layout for the current cpu from the selected file.
+
         If at anypoint this funciton would error, the default layout
         is loaded instead.
         """
@@ -666,8 +678,7 @@ class GUI(QMainWindow):
         visibility: bool,
     ) -> None:
         """
-        Changes the graphical signal to have the positions given
-        as argument.
+        Changes the graphical signal to have the positions given as argument.
         """
         qpoints = []
         # Turn points -> QPointF
@@ -686,8 +697,7 @@ class GUI(QMainWindow):
         graphics_module_y: float,
     ) -> None:
         """
-        Changes the positions of graphical modules to the ones given
-        as argument.
+        Changes the positions of graphical modules to the ones given as argument.
         """
         graphics_module.setX(graphics_module_x)
         graphics_module.setY(graphics_module_y)
@@ -708,8 +718,8 @@ class GUI(QMainWindow):
     def saveStateMenuButtonClick(self) -> None:
         """
         Save state of cpu to file.
-        Erases the previous content of the file before saving
-        the data.
+
+        This erases the previous content of the file before saving the data.
         """
 
         # Not safe to save while running
@@ -753,7 +763,9 @@ class GUI(QMainWindow):
 
     def loadLayoutToolBarButtonClick(self) -> None:
         """
-        Loads a given layout from a selected file. If the layout was
+        Loads a given layout from a selected file.
+
+        If the layout was
         unable to load, an error message will pop up informing the user
         and the default layout will be loaded.
         """
diff --git a/src/simudator/gui/pipeline.py b/src/simudator/gui/pipeline.py
new file mode 100644
index 0000000..1755428
--- /dev/null
+++ b/src/simudator/gui/pipeline.py
@@ -0,0 +1,10 @@
+from qtpy.QtWidgets import QTableWidget
+
+class PipeLine(QTableWidget):
+    """
+    Documentation
+    """
+
+    def __init__(self):
+        super().__init__()
+
-- 
GitLab