我对如何为窗口实现拖放功能然后让 url 出现在文本框中感到困惑。
我已经更新了我卡在的地方
class controller(NSWindow):
#File to encode or decode
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 doctor who'
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():
print 'my actions finally working'
fileAStr = pboard.propertyListForType_(NSFilenamesPboardType)[0]
print type(fileAStr.encode('utf-8'))
successful = True
print self.form_file
return successful
我可以删除文件,但我无法form_file
从performDragOperation
函数内部引用插座。如您所见,我正在尝试打印它,但它返回NoneType
错误。
(原因 '<type 'exceptions.TypeError'>: 'NoneType' object is not callable')在拖动会话期间引发