[PyQt] loading arbitrary kparts

Marcos Dione mdione at grulic.org.ar
Mon Oct 8 15:41:02 BST 2007


    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 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?


More information about the PyQt mailing list