[PyQt] loading arbitrary kparts
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::createPartInstanceFromQueryKParts::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? ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] loading arbitrary kparts
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 part). I also found examples like this: mimetype == KMimeType::findByURL( m_url )-name(); m_part = KParts::ComponentFactory::createPartInstanceFromQueryKParts::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. Jim ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] loading arbitrary kparts
On Mon, Oct 08, 2007 at 09:38:21AM -0700, Jim Bublitz wrote: 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. try this: --- begin code --- 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 mineType= KIO.NetAccess.mimetype (url, None); print mimeType --- end code --- 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? ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] loading arbitrary kparts
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: [EMAIL PROTECTED]:~/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: [EMAIL PROTECTED]:~/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 ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Re: [PyQt] loading arbitrary kparts
damn, it was a (insert very offensive phrase here) typo! see the posted code again... On Mon, Oct 08, 2007 at 05:21:13PM -0700, Jim Bublitz wrote: because (from the KDE API docs): Yes, I knew that, that's why I searched for the alternative and found KIO.NetAccess.mimetype. 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. 3.16.0 from debian. 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. ah, those monsters. thanks for the heads up! ___ PyQt mailing listPyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt