Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think you don't need to use <code>objc.selector</code> at all; try this instead:</p> <pre><code>@objc.IBAction def ShowOpenPanel_(self, sender): self.panel = NSOpenPanel.openPanel() self.panel.setCanChooseFiles_(False) self.panel.setCanChooseDirectories_(True) NSLog(u'Starting OpenPanel') self.panel.beginForDirectory_file_types_modelessDelegate_didEndSelector_contextInfo_( self.defaults.objectForKey_(u'projpath'), objc.nil, objc.nil, self, self.OpenPanelDidEnd_returnCode_contextInfo_, objc.nil) NSLog(u'OpenPanel was started.') </code></pre> <p>I've also found that I need to decorate the end-of-panel function with <code>PyObjCTools.AppHelper.endSheetMethod</code>:</p> <pre><code>@PyObjCTools.AppHelper.endSheetMethod def OpenPanelDidEnd_returnCode_contextInfo_(self, panel, returnCode, context): NSLog('Panel ended.') if (returnCode == NSOKButton): NSLog(u'User selected OK') path = self.panel.filenames()[0] self.defaults.setObject_forKey_(path, u'projpath') del self.panel </code></pre> <p>Here's how I would write what you have:</p> <pre><code>@objc.IBAction def showOpenPanel_(self, sender): panel = NSOpenPanel.openPanel() panel.setCanChooseFiles_(False) panel.setCanChooseDirectories_(True) NSLog(u'Starting openPanel') panel.beginForDirectory_file_types_modelessDelegate_didEndSelector_contextInfo_( self.defaults.objectForKey_(u'projpath'), #forDirectory None, #file None, #types self, #modelessDelegate self.openPanelDidEnd_returnCode_contextInfo_, #didEndSelector None) #contextInfo NSLog(u'openPanel started') @PyObjCTools.AppHelper.endSheetMethod def openPanelDidEnd_returnCode_contextInfo_(self, panel, returnCode, context): NSLog(u'Panel ended') if returnCode != NSOKButton: return NSLog(u'User selected OK') path = panel.filenames()[0] self.defaults.setObject_forKey_(path, u'projpath') </code></pre> <p>Explanation of changes: I always use <code>None</code> rather than <code>objc.nil</code> and it hasn't messed me up yet; I don't think your panel needs to be a property of <code>self</code> since you get it in your return function; objc convention is to have the first letter of your function in lower case.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload