From c6d3f374b24f606a5430cde308a1045c5d0e8856 Mon Sep 17 00:00:00 2001
From: Johannes Kung <johku144@student.liu.se>
Date: Mon, 10 Jun 2024 10:12:15 +0200
Subject: [PATCH] Fixed bug where the tick buttons are not enabled after
 stepping some ticks

---
 src/simudator/gui/gui.py                     | 12 ++++++------
 src/simudator/gui/run_continuously_thread.py |  5 ++++-
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/simudator/gui/gui.py b/src/simudator/gui/gui.py
index d8372d2..7aa2f81 100644
--- a/src/simudator/gui/gui.py
+++ b/src/simudator/gui/gui.py
@@ -470,20 +470,20 @@ class GUI(QMainWindow):
         if self.cpu.breakpoint_reached:
             self.messageBox("Reached breakpoint: " + self.cpu.last_breakpoint.__str__())
             self.updateCpuListeners()
-            self.cpu_running = False
-            self.setDisabledWhenRunning(False)
-
 
-        # When the cpu is done we want to inform the user and update visuals
+        # When the CPU is done we want to inform the user and update visuals
         if self.cpu.should_halt():
-
             # Only show halted message for larger steps that take time
             # This is done so a user dosent have to close
             # the message box after every small step
             if steps > self.HALT_MESSAGE_THRESHOLD:
                 self.messageBox("The processor halted.")
-
             self.updateCpuListeners()
+
+        # A signal of 0 steps signifies end of execution, i.e. the CPU has 
+        # halted or run the specified amount of ticks 
+        # => Enable the relevant parts of the GUI again
+        if steps == 0:
             self.cpu_running = False
             self.setDisabledWhenRunning(False)
 
diff --git a/src/simudator/gui/run_continuously_thread.py b/src/simudator/gui/run_continuously_thread.py
index 3694165..e2693fe 100644
--- a/src/simudator/gui/run_continuously_thread.py
+++ b/src/simudator/gui/run_continuously_thread.py
@@ -24,7 +24,7 @@ class RunThread(QRunnable):
 
     def run(self):
         if self.run_continuously:
-            while not self.cpu.should_halt():
+            while not self.cpu.should_halt() and not self.cpu.is_stopped:
                 self.cpu.do_tick()
                 self.signal.emit(1)
                 time.sleep(CPU_TICK_DELAY)
@@ -34,3 +34,6 @@ class RunThread(QRunnable):
                 self.cpu.do_tick()
                 self.signal.emit(1)
                 time.sleep(CPU_TICK_DELAY)
+
+        # Signal end of execution as having run 0 ticks
+        self.signal.emit(0)
-- 
GitLab