Re: [Pyobjc-dev] Subclassing from NibClassBuilder-generated files
Brought to you by:
ronaldoussoren
From: Martina O. <Ma...@Oe...> - 2003-12-02 21:11:45
|
Hi Jordan, > I tried creating another file for CurrencyConverter which imported > CurrencyConverter.py's classes (which were renamed to _Converter and > _ConverterController), subclassed them, and attempted to call > runEventLoop() from there, but the runtime is complaining that the > classes already exist: > > File "Resources/t.py", line 6, in ? > class Converter(_Converter): > objc.error: Class already exists in Objective-C runtime > > Here's t.py: > > *snip* > from PyObjCTools import NibClassBuilder, AppHelper > > from CurrencyConverter import Converter as _Converter This doesn't rename the ObjC class 'Converter'. (Actually, AFAIK it doesn't rename the python class either, it only makes the class available under a new nickname) > class Converter(_Converter): > pass You are trying to create a new class Converter, which inherits from the existing Python/objc class Converter. Thus PyObjC tries to make the new Python class also known to the objc runtime, but this fails due the name conflict with the existing class: > objc.error: Class already exists in Objective-C runtime Contrary to Python classes, objc classes don't live in modules. On the objc side, all classes live in a single namespace. CurrencyConverter.Converter (also known as t._Converter) and t.Converter would both map to the same objc class Converter. > If this is in fact a problem, how does one get around this? Perhaps > I'm just used to wxglade, where it exports classes to be used > elsewhere, knowing that they will be generated often. If it's > something else, please let me know :) You don't need to re-run NibClassBuilder as a script after changing the nib. Usually you run it once to create a template from which you can work on, to save some typing. If you just added one or two new actions in IB, it is probably not worth to go re-run, you can just type in the new method name(s) by hand. If you made a lot of changes in IB, re-running NibClassBuilder may save some typing. For example, just let NibClassBuilder write the class to stdout, and copy the new declarations from the terminal window into your script. Note that the technique which you described wouldn't save you the typing/copying, either (if it would work). You would have to type/copy the same action names into your subclass... ciao Martina |