From 67cc14af5512c981709e4472b22224fa2bf2bf4f Mon Sep 17 00:00:00 2001 From: Youness Alaoui Date: Tue, 30 Dec 2014 22:41:45 -0500 Subject: [PATCH] Prevent forced sleep on windows by going to away mode when supported This will prevent the computer from going to sleep even if the user puts the computer to sleep manually. It will go to awaymode which is identical to sleep mode but the application will keep running in the background until it is done. This should help with issue #46 --- Cura/gui/printWindow.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Cura/gui/printWindow.py b/Cura/gui/printWindow.py index 8a831bed..db57465d 100644 --- a/Cura/gui/printWindow.py +++ b/Cura/gui/printWindow.py @@ -17,9 +17,13 @@ if sys.platform.startswith('win'): """ ES_CONTINUOUS = 0x80000000 ES_SYSTEM_REQUIRED = 0x00000001 + ES_AWAYMODE_REQUIRED = 0x00000040 #SetThreadExecutionState returns 0 when failed, which is ignored. The function should be supported from windows XP and up. if prevent: - ctypes.windll.kernel32.SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED) + # For Vista and up we use ES_AWAYMODE_REQUIRED to prevent a print from failing if the PC does go to sleep + # As it's not supported on XP, we catch the error and fallback to using ES_SYSTEM_REQUIRED only + if ctypes.windll.kernel32.SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_AWAYMODE_REQUIRED) == 0: + ctypes.windll.kernel32.SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED) else: ctypes.windll.kernel32.SetThreadExecutionState(ES_CONTINUOUS) -- 2.30.2