One possible aproach that I can see (but have not tested) is to create
a new class inherrited from QTextBrowser and overload the loadResource function in a way where you check for the names you are interested in and resolve them.
For example like this (again not tested)
Qt Code:
{ QImage correctImage; //lookup the correct QImage from a cache } else { } }
Qt Code:
Disclaimer: Shot from the Hip, not tested...might be completely the wrong track
------------------------------------------------------------------------from PyQt4 import QtCore,QtGui
import urllib, os, md5
class PBrowser(QtGui.QTextBrowser):
def loadResource(self, type, name):
url=unicode(name.toString())
ret=QtCore.QVariant()
if url.startswith('http://'):
dn=os.path.expanduser('~/.bartleblog/cache/')
if not os.path.isdir(dn):
os.mkdir(dn)
m=md5.new()
m.update(url)
fn=os.path.join(dn,m.hexdigest())
if not os.path.isfile(fn):
urllib.urlretrieve(url, fn)
ret=QtGui.QTextBrowser.loadResource(self, type, QtCore.QUrl(fn))
else:
ret=QtGui.QTextBrowser.loadResource(self, type, name)
return ret
No comments:
Post a Comment