As elv notes, beginSheetForDirectory:file:modalForWindow:modalDelegate:didEndSelector:contextInfo:
has been deprecated in 10.6, and the new method to use is beginSheetModalForWindow:completionHandler:
There's no metadata for this method in the version of PyObjC that shipped with Snow Leopard, but it has since been added, and you can update the appropriate file yourself so that you can use this method. Open /System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC/AppKit/PyObjC.bridgesupport and find the element:
<class name='NSSavePanel'>
inside this, add the following:
<method selector='beginSheetModalForWindow:completionHandler:'>
<arg index='1' block='true' >
<retval type='v' />
<arg type='i' type64='q' />
</arg>
</method>
<method selector='beginWithCompletionHandler:'>
<arg index='0' block='true' >
<retval type='v' />
<arg type='i' type64='q' />
</arg>
</method>
This is the metadata that the Python side needs in order to get and return the correct types of objects to Objective-C. You can pass any callable for the completion handler, as long as it has the correct signature (i.e., takes an integer argument and returns nothing). An example:
def showOpenPanel_(self, sender):
openPanel = NSOpenPanel.openPanel()
def openPanelDidClose_(result):
if result == NSFileHandlingPanelOKButton:
openPanel.orderOut_(self)
image = NSImage.alloc().initWithContentsOfFile_(openPanel.filename())
self.imgView.setImage_(image)
openPanel.setAllowedFileTypes_(NSImage.imageFileTypes())
openPanel.beginSheetModalForWindow_completionHandler_(self.imgView.window(),
objc.selector(openPanelDidClose_, argumentTypes='l'))