On Fri, Aug 29, 2008 at 11:47 PM, Jim Bublitz <[EMAIL PROTECTED]> wrote:
> On Friday 29 August 2008 15:02, Paul Giannaros wrote:
>> KTextEditor works with an interface class -- implementors of the
>> interface subclass
>> KTextEditor::View and KTextEditor::Document, with the subclasses also
>> inheriting from any interfaces that they choose to support. This is a
>> problem -- I can't see
>> a way to cast to the required type.
>>
>> Even though I can check at run-time whether my view implements an interface
>>
>> with something like:
>> >>> document = Kate.application().documentManager().documents()[0]
>> >>> view = document.activeView()
>> >>> view.inherits('KTextEditor::ConfigInterface')
>>
>> True
>>
>> I cannot use anything to cast to the appropriate type to get at the
>> methods provided
>> by the interface.
>>
>> Is there a solution to this problem?
>
> Are the parent classes also wrapped in your module?Firstly, it's not my module: ktexteditor is part of PyKDE4! Most of the interface classes are wrapped, yes (it looks like some may be missing, though; I can see KTextEditor::AnnotationInterface exists but no sip binding for it exists according to websvn). > > If they are, you can use %ConvertToSubClassCode (CTSCC) - see it's use in > PyKDE or PyQt for examples and the sip docs (not all PyKDE classes have > inherits() available, so they use dynamic_cast; PyQt code uses inherits()). > > For example, if a call creates a QWidget but returns (in C++) a QObject, > CTSCC will "cast" the returned object to QWidget in the Python program. I'm not sure how this will help. I don't want the KTextEditor::View object to always be returned to me as a KTextEditor::ConfigInterface. I need some way to get at a ConfigInterface (and a CursorInterface, SearchInterface, etc) from a View instance. I'd be happy if View objects had a method like configInterface() to return the interface where available. > > Otherwise there are ways to cast within Python using sip functions (see the > sip docs), but they probably aren't what you want. Unfortunately not. sip.cast only lets you cast to instances of superclasses. Paul _______________________________________________ PyQt mailing list [email protected] http://www.riverbankcomputing.com/mailman/listinfo/pyqt
