我想用PyObjC编写以下Objective-C代码的等效Python代码。不知道怎么办?如果能在ow上帮助将Objective-C代码连接到Python中,我们将不胜感激。在
#import <IOKit/pwr_mgt/IOPMLib.h>
...
// kIOPMAssertionTypeNoDisplaySleep prevents display sleep,
// kIOPMAssertionTypeNoIdleSleep prevents idle sleep
//reasonForActivity is a descriptive string used by the system whenever it needs
// to tell the user why the system is not sleeping. For example,
// "Mail Compacting Mailboxes" would be a useful string.
// NOTE: IOPMAssertionCreateWithName limits the string to 128 characters.
CFStringRef* reasonForActivity= CFSTR("Describe Activity Type");
IOPMAssertionID assertionID;
IOReturn success = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep,
kIOPMAssertionLevelOn, reasonForActivity, &assertionID);
if (success == kIOReturnSuccess)
{
//Add the work you need to do without
// the system sleeping here.
success = IOPMAssertionRelease(assertionID);
//The system will be able to sleep again.
}
...
您需要首先使用
gen_bridge_metadata
命令为IOKit.framework
生成一个网桥文件。在如果需要,可以将文件的内容硬编码为Python变量。在
然后使用
objc.parseBridgeSupport()
将桥加载到PyObjC中示例here和{a2}
Here is an example这几乎完全符合你的要求。在
相关问题 更多 >
编程相关推荐