无法参考插座

时间:2013-01-11 04:54:33

标签: python objective-c cocoa

我似乎无法引用我的插座,我终于得到了拖放工作,(在stackoverflow成员的帮助下),但仍然无法使这个插座工作。

class controller(NSWindow):


    form_file = IBOutlet()
    mainWindow = IBOutlet()


    #drag and drop ability
    def awakeFromNib(self):
        self.registerForDraggedTypes_([NSFilenamesPboardType, None])
        print 'registerd drag type'


    def draggingEntered_(self, sender):
        print 'dragging entered'
        pboard = sender.draggingPasteboard()
        types = pboard.types()
        opType = NSDragOperationNone
        if NSFilenamesPboardType in types:
            opType = NSDragOperationCopy
        return opType


    def performDragOperation_(self, sender):
        print 'preform drag operation'
        pboard = sender.draggingPasteboard()
        successful = False
        if NSFilenamesPboardType in pboard.types():
            fileAStr = pboard.propertyListForType_(NSFilenamesPboardType)[0].encode('utf-8')
            successful = True

        #edit some things
        print type(fileAStr)
        self.form_file.setStringValue_(fileAStr)
        return successful

我可以删除该文件,但我无法从form_file函数内部引用performDragOperation出口。我想使用已删除文件中的URL更新NSTextField,但它会返回NoneType错误。

(reason '<type 'exceptions.TypeError'>: 'NoneType' object is not callable') was raised     during a dragging session

我试图捕捉错误,所以我在awakeFromNib函数

中添加了以下内容
    print type(self.formfile)
    print type(self.mainWindow)
    NSLog("formfile = %p", self.formfile)
    NSLog("mainWindow = %p", self.mainWindow)
    NSLog("self = %p", self)
    print self

哪会归还:

registerd drag type
<type 'NoneType'>
<type 'NoneType'>
2013-01-12 16:32:29.211 app [463:303] formfile = 0x10013c148
2013-01-12 16:32:29.212 app[463:303] mainWindow = 0x10013c148
2013-01-12 16:32:29.212 app[463:303] self = 0x105aba890
<controller: 0x1008a1600>
registerd drag type
<objective-c class NSTextField at 0x7fff785296e8>
<objective-c class controller at 0x10541b6a0>
2013-01-12 16:32:29.216 app[463:303] formfile = 0x105abaa10
2013-01-12 16:32:29.216 app[463:303] mainWindow = 0x105abaa10
2013-01-12 16:32:29.216 app[463:303] self = 0x105aba890
<controller: 0x1008afe00>

但是如果我在draggingEntered函数中进行相同的测试,那么我只得到一个控制器和对象(NoneType一个)。问题是它运行awakeFromNib方法两次吗?我认为这可能是我的xib文件的一个问题,但我已经过了它,似乎无法弄清楚这个问题。

任何想法,

汤姆

1 个答案:

答案 0 :(得分:0)

由于我不熟悉Python,我的建议可能有效,也可能无效......

如果Python有类并且您的文件是子类,请尝试调用awakeFromNib中的超类。