[PyKDE] Using KParts

Patrick Stinson patrickkidd at gci.net
Tue Dec 21 08:25:45 GMT 2004


This worked quite well. Thanks again, troy.

I hope that my discovery of the segmentation faults that occur on some calls 
to KLibLoader.library('katepart') can help you guys, at least.

On Sunday 12 December 2004 04:38 pm, 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)
>     try:
>         ptr = offers[0]
>     except (IndexError, TypeError, ), te:
>         return
>     if writable:
>         builder = createReadWritePart
>     else:
>         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.




More information about the PyQt mailing list