[Pyobjc-dev] New NibLoader.py
Brought to you by:
ronaldoussoren
From: Just v. R. <ju...@le...> - 2002-11-15 22:44:33
|
I've attached the current state of NibLoader.py. I would have checked it right in, if I wasn't getting cvs errors (I think it may be because it takes a while for new developers to get their permissions set up right, maybe it's a cron job that runs only once a day?). Lot's of things have changed, lots of cleanups. Instead if subclassing from a magic object with a magic metaclass, you now have to specify a metaclass explicitly: from AppKit import NSTableSource from AppKit.NibLoader import NibClassBuilder, loadNibFromBundle loadNibFromBundle("MainMenu") class PyModel(NSTableSource): __metaclass__ = NibClassBuilder I think this is better as you see right away that something special is going on, whereas subclassing from a magic object just looks like subclassing. I think it's good that the magic stands out. In private mail Jack and I talked about seeing nib files as something similar to Python modules, so instead of the above one would do (say): class PyModel(NSTableSource): __metaclass__ = getClassBuilder("MainMenu") However, this suggests that a nib file is a namespace. It's not. The same class definition may occur in several nibs, but at runtime there can only exist one, as Obj-C's class namespace is flat. So I think it's best/better to just keep a global dict of classes, gathered from all nibs. (The loading of nibs currently needs to be done with NibLoader.loadNib() or NibLoader.loadNibFromBundle(), but I think it would be nice to have some bootstrap code somewhere that just loads all nibs found the the app bundle.) I've added a simple command line main program, which lets you print an overview of classes in a set of nibs. I think this could satisfy Ronalds wish for a nib "documentation" viewer. It's invoked like so: python NibLoader.py <path-to-nib> [more paths to nibs] The program has one option, -t, that will run a simple test instead of printing the overview. (Style: I've mostly followed my own naming and coding style. If there's a consensus about what style the pyobj project should follow, I'd gladly adopt NibLoader to it. I have some opinions, but this gets religious real fast...) Just |