[PyKDE] Using KParts
jbublitz at nwinternet.com
Mon Dec 13 08:10:20 GMT 2004
On Sunday 12 December 2004 17:38, Troy Melhase wrote:
> On Thursday 09 December 2004 10:26 pm, Patrick Stinson wrote:
> > kparts.createReadWritePart('kwritepart') # can't remember the exact
> > syntax
> This has worked for me in the past:
> from kio import KTrader
> from kparts import createReadOnlyPart, createReadWritePart
> def buildPart(parent, query, contraint, writable=False):
> """ builds the first available offered part on the parent
> offers = KTrader.self().query(query, contraint)
> ptr = offers
> except (IndexError, TypeError, ), te:
> if writable:
> builder = createReadWritePart
> builder = createReadOnlyPart
> return builder(ptr.library(), parent, ptr.name())
> Then later, it's used like so:
> query = "Type == 'Service' and Name == 'Embedded Advanced Text Editor'"
> part = buildPart(self, 'application/x-python', query, True)
> if not part:
> print 'Ack! No part available for displaying python source'
> Hope this helps.
That looks correct to me. The only other thing I'd add is that if the
application is using a window, it should subclass KParts.MainWindow as the
main window, and not KMainWindow (which is a base class to
I'll try to verify all of this in the next day or two, and add an example to
PyKDE. The original example broke going from KDE2->3 and I never replaced it.
More information about the PyQt