diff --git a/src/calibre/gui2/viewer/control_sleep.py b/src/calibre/gui2/viewer/control_sleep.py new file mode 100644 index 0000000000..d189cd4b27 --- /dev/null +++ b/src/calibre/gui2/viewer/control_sleep.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python +# vim:fileencoding=utf-8 +# License: GPL v3 Copyright: 2021, Kovid Goyal + + +from calibre.constants import ismacos, iswindows + +if iswindows: + from winutil import ( + ES_CONTINUOUS, ES_DISPLAY_REQUIRED, ES_SYSTEM_REQUIRED, + set_thread_execution_state + ) + + def prevent_sleep(reason=''): + set_thread_execution_state(ES_CONTINUOUS | ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED) + print(11111111111) + return 1 + + def allow_sleep(cookie): + set_thread_execution_state(ES_CONTINUOUS) + print(2222222222) +elif ismacos: + from cocoa import ( + create_io_pm_assertion, kIOPMAssertionTypeNoDisplaySleep, + release_io_pm_assertion + ) + + def prevent_sleep(reason=''): + return create_io_pm_assertion(kIOPMAssertionTypeNoDisplaySleep, reason or 'E-book viewer automated reading in progress') + + def allow_sleep(cookie): + release_io_pm_assertion(cookie) + +else: + def prevent_sleep(reason=''): + return 0 + + def allow_sleep(cookie): + pass diff --git a/src/calibre/utils/windows/winutil.cpp b/src/calibre/utils/windows/winutil.cpp index c20733e603..a32d610f9a 100644 --- a/src/calibre/utils/windows/winutil.cpp +++ b/src/calibre/utils/windows/winutil.cpp @@ -988,7 +988,7 @@ wait_named_pipe(PyObject *self, PyObject *args) { static PyObject* set_thread_execution_state(PyObject *self, PyObject *args) { unsigned long new_state; - if (!PyArg_ParseTuple(args, "k", new_state)) return NULL; + if (!PyArg_ParseTuple(args, "k", &new_state)) return NULL; if (SetThreadExecutionState(new_state) == NULL) return PyErr_SetFromWindowsErr(0); Py_RETURN_NONE; }