This commit is contained in:
Kovid Goyal 2020-11-19 20:44:57 +05:30
parent ab377cfda5
commit fbb259b86b
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 11 additions and 9 deletions

View File

@ -18,6 +18,7 @@ class Client:
self.current_callback = None
def __del__(self):
if self.sp_voice is not None:
self.sp_voice.shutdown_event_loop()
self.events_thread.join(5)
self.sp_voice = None
@ -27,8 +28,9 @@ class Client:
while True:
if self.sp_voice.wait_for_event() is False:
break
if self.current_callback is not None:
self.current_callback()
c = self.current_callback
if c is not None:
c()
def get_events(self):
from calibre_extensions.winsapi import SPEI_TTS_BOOKMARK, SPEI_START_INPUT_STREAM, SPEI_END_INPUT_STREAM

View File

@ -340,7 +340,7 @@ Voice_shutdown_event_loop(Voice *self, PyObject *args) {
}
static PyObject*
get_events(Voice *self, PyObject *args) {
Voice_get_events(Voice *self, PyObject *args) {
HRESULT hr;
const ULONG asz = 32;
ULONG num_events;
@ -383,9 +383,9 @@ get_events(Voice *self, PyObject *args) {
}
static PyObject*
Voice_wait_for_event(Voice *self, PyObject *callback) {
if (!PyCallable_Check(callback)) { PyErr_SetString(PyExc_TypeError, "callback object is not callable"); return NULL; }
Voice_wait_for_event(Voice *self, PyObject *args) {
const HANDLE handles[2] = {self->shutdown_events_thread, self->events_available};
DWORD ev;
Py_BEGIN_ALLOW_THREADS;
ev = WaitForMultipleObjects(2, handles, true, INFINITE);
Py_END_ALLOW_THREADS;
@ -420,7 +420,7 @@ static PyMethodDef Voice_methods[] = {
M(set_current_sound_output, METH_VARARGS),
M(shutdown_event_loop, METH_NOARGS),
M(wait_for_event, METH_O),
M(wait_for_event, METH_NOARGS),
M(get_events, METH_NOARGS),
{NULL, NULL, 0, NULL}
};