[Pyobjc-dev] Silly Cocoa question
Brought to you by:
ronaldoussoren
From: Jack J. <Jac...@cw...> - 2003-06-17 14:11:37
|
Folks, I think I'm 90% done with the example of embedding Python in an existing ObjC application, but I need a little Cocoa help. Let me first say how I'm doing it. I start with a perfectly normal ObjC PB Project (SimpleComboBox). I add three files to this, PythonGlue.h and PythonGlue.m to Classes, PythonGlue.py to Resources, and I add Python.framework to the frameworks. PythonGlue.{h,m} implement a slightly magic singleton class. When instantiated this class initializes the Python interpreter, it uses Foundation magic to find our resource folder and it runs the file PythonGlue.py from there. The latter file simply adds the resource folder to sys.path and imports any modules found there. Now we only need to get the PythonGlue class instantiated and everything is hunky-dory. Turns out this is easy: instantiate it in MainMenu.nib and set that object to be the application's delegate. Presto, everything works! You simply add PyObjC source files to your Resources section and the classes are automatically available. But now I'm stuck with a silly Cocoa question. I've added a class and instance ITunesCommunication to the CDInfoDocument.nib file, added an askITunes: action to this class, instantiated the class, added an "ask iTunes" button and connected the button to the askITunes method of the instance. Created the Python code and it is indeed called. But in the ITunesCommunication.askITunes_() method the only thing I get is a reference to the button that was pressed. What I need is the CDInfoDocument object, the File Owner for this NIB file (it's an NSDocument subclass). I assume there's a way to go from the button to the window to the document, but I don't know enough Cocoa to do this. Can anyone help? -- Jack Jansen, <Jac...@cw...>, http://www.cwi.nl/~jack If I can't dance I don't want to be part of your revolution -- Emma Goldman |