[PyKDE] KParts

Jim Bublitz jbublitz at nwinternet.com
Mon Sep 29 22:08:00 BST 2003


On Monday September 29 2003 10:35, David Boddie wrote:
> On Sun, 28 Sep 2003 10:17:04, "Ted Shab" wrote:
> > Has anyone written a KPart from PyKDE?  Is it
> > straightforward?  What are the major issues?

> The term KPart appears to cover a multitude of sins...

I believe they're either KPart::ReadOnlyPart or 
KPart::ReadWritePart descendants.

KParts are also different in KOffice than the rest of KDE if I 
recall correctly ...

> I looked at the example at

>http://developer.kde.org/documentation/tutorials/dot/writing-plugins.html

> and have been trying to produce a Python equivalent. At the
> moment I'm stuck where the author casts a QObject to a
> KHTMLPart. I presume that there's a way of pursuading
> PyKDE/sip to give me a Python KHTMLPart from the Python
> QObject I receive but I'm beginning to get concerned that it's
> only possible to do this in C++. Still, that hopefully
> wouldn't be so hard to implement.

If I read the tutorial correctly (I'm in kind of a rush at the 
moment), that's on the loading side - PyKDE can already load 
KParts. The C++ code is in part.sip, at the end. There is an 
example in the examples/ directory (pyParts.py) - the KTrader 
stuff is broken (doesn't come up with an image viewer to load), 
but the KParts stuff should still work. If you give it a KPart 
it can actually find and load, it should work. I think I'd get 
that working before trying to write the part to be loaded in 
Python.

createReadOnlyPart/createReadWritePart (which are PyKDE specific 
global functions) do all of the work and return a correctly 
typed instance (since about PyKDE3.3 or maybe earlier).  Those 
are written to do the steps the docs (and apparently the 
tutorial) require to load the part and cast it. 

The error I always make is forgetting to subclass the app's main 
window from KParts::MainWindow and making sure I call that in 
the __init__ method as well (instead of KMainWindow) -- hard to 
debug.

There are three possible scenarios:

Application    KPart to load
========    ==========
Python          C++              should work
C++             Python           not yet - need .so
Python          Python           not yet, but should work on the          
                                         loading side as is

In the last case, I'd still use the C++ mechanisms rather than 
some Python specific solution for situations where both are in 
Python.

Jim




More information about the PyQt mailing list