summaryrefslogtreecommitdiff
path: root/lib/gui/simulator.py
diff options
context:
space:
mode:
authorLex Neva <lexelby@users.noreply.github.com>2023-02-16 22:58:10 -0500
committerGitHub <noreply@github.com>2023-02-16 22:58:10 -0500
commit7aee0979be4f39cde7a6396cdc0d1d2cc4222d90 (patch)
tree1123050a6ba7428dbcc8b72bd074161bdb3e014f /lib/gui/simulator.py
parent30c73dc39c1ac814d0c63ec102c7f8c2b993fdd0 (diff)
parentf6c2aa89197c82cedfb31465fc4b2acffaeb8f25 (diff)
Merge pull request #2045 from inkstitch/lexelby/interruptible-threads
make simulator threads interruptible
Diffstat (limited to 'lib/gui/simulator.py')
-rw-r--r--lib/gui/simulator.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/gui/simulator.py b/lib/gui/simulator.py
index 1cc7066e..d9f51b48 100644
--- a/lib/gui/simulator.py
+++ b/lib/gui/simulator.py
@@ -10,6 +10,8 @@ from threading import Event, Thread
import wx
from wx.lib.intctrl import IntCtrl
+from lib.debug import debug
+from lib.utils.threading import ExitThread
from ..i18n import _
from ..stitch_plan import stitch_groups_to_stitch_plan, stitch_plan_from_file
from ..svg import PIXELS_PER_MM
@@ -749,6 +751,10 @@ class SimulatorPreview(Thread):
self.simulate_window = None
self.refresh_needed = Event()
+ # This is read by utils.threading.check_stop_flag() to abort stitch plan
+ # generation.
+ self.stop = Event()
+
# used when closing to avoid having the window reopen at the last second
self._disabled = False
@@ -770,17 +776,27 @@ class SimulatorPreview(Thread):
if not self.is_alive():
self.start()
+ self.stop.set()
self.refresh_needed.set()
def run(self):
while True:
self.refresh_needed.wait()
self.refresh_needed.clear()
- self.update_patches()
+ self.stop.clear()
+
+ try:
+ debug.log("update_patches")
+ self.update_patches()
+ except ExitThread:
+ debug.log("ExitThread caught")
+ self.stop.clear()
def update_patches(self):
try:
patches = self.parent.generate_patches(self.refresh_needed)
+ except ExitThread:
+ raise
except: # noqa: E722
# If something goes wrong when rendering patches, it's not great,
# but we don't really want the simulator thread to crash. Instead,