Python 引用插座时出现问题
我似乎在引用我的出口时遇到了问题,在stackoverflow成员的帮助下,我终于实现了拖放操作,但仍然无法让这个出口工作Python 引用插座时出现问题,python,objective-c,cocoa,Python,Objective C,Cocoa,我似乎在引用我的出口时遇到了问题,在stackoverflow成员的帮助下,我终于实现了拖放操作,但仍然无法让这个出口工作 class controller(NSWindow): form_file = IBOutlet() mainWindow = IBOutlet() #drag and drop ability def awakeFromNib(self): self.registerForDraggedTypes_([NSFilen
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
我可以删除该文件,但无法从performDragOperation函数内部引用form_文件出口。我想用删除文件中的URL更新NSTextField,但它返回一个非类型错误
这将返回以下内容:
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>
但是如果我在Draggingered函数中做同样的测试,那么我只得到一个控制器和一个非类型的对象。问题是它从NIB方法中运行了两次,对吗?我想这可能是我的xib文件的问题,但我已经检查过了,似乎无法找出问题所在
任何想法
Tom由于我不熟悉Python,我的建议可能行得通,也可能行不通
如果Python有类,并且您的文件是子类,请尝试在awakeFromNib中调用超类。从函数中调用超类无法修复函数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>