chiark / gitweb /
Possible fix for #46 on mac. prevent sleep function implemented with IOKit
authorJustin Nesselrotte <jnesselr@harding.edu>
Wed, 31 Dec 2014 17:44:15 +0000 (11:44 -0600)
committerJustin Nesselrotte <jnesselr@harding.edu>
Wed, 31 Dec 2014 17:44:15 +0000 (11:44 -0600)
Cura/gui/printWindow.py

index db57465ddc72f7b0d9aa00d1b9ef73526f156a78..35be4a8385f1be33c478b6cce3361ecf760f86e3 100644 (file)
@@ -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):