[PyQt] [PyKDE] KTextEditor interface classes

Paul Giannaros paul at giannaros.org
Sat Aug 30 02:09:09 BST 2008


On Sat, Aug 30, 2008 at 1:34 AM, Jim Bublitz <jbublitz at nwinternet.com> wrote:
> On Friday 29 August 2008 16:19, Paul Giannaros wrote:
>> On Fri, Aug 29, 2008 at 11:47 PM, Jim Bublitz <jbublitz at nwinternet.com>
> 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).
>
> I dropped it from PyKDE4 to make the package smaller - Simon apparently added
> it back.

I remember. The Kate bindings aren't (and certainly shouldn't be) in there, but
as KTextEditor is a part of kdelibs I think it should be part of the standard
distribution.

>
> You need to communicate with Simon Edwards and a) get the classes you need
> into the bindings and b) get the CTSCC blocks generated (it's done
> automatically via the project file).
>
>> > 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.
>
> Right - that's what %ConvertToSubClassCode will do for you. In PyKDE the code
> in the sip file (C++ code) tries to dynamic_cast to a subclass type and will
> return the most-derived type it can find.  I'm assuming CursorInterface,
> SearchInterface, etc are subclasses of ConfigInterface. It seems to me that's
> what you want, but maybe I'm misunderstanding.

No, they're not. All of the Interface classes are simple QObject-inheriting
classes. When a project wants to implement the KTextEditor interface
they'll do something like:

class MyInternalView : public KTextEditor::View, public Interface1,
public Interface2, public Interface3 ....

A pointer to a MyInternalView object would be passed around to plugins and
anything else using the KTE API cast as a View.

I hope that makes sense.


>
> If that's not what you want, then it seems you'll have to write C++ code and
> add it to the bindings, which is not that hard to do.
>

If I'm not mistaken then that's what I'll need to. I'll get into
contact with Simon
Edwards -- I'm not sure what his auto-generation process is like and therefore
how he wants patches.

Thanks for your help Jim,

Paul


More information about the PyQt mailing list