Re: [Pyobjc-dev] Key-Value Coding; Key-Value Observing;
Brought to you by:
ronaldoussoren
|
From: Ronald O. <ron...@ma...> - 2010-05-26 05:33:08
|
On 24 May, 2010, at 19:56, Orestis Markou wrote:
> Thank you for this. Hopefully google will pick it up for other people.
>
> One question - in the synthesize case, is there a convention that maps the _fido ivar to the fido property?
Yes.
The documentation:
def synthesize(name, copy=False, readwrite=True, type=_C_ID, ivarName=None):
"""
Use this in a class dictionary to syntheze simple setting/setter methods.
Note: this is only necessary to get propper behaviour when Key-Value coding
is used and special features (like copying) are needed
usage::
class MyClass (NSObject):
objc.synthesize('someTitle', copy=True)
"""
What the documentation doesn't mention is that 'ivarName' defaults to "_" + name.
BTW. synthesize will also create the ivar variable for you.
Ronald
>
>
> On 24 May 2010, at 15:43, Brice Thurin wrote:
>
>> Good Morning,
>>
>> I am new to Objective-C and PyObjc. I decided to learn Cocoa by reading the book of Aaron Hillegass, "Cocoa Programming for Mac OS X". I first tried the tried the example using only Objective-C. I am now trying to implement the same example using Python and I would like to share my finding as It took me some times to figure out how to do it, also I will appreciate some inputs as what might be a very silly way of using PyObjc. Here I would like to talk about the example of chapter 7 on key-value coding and key-value observing. At first I was a bit confused as if I was supposed to use objc.accessor or not, or if i needed to import PyObjCTools.KeyValueCoding or not, etc.
>>
>> I am coding on a machine running Snow Leopard and I am using XCode with the template provided on the svn. The project is called PyKVCFun. It is a python-cocoa application. Remove the appdelegate file. Create a PyAppController.py file with the template python NSObject subclass. Delete the delegate in the MainMenu.xib file and create add a new NSObject controller and set its class to PyAppController. Make sure you replace the delegate import in main.py by import PyAppController.
>>
>>
>> STEP 1: Add an init function method to the NSObject class .
>>
>> It should look like this:
>>
>> ######
>> from Foundation import *
>> import objc # Do not forget to add it as it is needed later
This isn't needed in PyObjC 2.2 or later (including the version shipped with OSX).
Ronald |