[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: [PyQt] Custom webkit protocol example not working anymore?
From: Henning_Schröder <henning.schroeder () gmail ! com>
Date: 2012-01-30 12:09:05
Message-ID: CAOZLMt-jVcYBRLwQFBiN5b6yvEgvbFNoY5oizhreXwv7U-QTzQ () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
Hello,
I tried
http://diotavelli.net/PyQtWiki/Using%20a%20Custom%20Protocol%20with%20QtWebKit
(I attached the code).
Unfortunately I do not see anything on the page after clicking the link
with the new protocol.
Has anything changed or is it a bug in the version I used (PyQt 4.8.3, sip
4.12.1) ?
Regards
Henning
[Attachment #5 (text/html)]
Hello,<br>I tried <a \
href="http://diotavelli.net/PyQtWiki/Using%20a%20Custom%20Protocol%20with%20QtWebKit"> \
http://diotavelli.net/PyQtWiki/Using%20a%20Custom%20Protocol%20with%20QtWebKit</a><br>(I \
attached the code).<br>Unfortunately I do not see anything on the page after clicking \
the link with the new protocol.<br>
Has anything changed or is it a bug in the version I used (PyQt 4.8.3, sip 4.12.1) ? \
<br><br>Regards<br>Henning<br><br>
--20cf30776079b02b6c04b7bdb780--
["testwkprotocol.py" (text/x-python)]
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Code from http://www.diotavelli.net/PyQtWiki/Using%20a%20Custom%20Protocol%20with%20QtWebKit
import sys
from PyQt4.QtCore import QTimer, QVariant, SIGNAL
from PyQt4.QtGui import *
from PyQt4.QtNetwork import QNetworkAccessManager, QNetworkRequest, QNetworkReply
from PyQt4.QtWebKit import QWebView
html = """<html>
<head>
<title>Test page for the download:// scheme</title>
</head>
<body>
<h1>Downloads</h1>
<a href="download://myfile">Download a file</a>
<hr />
<a href="http://www.google.com">A normal link</a>
</body>
</html>
"""
class DownloadReply(QNetworkReply):
def __init__(self, parent, url, operation):
QNetworkReply.__init__(self, parent)
self.content = "<html><head><title>Test</title></head><body>This is a test.</body></html>"
self.offset = 0
self.setHeader(QNetworkRequest.ContentTypeHeader, QVariant("text/html; charset=ASCII"))
self.setHeader(QNetworkRequest.ContentLengthHeader, QVariant(len(self.content)))
QTimer.singleShot(0, self, SIGNAL("readyRead()"))
QTimer.singleShot(0, self, SIGNAL("finished()"))
self.open(self.ReadOnly | self.Unbuffered)
self.setUrl(url)
def abort(self):
pass
def bytesAvailable(self):
return len(self.content) - self.offset
def isSequential(self):
return True
def readData(self, maxSize):
print "readData called with", maxSize
print "offset is", self.offset
if self.offset < len(self.content):
end = min(self.offset + maxSize, len(self.content))
data = self.content[self.offset:end]
self.offset = end
return data
class NetworkAccessManager(QNetworkAccessManager):
def __init__(self, old_manager):
QNetworkAccessManager.__init__(self)
self.old_manager = old_manager
self.setCache(old_manager.cache())
self.setCookieJar(old_manager.cookieJar())
self.setProxy(old_manager.proxy())
self.setProxyFactory(old_manager.proxyFactory())
def createRequest(self, operation, request, data):
if request.url().scheme() != "download":
return QNetworkAccessManager.createRequest(self, operation, request, data)
if operation == self.GetOperation:
# Handle download:// URLs separately by creating custom
# QNetworkReply objects.
reply = DownloadReply(self, request.url(), self.GetOperation)
return reply
else:
return QNetworkAccessManager.createRequest(self, operation, request, data)
if __name__ == "__main__":
app = QApplication(sys.argv)
view = QWebView()
old_manager = view.page().networkAccessManager()
new_manager = NetworkAccessManager(old_manager)
view.page().setNetworkAccessManager(new_manager)
view.setHtml(html)
view.show()
sys.exit(app.exec_())
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic