[Pythonmac-SIG] Pyobjc and Panel?

Bob Ippolito bob at redivi.com
Tue Oct 5 14:01:04 CEST 2004


On Oct 5, 2004, at 7:50 AM, whamoo wrote:

> I have some problem to use the cocoa panel (NSOpenPanel, and  
> NSSavePanel) using PyObjC...
> I must import AppKit right? Then? Calling AppKit.NSOpenPanel() result  
> to :"(TypeError: Use class methods to instantiate new Objective-C  
> objects)",
> So how to use the panel? (and it is normal that pydoc on AppKit take 1  
> minute to open?)

Yes you must import AppKit to use AppKit functionality.  Yes it's  
normal for pydoc to be very slow for PyObjC modules.  You shouldn't be  
using pydoc, you should be using Apple's documentation.  There is very  
little useful information in the pydoc for AppKit, Foundation, etc.

You create an NSOpenPanel instance the same way you do in Objective C.

1) Read the documentation:
http://developer.apple.com/documentation/Cocoa/Reference/ 
ApplicationKit/ObjC_classic/Classes/NSOpenPanel.html

2) Find the designated initializer in the documentation:
openPanel
+ (NSOpenPanel *)openPanel
Creates and returns a new NSOpenPanel object. The open panel has been  
initialized with default values.

3) Translate the Objective C in the documentation into PyObjC code:

from AppKit import *

# this isn't a full example, this code needs to be called during a  
runloop...
panel = NSOpenPanel.openPanel()
rval = panel.runModalForTypes_([u'py'])
print panel.filenames()


If this doesn't make sense to you, I suggest you read through some of  
the examples and all of the documentation for PyObjC.

-bob


More information about the Pythonmac-SIG mailing list