[Pyobjc-dev] Objc-agnostic model classes
Brought to you by:
ronaldoussoren
From: Jordan K. <jo...@kr...> - 2004-08-12 23:15:26
|
Perhaps my last mail was asking too many questions, so I'll keep this=20 one simple. I'm attempting to follow Hillegass' RaiseMan project from Cocoa=20 Programming for OS X (2nd Ed), using bindings, but in PyObjc instead. =20= The below code works just fine, with addition, editing, and deletion=20 all working fine with no errors. Person.py: """ from Foundation import * import objc class Person (NSObject): def init(self): # This works without super(), do I need it? # super(Person, self).init() self._expectedRaise =3D 5.0 self._personName =3D 'New Person' return self =09 def expectedRaise(self): return self._expectedRaise def setExpectedRaise_(self, x): self._expectedRaise =3D x setExpectedRaise_ =3D objc.accessor(setExpectedRaise_) def personName(self): return self._personName =09 def setPersonName_(self, aName): self._personName =3D aName setPersonName_ =3D objc.accessor(setPersonName_) """ However, in another project, I'm trying to have a resuable, pure-Python=20= model class that can be used verbatim in the Twisted server to which=20 this Cocoa app will communicate, with the model objects ultimately=20 residing on said server (using Twisted's cacheable 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 this?=20= Should I simply override setValue:forKey: and valueForKey: and access=20= the pure-Python model's methods that way? Will this bugger up=20 nil-related attribute setting =E0 la setNilValueForKey: ? 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(), or=20= str(personName) every time, or should I write my own? One more obligatory question, where I don't mean to offend, and I know=20= that few people in this world are capable of fixing it, but: Any hope=20= of getting Twisted to work with PyObjC again soon?: http://www.twistedmatrix.com/users/roundup.twistd/twisted/issue648 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 having=20= expectedRaise() call to a remote XML-RPC service every time the=20 tableView calls it! Thanks in advance, J.= |