From: Justin Nesselrotte Date: Wed, 31 Dec 2014 17:44:15 +0000 (-0600) Subject: Possible fix for #46 on mac. prevent sleep function implemented with IOKit X-Git-Tag: 14.09-1.18~5^2~4 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=05b74c0b8275a203a89832f5a45db418f810c230;p=cura.git Possible fix for #46 on mac. prevent sleep function implemented with IOKit --- 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):