【发布时间】:2013-05-29 02:05:42
【问题描述】:
编辑:对于未来的 googlers abarnert 的回答作品提供 NSHIObject(来自 HIToolbox,HI 代表人机界面),我可以找到更多关于此的文档,在 apple.com 上唯一提及(那里是关于一个名为 NSHI 对象的类的零、ZIP、NADA 文档,截至目前https://www.google.com/#q=%22NSHIObject%22+site%3Aapple.com&filter=0) 是 在对象 c 中,如果我有以下 http://lists.apple.com/archives/webkitsdk-dev/2010/Sep/msg00007.html 不适用于此对象,则不会创建 NSWindow。是的,苹果 api 文档。
NSWindow.initWithWindowRef_(nshi_object)
Traceback (most recent call last):
File "<input>", line 1, in <module>
TypeError: Expecting instance of NSWindow as self, got one of NSHIObject
关于加载从 wxPython 给出的指针的原始问题
C 代码
// our data
int a = 42;
// create a pointer to that data
int *p = &a;
// p now contains the address (say 1776) and that address has the integer 42
// get the data back
int ret_a = *p;
// now if we already have an address
int* manual_pointer = (int*) 1776;
int man_a = *manual_pointer;
printf("%d,%d\n", ret_a, man_a);
如何在 pyobjc 中执行此语法?我看到它提到了here
More complex types can be represented using longer type strings:
a pointer to some type is _C_PTR followed by the type string of the pointed-to type.
那我该怎么办?这个(如果对象类型是 NSInt)?
arg = _C_PTR + "NSInt" + "1776"
Objective C 代码(稍后添加) 请注意,您必须以某种方式将其注入 python 进程,否则它将无法工作
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
char line[2048];
// this will store are address
long adr;
printf("According to \n- http://forums.wxwidgets.org/viewtopic.php?f=23&t=31778\n- http://forums.wxwidgets.org/viewtopic.php?f=23&t=18645\n");
printf("This will prompt you for a pointer address; please paste in the long you received from GetHandle()\n");
printf("Please enter pointer address: ");
fgets(line, sizeof(line), stdin);
sscanf(line, "%ld", &adr);
printf("Using address: %ld\n", adr);
printf("Grabbing view...");
// our NSView
NSView *view = (__bridge NSView *)((void *)adr);
NSRect f = view.frame;
int w = f.size.width;
int h = f.size.height;
printf("Size(%d, %d)", w, h);
}
return 0;
}
【问题讨论】:
-
您展示的代码是纯C,其中没有ObjC。指向 Objective-C 类型字符串的链接在这里似乎根本不相关。你到底想做什么?
-
你没有提到你真正想要做什么,这让你很难告诉你该做什么。
-
无论如何,您所指的 PyObjC 文档是用于描述函数/方法参数类型的 Objective-C 类型编码的文档。作为 PyObjC 的用户,您应该没有理由实际使用这些类型编码。
标签: python objective-c macos pyobjc