PDA

View Full Version : Error importing NSOutlineViewDataSource in PyObjC code




cjcaufield
Feb 28, 2009, 03:40 PM
Hi everyone, first post. :-)

I'm having a problem importing NSOutlineViewDataSource in a Python Cocoa application. The problem is easily reproduced by creating a new Python Cocoa application (document based), and adding the following to main.py just before AppHelper.runEventLoop():

from AppKit import NSOutlineViewDataSource

The error I get is:

Traceback (most recent call last):
File "/Users/colin/Desktop/Untitled/build/Debug/Untitled.app/Contents/Resources/main.py", line 19, in <module>
from AppKit import NSOutlineViewDataSource
ImportError: cannot import name NSOutlineViewDataSource

Anyone know what the deal is? Thanks.



cjcaufield
Feb 28, 2009, 03:48 PM
Forgot to mention, my machine is running 10.5.6 and, as far as I know, everything is up to date.

MacRumors Guy
Feb 28, 2009, 07:22 PM
You can't import it and you don't need to import it.

cjcaufield
Feb 28, 2009, 09:56 PM
Care to be more specific?

hhas
Mar 1, 2009, 04:20 AM
NSOutlineViewDataSource is a protocol, not a class. See:

http://pyobjc.sourceforge.net/documentation/pyobjc-core/protocols.html

Short version, you don't need to do anything special to support informal protocols. Just make sure your Python class (which should be a descendent of NSObject) supports the methods described by the protocol.

More information on ObjC protocols if you need it:

http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/chapter_7_section_1.html

cjcaufield
Mar 1, 2009, 05:36 PM
Thanks, hhas.