Re: [Pyobjc-dev] PyObjC and bindings
Brought to you by:
ronaldoussoren
|
From: Ronald O. <ron...@ma...> - 2008-01-22 17:42:15
|
John,
Could you post the code, that would make discussion easier.
The first error you're getting is probably because you do something
like this:
def setFoo_(self, value):
self.foo = value
def foo(self):
return self.foo
That works in Objective-C, but no in python, the method foo and the
instance variable foo live in the same namespace in Python (more or
less, reality is slightly more complex than that).
The non-accessor version probably needs a property definition:
class FileModel (NSObject):
foo = objc.ivar()
Ronald
On 22 Jan, 2008, at 0:08, John Skidgel wrote:
> Hi All,
>
> Forgive me but I'm new to PyObjC.
>
> I'm trying to add a directory path to an NSTableView programatically.
>
> In Interface builder, I have an NSTableView with columns bound to an
> NSArrayController. It's called arrayController and it's class name is
> FileModel, which is a Python class in my XCode project.
> ArrayController has fileName, and fileLocation as keys. FileModel.py
> has instance variables for both of these.
>
> Below the table, I have an Add and a Remove button. The Add button
> displays an Open panel as a sheet. Upon selecting a file and clicking
> OK, a method named, didEndSheet_returnCode_contextInfo_ creates a
> FileModel object, myFile and uses sheet.filename() to set fileLocation
> and sheet.filename().lastPathComponent() to set fileName. I can use
> NSLog and successfully trace these attributes. Where the program fails
> is in adding this myFile instance to arrayController instance.
>
> The current flow is:
> 1 The user launches the application
> 2 The user clicks Add button
> 3 The application displays a File Open panel as a sheet
> 4 The user browses to a file and selects it
> 5 The user clicks open
> 6 Error occurs
>
> I've added accessor methods for the FileModel class and I get this
> error at step 6:
>
> (TypeError: cannot change a method)
>
> If I remove the accessor methods, I get the following error dialog in
> step 6:
>
> (AttributeError: 'NoneType' object has no attribute 'addObject_')
>
> I've read a few tutorials on bindings but I'm still fuzzy on whether
> there's a disconnect between the NSArrayController in the Nib file and
> code in the delegate or if it's a type conversion problem.
>
> Any ideas?
>
> Cheers,
>
> John
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Pyobjc-dev mailing list
> Pyo...@li...
> https://lists.sourceforge.net/lists/listinfo/pyobjc-dev
|