From b2f72f908e5894c0b2bb661dd2548378627f62f1 Mon Sep 17 00:00:00 2001 From: Greg Lucas Date: Fri, 15 Dec 2023 20:47:05 -0700 Subject: [PATCH] FIX: Add macos timers to the main thread The macos timers need to be explicitly added to the main runloop so the drawing takes place there. This causes issues if updating data from other threads and wanting the plot to update. --- src/_macosx.m | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/_macosx.m b/src/_macosx.m index a580362f676f..611486fe26fe 100755 --- a/src/_macosx.m +++ b/src/_macosx.m @@ -1726,11 +1726,15 @@ - (void)flagsChanged:(NSEvent *)event } // hold a reference to the timer so we can invalidate/stop it later - self->timer = [NSTimer scheduledTimerWithTimeInterval: interval - repeats: !single - block: ^(NSTimer *timer) { + self->timer = [NSTimer timerWithTimeInterval: interval + repeats: !single + block: ^(NSTimer *timer) { gil_call_method((PyObject*)self, "_on_timer"); }]; + // Schedule the timer on the main run loop which is needed + // when updating the UI from a background thread + [[NSRunLoop mainRunLoop] addTimer: self->timer forMode: NSRunLoopCommonModes]; + exit: Py_XDECREF(py_interval); Py_XDECREF(py_single);