On 13-aug-04, at 1:26, Bob Ippolito wrote:
> On Aug 12, 2004, at 7:15 PM, Jordan Krushen wrote:
>> However, in another project, I'm trying to have a resuable,=20
>> pure-Python model class that can be used verbatim in the Twisted=20
>> server to which this Cocoa app will communicate, with the model=20
>> objects ultimately residing on said server (using Twisted's cacheable=20=
>> PB objects, perhaps)
>> I tried making a pure-Python (no objc references) class that was=20
>> created for each above Person class:
>> class PyPerson (object):
>> def __init__(self):
>> self.personName =3D 'New Person'
>> self.expectedRaise =3D 6.0
>> ...and instantiating it as self.pyPerson in Person.py's init(), and=20=
>> then get/set self.pyPerson.whatever from Person.py's setters/getters,=20=
>> like so:
>> def setExpectedRaise_(self, x):
>> self.pyPerson.expectedRaise =3D x.doubleValue()
>> setExpectedRaise_ =3D objc.accessor(setExpectedRaise_)
>> (ignoring setter/getter methods in PyPerson for now, using direct=20
>> attribute access)
>> This works, but is this the recommended way of doing things? Will I=20=
>> have to wrap all my pure-Python model objects with KVC shims like=20
>> this? Should I simply override setValue:forKey: and valueForKey: and=20=
>> access the pure-Python model's methods that way? Will this bugger up=20=
>> nil-related attribute setting =E0 la setNilValueForKey: ?
> Having Python objects that don't inherit from NSObject cross the=20
> bridge doesn't work as well as it could. Personally I think that=20
> everything in PyObjC should support KVC unless explicitly told not to,=20=
> especially bridged pure python objects. That's more up to bill and=20
> ronald though.
Key-Value *Coding* should work just fine, Key-Value *Observing* (aka=20
Cocoa Bindings) probably isn't. The major problem there is that there's=20=
no easy way to generate the required notifications. It might be=20
possible to use the python debugger to create hooks on __getattr__ and=20=
__setattr__ though. (The alternative is generating the notification=20
yourself in python code, but that isn't a very useful alternative).
I am interested in adding a way to use pure python objects with Cocoa=20
Bindings, that would make it easier to have a platform-independent core=20=
with a Cocoa GUI layer on top (and a GTK layer on Linux, etc.)
>> Is there an auto-converter for any given objc type to a native,=20
>> non-objc Python type, so that I don't have to call x.doubleValue(),=20=
>> or str(personName) every time, or should I write my own?
> There is and can't really be an "auto-converter".
> BTW: You should never str(personName) .. you should use unicode(...).=20=
> As for doubleValue(), etc. You don't know whether it's an integer,=20=
> double, etc. from the NSNumber so you're better off calling what you=20=
> want explicitly.
Isn't NSNumber automaticly converted at the moment? You do have to call=20=
x.doubleValue() (or intValue, or strValue, or ...) on text fields, but=20=
automaticly converting those really isn't possible.
>> One more obligatory question, where I don't mean to offend, and I=20
>> know that few people in this world are capable of fixing it, but: =20
>> Any hope of getting Twisted to work with PyObjC again soon?:
>> I'm spending a lot of time trying to figure out how to get Cocoa to=20=
>> talk to the remote server, and may have to set up XML-RPC blocking=20
>> calls to the Twisted server for now, and it's a bunch of extra work,=20=
>> and really doesn't give me the object access I'd want. Imagine=20
>> having expectedRaise() call to a remote XML-RPC service every time=20
>> the tableView calls it!
> I'd like to fix it but I'm too busy. I'm not sure when I'll have=20
> time. I don't use PyObjC+Twisted in any sort of production=20
> application right now.
I don't use Twisted at all. I'd like to, but the sheer size of it=20
scares me away :-)
X|support bv http://www.xsupport.nl/
T: +31 610271479 F: +31 204416173