From 05b74c0b8275a203a89832f5a45db418f810c230 Mon Sep 17 00:00:00 2001 From: Justin Nesselrotte Date: Wed, 31 Dec 2014 11:44:15 -0600 Subject: [PATCH] Possible fix for #46 on mac. prevent sleep function implemented with IOKit --- Cura/gui/printWindow.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Cura/gui/printWindow.py b/Cura/gui/printWindow.py index db57465d..35be4a83 100644 --- a/Cura/gui/printWindow.py +++ b/Cura/gui/printWindow.py @@ -27,9 +27,24 @@ if sys.platform.startswith('win'): else: ctypes.windll.kernel32.SetThreadExecutionState(ES_CONTINUOUS) +elif sys.platform.startswith('darwin'): + import objc + bundle = objc.initFrameworkWrapper("IOKit", + frameworkIdentifier="com.apple.iokit", + frameworkPath=objc.pathForFramework("/System/Library/Frameworks/IOKit.framework"), + globals=globals()) + objc.loadBundleFunctions(bundle, globals(), [("IOPMAssertionCreateWithName", b"i@I@o^I")]) + def preventComputerFromSleeping(prevent): + if prevent: + success, preventComputerFromSleeping.assertionID = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, "Cura is printing", None) + if success != kIOReturnSuccess: + preventComputerFromSleeping.assertionID = None + else: + if preventComputerFromSleeping.assertionID is not None: + IOPMAssertionRelease(preventComputerFromSleeping.assertionID) + preventComputerFromSleeping.assertionID = None else: def preventComputerFromSleeping(prevent): - #No preventComputerFromSleeping for MacOS and Linux yet. pass class printWindowPlugin(wx.Frame): -- 2.30.2