[PyQt] loading arbitrary kparts

Jim Bublitz jbublitz at nwinternet.com
Mon Oct 8 17:38:21 BST 2007

On Monday 08 October 2007 07:41, Marcos Dione wrote:
>     hi all. I've been playing with kparts a little and now I hit a wall.
> I try to load the proper part for a given url. the code I have looks
> like this:
> mime= KMimeType.findByURL(url, 0, False, False)
> mimeType= mime.name ()
> # this trick I saw in
> #
> http://lxr.kde.org/source/KDE/kdegraphics/kuickshow/src/kuickshow.cpp?v=3.5
>-branch#166 if mimeType=='application/octet-stream':
>     mineType= KIO.NetAccess.mimetype (url, self);
> ptr= KTrader.self().query(mimeType, "'KParts/ReadOnlyPart' in
> ServiceTypes")[0] part= createReadOnlyPart (ptr.library (), tab, ptr.name
> ())
>     no matter what url it is, seems like I always get mimeType as
> "application/octet-stream", and the part it loads it's an hex editor. I
> tried to find other examples of findByUrl(), but the only one that could
> be interesting (in konqueror) is very deep and can't wrap my head around
> it.

I'm using KIO.NetAccess.mimeType in a PyKDE4 application and it works fine 
there - there could be some difference to the PyKDE 3 version. It would help 
if you'd provide a short example program that exhibits the problem so I can 
see if there's some other problem in the surrounding code triggering the 
mimetype problem.

You could also try to use KRun, just as a *test* to see if it will pick up the 
mime type correctly (it launches an application though - doesn't load a 

>     I also found examples like this:
> mimetype == KMimeType::findByURL( m_url )->name();
> m_part =
> KParts::ComponentFactory::createPartInstanceFromQuery<KParts::ReadOnlyPart>
>( mimetype, QString::null, this, 0, this, 0 );
>     but I can't find the ComponentFactory namespace in pykde, and I'm
> not sure it would fix my problem. so, what am I missing?

ComponentFactory consists of only templates, so there isn't any code to wrap, 
unless the templates are instantiated via a typedef somewhere else in 
kdelibs. KParts.Factory is implemented though.


More information about the PyQt mailing list