Re: [Pyobjc-dev] NibLoader.py: parsing nibs at runtime
Brought to you by:
ronaldoussoren
From: Ronald O. <ous...@ci...> - 2002-11-15 18:49:08
|
While I like the idea, I feel there is a minor disadvantage to this solution: With an explicit nibwrapper.py you can easily check which methods you should implement and which outlets are available. The advantage of your approach is that you do not have to worry about updating the nibwrapper.py file when you make relevant changes to a NIB file. The additional startup time is probably not very relevant (at least at the moment, loading the frameworks pretty expensive) We could of course use a variant of mknibwrapper to generate userfriendly documentation instead of a python file. Ronald On Friday, Nov 15, 2002, at 01:09 Europe/Amsterdam, 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. > > 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 attached module lets you do this: > > > [...more imports snipped...] > from NibLoader import NibLoader, addNib > > # (the addNib() could be done elewhere, or could be done more > # concisely with a helper funciton in the NibLoader module) > addNib(os.path.join(sys.path[0], "English.lproj/MainMenu.nib")) > > class PyModel(NibLoader, NSTableDataSource): > ...etc... > > > addNib() parses a nib file and sucks the class info out of it. > NibLoader is a magic class (or rather, has a magic superclass) that > will make > sure the subclass has the right base class, and will populate it with > all the > stuff that was normally generated in the nibwrapper file. > > So far I've only tested it with the TableModel demo: it works for me. > > The NibLoader module contains a tiny test program: you can invoke it > from the > command line like so: > > % python NibLoader.py <path-to-nib> [more paths to nibs] > > 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. > > Obviously much of the code is ripped straight from objc/classnib.py. > > Useful? > > Just<NibLoader.py> |