Re: [Pyobjc-dev] Controller Layer
Brought to you by:
ronaldoussoren
From: Ronald O. <ous...@ci...> - 2003-12-23 22:01:03
|
I finally found some time to look into this, and this seems to be caused by an implementation trick in Cocoa. For some reason the instance of 'Converter' is an instance of 'NSNotifying_Converter' during the call to 'getAmount', and 'getAmount' is not recognized as a Python method which is causing infinite recursion. The class of the object is probably changed to implement some feature of KVO. This is fixable by using libffi more agressively, although this may have other negative effects. E.g., we should use libffi to find the exact Python function to the method stub, instead of looking up the Python method in the class when it is called. Ronald On 2 dec 2003, at 1:48, Carlos Phillips wrote: > Hi, > > I sent the following email to Bill (b.bum): > >> There is something fundamental about the key-value binding that I >> don' t understand. I have been using it extensively in objective-c, >> but I can't seem to be able to use it to connect to a nib in PyObjC. >> Here is a sample python class I use: >> >> # Converter.py: >> import objc >> >> class Converter(objc.runtime.NSObject): >> def getAmount(self): >> return "1" >> if __name__ == "__main__": >> AppHelper.runEventLoop() >> >> >> Now I create a MainMenu.nib which has a window with a single >> NSTextField. In the nib, I instantiate an empty definition of >> Converter in the nib. Converter is defined as a subclass of NSObject. >> I then create an instance of NSController, add an "amount" key and >> bind the value of the text field to it. Finally, I connect the >> Converter instance to the "content" outlet of the NSController. This >> is the exact setup I used in an obj-c version of this test. >> >> I run the following buildapp.py script to make this into a program >> >> from bundlebuilder import buildapp >> buildapp( >> mainprogram = "Converter.py", >> resources = ["English.lproj" ], >> nibname = "MainMenu", >> ) >> >> The result is a sementation fault. What am I doing wrong? > > He responded as follows: > >> This'd be an objc/c problem -- if the app is crashing and giving you >> the "submit crash report" panel, then click "submit" and copy/paste >> the backtrace found in the resulting window. If not, have a look in >> ~/Library/Logs/ and see if there is a log there. >> >> Otherwise, you'd need to run under gdb. >> >> Try adding... >> >> def automaticallyNotifiesObserversForKey_(self, aKey): >> return NO >> >> ... to your class and see if that fixes the problem. Also, make sure >> you are running pyobjc based on the latest source from CVS -- there >> have been many updates that are 10.3 specific. >> >> Finally, we should continue this on pyobjc-dev. I'm really busy @ >> Apple and will likely not have time to answer you in the coming days >> -- but the folks on pyobjc-dev will answer and they are really >> friendly/knowledgeable. > > Overloading the method did in fact fix the problem. I thought this > might be useful to someone else. > > Carlos > > > > ------------------------------------------------------- > This SF.net email is sponsored by: SF.net Giveback Program. > Does SourceForge.net help you be more productive? Does it > help you create better code? SHARE THE LOVE, and help us help > YOU! Click Here: http://sourceforge.net/donate/ > _______________________________________________ > Pyobjc-dev mailing list > Pyo...@li... > https://lists.sourceforge.net/lists/listinfo/pyobjc-dev > |