[PyQt] [PyKDE] KTextEditor interface classes

Jim Bublitz jbublitz at nwinternet.com
Fri Aug 29 23:47:21 BST 2008


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?

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.

Otherwise there are ways to cast within Python using sip functions (see the 
sip docs), but they probably aren't what you want.

Jim


More information about the PyQt mailing list