[PyQt] loading arbitrary kparts
    Jim Bublitz 
    jbublitz at nwinternet.com
       
    Tue Oct  9 01:21:13 BST 2007
    
    
  
On Monday 08 October 2007 16:16, Marcos Dione wrote:
Running this:
from kdecore import *
from kio import *
from kparts import *
import sys
KCmdLineArgs.init (sys.argv, sys.argv[0], "testmime", "", "")
args= KCmdLineArgs.parsedArgs ()
app= KApplication ()
#app.exec_loop ()
for u in ('http://api.kde.org/3.5-api/kdelibs-apidocs/kde_gear_64.png', 
'http://jbailey.livejournal.com/41057.html'):
    url = KURL (u)
#    mime = KMimeType.findByURL(url, 0, False, False)
#    mimeType= mime.name ()
#    if mimeType=='application/octet-stream':
#        print "trying harder"
    mimeType= KIO.NetAccess.mimetype (url, None)
    print mimeType
I get:
jim at jim:~/Documents> python testMime.py
image/png
text/html
Changing it to this:
for u in ('http://api.kde.org/3.5-api/kdelibs-apidocs/kde_gear_64.png', 
'http://jbailey.livejournal.com/41057.html'):
    url = KURL (u)
    mime = KMimeType.findByURL(url, 0, False, False)
    mimeType= mime.name ()
#    if mimeType=='application/octet-stream':
#        print "trying harder"
#    mimeType= KIO.NetAccess.mimetype (url, None)
    print mimeType
I get:
jim at jim:~/Documents> python testMime.py
application/octet-stream
application/octet-stream
because (from the KDE API docs):
"This function looks at mode_t first. If that does not help it looks at the 
extension. This is fine for FTP, FILE, TAR and friends, but is not for HTTP 
( cgi scripts! ). You should use KRun instead, but this function returns 
immediately while KRun is async. If no extension matches, then
****  the file will be examined if the URL is a local file or  ****
****    "application/octet-stream" is returned otherwise.    **** "
So PyKDE appears to be working correctly here. What version of PyKDE are you 
using? Shouldn't make a difference, but if an older version you could try 
upgrading.
> > 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 part).
>
>     will try.
>
> > >     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.
>
>     I didn't get this whole. can you explain a little more?
In C++, template types (classes or functions) only cause code to be generated 
when they're used - in a typedef or when instantiated. If no code references 
the template, then the template doesn't produce any code in the library or 
application.
componentfactory.h doesn't contain anything except templates, and if nothing 
else in the KParts module references those templates, they don't produce any 
code.
PyKDE (PyQt/sip) works by providing an interface to code in .so libs. If no 
binary code is there for a template type (and in this case there isn't any 
code), there isn't anything to interface to, so it isn't possible to use 
anything from componentfactory.h in PyKDE - there's no 'there' there.
Jim
    
    
More information about the PyQt
mailing list