Re: [Pyobjc-dev] NibLoader.py: parsing nibs at runtime
Brought to you by:
ronaldoussoren
From: <bb...@ma...> - 2002-11-15 16:19:14
|
On Thursday, November 14, 2002, at 07:09 PM, Just van Rossum wrote: > Today, instead of learning how to do useful things with Cocoa <wink>, > I wrote a > replacement for mknibwrapper/objc.classnib.py, that does the same > thing at > runtime, making nibwrapper.py files superfluous. Excellent. > This abviously has some startup time hit, but it seems quite quick. > Not that I > think that having to generate nibwrapper.py files is all that bad, I > was just > looking for an opportunity to learn a thing or two, eg. about > metaclasses... The startup is minor in comparison to other startup issues and to the unarchival of the object graph contained in the NIB [I would think]. Small price to pay in return for one less dependency within the development environment. > It will parse all nibs specified and will build dummy test classes for > all found > nib classes and print some blurb to stdout. I've tested this on a few > nibs found > in apps that came with the OS as well as with all the nibs in the > Examples > folder, and apart from some classes that don't seem to have a > SUPERCLASS > attribute, building the test classes seems to work. If a class doesn't have a SUPERCLASS, it should default to NSObject, I would think. I'll look into this as I convert some of my projects over to using NibLoader. > Obviously much of the code is ripped straight from objc/classnib.py. > > Useful? Very. Added to the CVS repository as Lib/AppKit/NibLoader.py. I modified it to skip FirstResponder -- a class does not need to be created for FirstResponder (target/action directed at first responder indicates to the event handling system that the action should be sent to the first object in the responder chain that responds to the action). I also added an addNibFromBundle() function that can be used like this: NibLoader.addNibFromBundle( "MainMenu.nib" ) It takes an optional second argument if you want to point it at a particular bundle or framework; defaults to NSBundle.mainBundle(). It uses NSBundle's pathForResource:ofType: method to find the NIB and, as such, will automatically load the NIB of the correct language in localized apps. Ronald: Does this supersede classnib? I.e. should classnib be removed? b.bum b.bum No Chunks... ... No Foul! |