Thread: [Pyobjc-dev] Altered classes
Brought to you by:
ronaldoussoren
From: Deirdre S. M. <de...@de...> - 2001-05-11 08:10:55
|
I'm not sure I'm going about the hack, slash and burn right, but it sure seems that ObjC classes that are defined in one framework and altered in another do not correctly have their methods updated. An example: In the Foundation framework, NSBundle is defined and, given Steven's example, those known methods of NSBundle seem to work. In the AppKit framework, NSBundle is extended to add several methods, which don't seem to work. An example: Nib = rt.NSBundle.loadNibNamed_owner("MainMenu.nib", Doc) ...doesn't work, but... foundationKit = rt.NSBundle.bundleWithPath_( '/System/Library/Frameworks/Foundation.framework').load() ...does. Furthermore, I can't seem to get it to want to list all of NSBundle's methods, so I'm not sure I'm asking for the right thing. Any help in reducing the pain of beating my head against the wall will of course reduce the amount of codeine this process is consuming. :) |
From: Bill B. <bb...@CO...> - 2001-05-11 13:23:40
|
Deirdre, Quick question; shouldn't "loadNibNamed_owner" be "loadNibNamed_owner_" in this context? b.bum On Friday, May 11, 2001, at 04:10 AM, Deirdre Saoirse Moen wrote: > I'm not sure I'm going about the hack, slash and burn right, but it > sure seems that ObjC classes that are defined in one framework and > altered in another do not correctly have their methods updated. > > An example: In the Foundation framework, NSBundle is defined and, given > Steven's example, those known methods of NSBundle seem to work. > > In the AppKit framework, NSBundle is extended to add several methods, > which don't seem to work. An example: > > Nib = rt.NSBundle.loadNibNamed_owner("MainMenu.nib", Doc) > > ...doesn't work, but... > > foundationKit = rt.NSBundle.bundleWithPath_( > '/System/Library/Frameworks/Foundation.framework').load() > > ...does. > > Furthermore, I can't seem to get it to want to list all of NSBundle's > methods, so I'm not sure I'm asking for the right thing. > > Any help in reducing the pain of beating my head against the wall will > of course reduce the amount of codeine this process is consuming. :) > _______________________________________________ > Pyobjc-dev mailing list > Pyo...@li... > http://lists.sourceforge.net/lists/listinfo/pyobjc-dev |
From: Deirdre S. M. <de...@de...> - 2001-05-11 16:27:26
|
>Deirdre, > > Quick question; shouldn't "loadNibNamed_owner" be >"loadNibNamed_owner_" in this context? I must confess - I don't understand the distinction and I could have sworn that I'd tried it both ways, but it DOES work. ::sigh:: Meaning that it doesn't give an error, not necessarily that it does what it's supposed to. I *used* to be awake when I was coding at 2 a.m., but I must be getting old. :) I *am* getting an error, upon subsequent launches, of: kCGSErrorNoneAvailable : CGSOrderFrontConditionally: Process not found ...and the Window that was defined in code is inactive (it shows, but doesn't accept clicks or anything). Meaning I'm going to have to log out or something to clean it up. Ugh. -- _Deirdre Stash-o-Matic: http://weirdre.com http://deirdre.net Macintosh Developer (seeking work): Will work for Cocoa "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams |
From: Bill B. <bb...@CO...> - 2001-05-11 17:19:35
|
Basically, pyobjc mangles the ObjC selector names by substituting _ for each : (because : is reserved in python). The second problem sounds more like an Appkit initialization problem-- did you have a look at Steve's AppKit example? Make sure something like that works first, then try loading the NIB. If the NIB loading is still broken, then we have an additional initialization phase at the AppKit level we haven't taken care of yet. As well, there will be a certain line beyond which we really, really, really need to have the Main Event Loop running to do anything from Python to the Appkit... Has anyone tried creating a Python object and setting it as NSApp's delegate, then seeing if you could grab notifications?? b.bum On Friday, May 11, 2001, at 12:26 PM, Deirdre Saoirse Moen wrote: >> Deirdre, >> >> Quick question; shouldn't "loadNibNamed_owner" be >> "loadNibNamed_owner_" in this context? > > I must confess - I don't understand the distinction and I could have > sworn that I'd tried it both ways, but it DOES work. ::sigh:: Meaning > that it doesn't give an error, not necessarily that it does what it's > supposed to. > > I *used* to be awake when I was coding at 2 a.m., but I must be getting > old. :) > > I *am* getting an error, upon subsequent launches, of: > kCGSErrorNoneAvailable : CGSOrderFrontConditionally: Process not found > > ...and the Window that was defined in code is inactive (it shows, but > doesn't accept clicks or anything). Meaning I'm going to have to log > out or something to clean it up. Ugh. > > -- _Deirdre Stash-o-Matic: http://weirdre.com > http://deirdre.net > Macintosh Developer (seeking work): Will work for Cocoa > "I love deadlines. I like the whooshing sound they make as they fly by." > - Douglas Adams > > _______________________________________________ > Pyobjc-dev mailing list > Pyo...@li... > http://lists.sourceforge.net/lists/listinfo/pyobjc-dev |
From: Yves S. <yst...@uw...> - 2001-05-11 17:28:56
|
Hi, Have tried that. Doesn't work. Traced it down to the mangling from objc back to python but couldn't make further progress with it. Yves > Has anyone tried creating a Python object and setting it as NSApp's > delegate, then seeing if you could grab notifications?? |
From: Deirdre S. M. <de...@de...> - 2001-05-11 20:13:42
|
>Basically, pyobjc mangles the ObjC selector names by substituting _ >for each : (because : is reserved in python). I guess what I don't understand is why the *trailing* underscore. I did understand the underscore bit though. >The second problem sounds more like an Appkit initialization >problem-- did you have a look at Steve's AppKit example? Make sure >something like that works first, then try loading the NIB. If the >NIB loading is still broken, then we have an additional >initialization phase at the AppKit level we haven't taken care of >yet. Yes, I've been working from that example and modifying it. >As well, there will be a certain line beyond which we really, >really, really need to have the Main Event Loop running to do >anything from Python to the Appkit... Understandable. In looking through AppKit, it seems that it loads all the stuff prior to the main loop, but I could be wrong. Basically I was trying it before running the app, but maybe that's the wrong approach. If you look at the Main file from an existing PB project, this is what it looks like these days: #import <Cocoa/Cocoa.h> int main(int argc, const char *argv[]) { return NSApplicationMain(argc, argv); } Maybe the Nib loading problem is from trying to use something other than that specific function? Unfortunately, in the example below, it doesn't exist: import pyobjc import sys rt = pyobjc.runtime def main(): pool = rt.NSAutoreleasePool() # Load Application Framework: foundationKit = rt.NSBundle.bundleWithPath_( '/System/Library/Frameworks/Foundation.framework').load() appKit = rt.NSBundle.bundleWithPath_( '/System/Library/Frameworks/AppKit.framework').load() Doc = rt.NSDocument.alloc() Nib = rt.NSBundle.loadNibNamed_owner_("MainMenu.nib", Doc) # print Nib return rt.NSApplicationMain(len(sys.argv), sys.argv) if __name__ == '__main__' : main() >Has anyone tried creating a Python object and setting it as NSApp's >delegate, then seeing if you could grab notifications?? Since people have tried this, I'd be interested in what *everyone* has tried, what did work and what didn't. I can make a coherent document out of it and then maybe that will open the door for other "bang and slash" people to try and figure out stuff. Then it won't be so lonely here. :) -- _Deirdre Stash-o-Matic: http://weirdre.com http://deirdre.net Macintosh Developer (seeking work): Will work for Cocoa "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams |
From: Bill B. <bb...@CO...> - 2001-05-11 20:26:17
|
The original method was something like "loadNibNamed:owner:" -- i.e. it takes two arguments and has two :'s. The Python mangled version is "loadNibNamed_owner_", as a result. There is a lot more that goes on ApplicationMain and in the startup of the application than you might otherwise expect given evidence at runtime. In particular, there is all kinds of binding to the Finder and the WindowServer, etc... I know why the Application delegate stuff isn't working and how to fix it. I'll try to do so on the train home tonight and commit the code tonight/tomorrow. It ain't pretty but, thankfully, I solved the problem before. (If interested, see the mssh project-- http://www.codefab.com/pub/unsupported. While there, see NoisyAppKit-- it spews everything that happens at app launch on mach ports...). b.bum On Friday, May 11, 2001, at 04:12 PM, Deirdre Saoirse Moen wrote: >> Basically, pyobjc mangles the ObjC selector names by substituting _ >> for each : (because : is reserved in python). > > I guess what I don't understand is why the *trailing* underscore. I did > understand the underscore bit though. > >> As well, there will be a certain line beyond which we really, really, >> really need to have the Main Event Loop running to do anything from >> Python to the Appkit... > > Understandable. In looking through AppKit, it seems that it loads all > the stuff prior to the main loop, but I could be wrong. Basically I was > trying it before running the app, but maybe that's the wrong approach. > > If you look at the Main file from an existing PB project, this is what > it looks like these days: > > #import <Cocoa/Cocoa.h> > > int main(int argc, const char *argv[]) > { > return NSApplicationMain(argc, argv); > } > > Maybe the Nib loading problem is from trying to use something other > than that specific function? > > Unfortunately, in the example below, it doesn't exist: > > import pyobjc > import sys > > rt = pyobjc.runtime > > def main(): > > pool = rt.NSAutoreleasePool() > # Load Application Framework: > foundationKit = rt.NSBundle.bundleWithPath_( > '/System/Library/Frameworks/Foundation.framework').load() > appKit = rt.NSBundle.bundleWithPath_( > '/System/Library/Frameworks/AppKit.framework').load() > > Doc = rt.NSDocument.alloc() > Nib = rt.NSBundle.loadNibNamed_owner_("MainMenu.nib", Doc) > # print Nib > > return rt.NSApplicationMain(len(sys.argv), sys.argv) > > if __name__ == '__main__' : > main() > > >> Has anyone tried creating a Python object and setting it as NSApp's >> delegate, then seeing if you could grab notifications?? > > Since people have tried this, I'd be interested in what *everyone* has > tried, what did work and what didn't. I can make a coherent document > out of it and then maybe that will open the door for other "bang and > slash" people to try and figure out stuff. Then it won't be so lonely > here. :) > > -- _Deirdre Stash-o-Matic: http://weirdre.com > http://deirdre.net > Macintosh Developer (seeking work): Will work for Cocoa > "I love deadlines. I like the whooshing sound they make as they fly by." > - Douglas Adams |
From: Steven D. M. <sd...@mi...> - 2001-05-12 02:09:22
|
On Fri, 11 May 2001, Bill Bumgarner wrote: > There is a lot more that goes on ApplicationMain and in the startup of > the application than you might otherwise expect given evidence at > runtime. In particular, there is all kinds of binding to the Finder > and the WindowServer, etc... The objc runtime has been released as part of Darwin. It's a pity they don't release the code for ApplicationMain too. It's obvious that LOTS more is going on than what's documented. (And it looks like it's going to be quite a while before Apple fills some of the holes and "To Be Determined"'s in the docs! That's the main thing I like about open source -- even more than the price. In my VMS days, DEC gave us a microfiche of the VMS sources -- very unlikely that I was going to type it all in and steal their code -- but it was nice to know that it was POSSIBLE, even if difficult to find an answer!) > I know why the Application delegate stuff isn't working and how to fix > it. I'll try to do so on the train home tonight and commit the code > tonight/tomorrow. It ain't pretty but, thankfully, I solved the > problem before. (If interested, see the mssh project-- > http://www.codefab.com/pub/unsupported. While there, see NoisyAppKit-- > it spews everything that happens at app launch on mach ports...). This is good news. But I'll probably still try building a debuggable objc-runtime from Darwin sources -- it still may come in handy to be able to step across the bridge in debugging! -- Steve Majewski |
From: Deirdre S. M. <de...@de...> - 2001-05-12 04:47:05
|
>The original method was something like "loadNibNamed:owner:" -- i.e. >it takes two arguments and has two :'s. The Python mangled version >is "loadNibNamed_owner_", as a result. Doh! Of course. >There is a lot more that goes on ApplicationMain and in the startup >of the application than you might otherwise expect given evidence at >runtime. In particular, there is all kinds of binding to the >Finder and the WindowServer, etc... I knew it. Voodoo. :) >I know why the Application delegate stuff isn't working and how to fix it. Neat. :) >I'll try to do so on the train home tonight and commit the code >tonight/tomorrow. It ain't pretty but, thankfully, I solved the >problem before. (If interested, see the mssh project-- >http://www.codefab.com/pub/unsupported. While there, see >NoisyAppKit-- it spews everything that happens at app launch on mach >ports...). -- _Deirdre Stash-o-Matic: http://weirdre.com http://deirdre.net Macintosh Developer (seeking work): Will work for Cocoa "I love deadlines. I like the whooshing sound they make as they fly by." - Douglas Adams |
From: Steven D. M. <sd...@mi...> - 2001-05-12 00:30:06
|
On Fri, 11 May 2001, Bill Bumgarner wrote: > Has anyone tried creating a Python object and setting it as NSApp's > delegate, then seeing if you could grab notifications?? Yes. I haven't been able to get them to work. I had a variant of HelloWorld -- actually based on LBW (LittleButtonMouse) but creating a Python class instance to register as a delegate. Registering the delegate seems to work but it never gets called. After this discussion of name mangling, I was just wondering if I misnamed the methods in Python: "applicationShouldTerminate_" , etc. I tried a simpler program using my own defined notifications and posting it myself so I had more control over what was going on -- it gets a bus error after posting the notification. I tried running it under gdb to see if I could find what was wrong -- my conclusion from that is that I'm going to have to build an objc-runtime from Darwin sources with debugger info and sources online so that I can step thru the objc-runtime code -- which is where things seem to go wrong. ( Not that it's the objc-runtime -- I'm pretty sure the problem is pyobjc-runtime, but to find that bug I think I need to back up from the error in the objc-runtime. ) -- Steve Majewski ( getting more and more sold on the rewrite idea! ) |
From: Steven D. M. <sd...@mi...> - 2001-05-12 01:53:21
|
[ Jon Harald also asked me directly about Nibs. You might want to subscribe to the pyobjc-dev mailing list at sourceforge, where we're discussion some of these problems. The short answer is that pyobjc isn't quite ready for prime-time AppKit apps yet -- there are a couple of important features that either don't work correctly, or we haven't figured out how to get them to work. We're also considering writing off this version as an experiment (it's pretty ancient both in it's objc and it's python features) and starting over with a better design. You're not going to get a useful AppKit GUI app writting this path, but you're likely to learn quite a bit about objective-C and Python internals and runtime if you stick around. ] Here is the **Jython** version of a program which sort-of-works: It is able to load the nib file from the Temperature Converter java tutorial or the Currency Converter objective-c tutorial. ( With a few less errors/warnings written to the terminal running the Java app I believe. ) It loads and instatiates the window from the Nib file, and all of the default behaviour, but none of the special behavior works. (i.e. You can move the window around, enter text, tab to next field, but clicking convert button for example, does nothing.) ---- from com.apple.cocoa.foundation import * from com.apple.cocoa.application import * MyApp = None _pools = [] tpath = './TempConverter/build/TempConverter.app' cpath = './CurrencyConverter/build/CurrencyConverter.app' def xxx(): print NSBundle.allFrameworks() def Pool(): global _pools tmp = NSAutoreleasePool.push() _pools.append(tmp) return tmp def App(): global MyApp MyApp = NSApplication.sharedApplication() return MyApp def Bundle( path=cpath ): return NSBundle.bundleWithPath( path ) xxx() pool = Pool() myapp = App() bndl = Bundle() nib = NSApplication.loadNibFromBundle( bndl, 'MainMenu', myapp ) if __name__ == '__main__' : myapp.run() ---- Note that the Java AppKit API has NSApplication.loadNibFromBundle( bundle, name, owner ) The bundle is created with a path, and the Nib is inside that bundle. In objective C, the equivalent methods are NSBundle additions, not NSApplication methods. ( Java doesn't have categories -- I assume that is one of the reasons for the change. Objective-C can load additional methods for an already defined class, and AppKit adds several methods to several existing Foundation classess. ): + loadNibFile:externalNameTable:withZone: + loadNibNamed:owner: - loadNibFile:externalNameTable:withZone: (That's NSBundle.loadNibFile_externalNameTable_withZone_() in Python.) +loadNibNamed:owner: just expects a nib file name, not a full path. It looks in the mainBundle, which for my python turns out to be "/usr/local/bin" . So that one doesn't work. For the others: I think I've tried both the class and instance methods. Neither works -- I get a number back which I haven't been able to interpret as any meaningful error code. The class method takes a complete pathname -- the instance method, I think, wants only a name and has a default search path. I've been passing an empty dictionary. ( Maybe this has to be filled for it to work -- I was hoping, as with the Jython code, to get at least partial results without it.) I've been getting the zone from the zone method of my NSApp instance. I'm not absolutely positive I've tried all the possible likely legal combinations. BTW: A lot of the other docs on Nib loading are missing ("To Be Determined" ) I'm not at all experienced in doing this from objective-C -- I think I ought to give it a try that way and make sure that I can figure out the correct combination without the worry of the python-objc bridge getting in the way. Then, translate that working code to Python. This is not "official" work (although, if it could be made to work, I could more easily justify the time -- it's a chicken and egg management problem! ;-) -- so it's fighting for my limited spare time and intermittently hacking on it hasn't made for sustained progress! -- Steve Majewski |
From: Steven D. M. <sd...@mi...> - 2001-05-12 00:50:42
|
On Fri, 11 May 2001, Deirdre Saoirse Moen wrote: > Furthermore, I can't seem to get it to want to list all of NSBundle's > methods, so I'm not sure I'm asking for the right thing. dir(runtime.NSBundle) only shows: ['Class', 'isClass', 'isInstance'] it doesn't show the class methods as it would for a Python Class. The pyobjc runtime doesn't keep a list of methods, but, after unmangling the python name to objc, it tests that the object respondsToSelector: Deirdre -- you might want to look at the section on proxies in the objective-C PDF book in the Mac Developer docs to get an idea about what's going on in the bridge and why. I posted some notions earlier about adding more reflective abilities to pyobjc. www.neodata-inc.com has a class introspector app which I also built as a pyobjc loadable bundle, so you can get info about a classes methods. But this is something, which if there is a grand rewrite, ought to be builtin to the runtime, so they give the same sort of reflection info that Python classes give. -- Steve Majewski |