Re: [Pyobjc-dev] Question on Bridging/Integration
Brought to you by:
ronaldoussoren
From: Ronald O. <ron...@ma...> - 2012-05-21 06:02:53
|
On 20 May, 2012, at 22:12, Vincent wrote: > Hi there, > > I'm new the whole PyObjC thing and have a simple document-bases app for which my goal is to all the user (personal project, so actually just me :P) to provide his/her (my) own filtering logic on a per-document basis. > > I basically have an NSSet of objects which need to be filtered based on a user-provided logic. > As the logic should not be limited to rather primitive NSPredicates I'd like to provide a barebones in-app Python editor in which the user can define his/her logic. > >> From what I've found on the web so far I know that one can subclass one's own Objective-C classes from inside Python using "objc.lookUpClass(…)". > There is however still one question that remained unanswered: > Being able to instantiate an Objective-C object from Python is neat, but still isolated. How do I expose a particular object instance from one language to the other? > After all I need to pass my Objective-C object to Python for evaluation and receive an answer from it in respose. > > A minimal sample function (as provided by the user at runtime) would look something like this: > > def shallRejectObject(object) > if object.foo(): > return True > return False > > Being totally new to PyObjC I'm thinking of some kind of reverse "objc.lookUpClass(…)" to allow me to instantiate my Python subclass from within Objective-C. Or how else would one approach this? Using Python from ObjC like this is suboptimal at the moment, mostly because I don't use PyObjC in that way. I'd define an stub class with the right interface in Objective-C with a subclass in Python that implements that interface. That way you can fetch the Python class using objc_lookUpClass (or the Foundation wrapper around that function), create an instance and then call the methods without getting compiler warnings. To expose instances you have to define an API to fetch those instances. Ronald > > Any hints? > > Thanks in advance, > Vincent > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Pyobjc-dev mailing list > Pyo...@li... > https://lists.sourceforge.net/lists/listinfo/pyobjc-dev |