mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Platform independent wrapper for controlling sleep
This commit is contained in:
parent
3fd1383c80
commit
a44cb71cbb
39
src/calibre/gui2/viewer/control_sleep.py
Normal file
39
src/calibre/gui2/viewer/control_sleep.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# vim:fileencoding=utf-8
|
||||||
|
# License: GPL v3 Copyright: 2021, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
|
|
||||||
|
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
|
@ -988,7 +988,7 @@ wait_named_pipe(PyObject *self, PyObject *args) {
|
|||||||
static PyObject*
|
static PyObject*
|
||||||
set_thread_execution_state(PyObject *self, PyObject *args) {
|
set_thread_execution_state(PyObject *self, PyObject *args) {
|
||||||
unsigned long new_state;
|
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);
|
if (SetThreadExecutionState(new_state) == NULL) return PyErr_SetFromWindowsErr(0);
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user