Helpviewer/Network/PyrcAccessHandler.py

Fri, 08 Jan 2010 14:44:33 +0000

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 08 Jan 2010 14:44:33 +0000
changeset 38
5fe2b7deab15
parent 13
1af94a91f439
child 168
3383117f894b
permissions
-rw-r--r--

Fixed a few issues of the web browser.

# -*- coding: utf-8 -*-

# Copyright (c) 2009 - 2010 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing a scheme access handler for Python resources.
"""

from PyQt4.QtCore import QBuffer, QIODevice, QByteArray

from Helpviewer.HTMLResources import startPage_html

from .SchemeAccessHandler import SchemeAccessHandler

from .NetworkReply import NetworkReply
from .NetworkProtocolUnknownErrorReply import NetworkProtocolUnknownErrorReply

import UI.PixmapCache

class PyrcAccessHandler(SchemeAccessHandler):
    """
    Class implementing a scheme access handler for Python resources.
    """
    def createRequest(self, op, request, outgoingData = None):
        """
        Protected method to create a request.
        
        @param op the operation to be performed (QNetworkAccessManager.Operation)
        @param request reference to the request object (QNetworkRequest)
        @param outgoingData reference to an IODevice containing data to be sent
            (QIODevice)
        @return reference to the created reply object (QNetworkReply)
        """
        if request.url().toString() == "pyrc:home":
            html = startPage_html
            pixmap = UI.PixmapCache.getPixmap("ericWeb32.png")
            imageBuffer = QBuffer()
            imageBuffer.open(QIODevice.ReadWrite)
            if pixmap.save(imageBuffer, "PNG"):
                html = html.replace("IMAGE_BINARY_DATA_HERE", 
                             bytes(imageBuffer.buffer().toBase64()).decode())
            return NetworkReply(request, QByteArray(html), "text/html")
        
        return NetworkProtocolUnknownErrorReply("pyrc")

eric ide

mercurial