Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed issue where NSApp terminate called after endLoop #226

Merged
merged 2 commits into from
Aug 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions pyttsx3/drivers/nsss.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,22 @@
from Foundation import *
from AppKit import NSSpeechSynthesizer
from PyObjCTools import AppHelper
from pyttsx3.voice import Voice
from PyObjCTools.AppHelper import PyObjCAppHelperRunLoopStopper
from ..voice import Voice

class RunLoopStopper(PyObjCAppHelperRunLoopStopper):

def init(self):
self = super(RunLoopStopper, self).init()
self.shouldStop = False
return self

def stop(self):
self.shouldStop = True
# this should go away when/if runEventLoop uses
# runLoop iteration
# if NSApp() is not None:
# NSApp().terminate_(self)

def buildDriver(proxy):
return NSSpeechDriver.alloc().initWithProxy(proxy)
Expand Down Expand Up @@ -32,7 +46,20 @@ def onPumpFirst_(self, timer):
def startLoop(self):
NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(
0.0, self, 'onPumpFirst:', None, False)
AppHelper.runConsoleEventLoop()
runLoop = NSRunLoop.currentRunLoop()
stopper = RunLoopStopper.alloc().init()
PyObjCAppHelperRunLoopStopper.addRunLoopStopper_toRunLoop_(stopper, runLoop)
try:

while stopper.shouldRun():
nextfire = runLoop.limitDateForMode_(NSDefaultRunLoopMode)
if not stopper.shouldRun():
break
if not runLoop.runMode_beforeDate_(NSDefaultRunLoopMode, nextfire):
stopper.stop()

finally:
PyObjCAppHelperRunLoopStopper.removeRunLoopStopperFromRunLoop_(runLoop)

def endLoop(self):
AppHelper.stopEventLoop()
Expand Down