Helpviewer/Network/PyrcAccessHandler.py

Sat, 02 Jan 2010 15:35:20 +0000

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 02 Jan 2010 15:35:20 +0000
changeset 13
1af94a91f439
parent 12
1d8dd9706f46
child 38
5fe2b7deab15
permissions
-rw-r--r--

Changed copyright for 2010.

# -*- 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.replace("IMAGE_BINARY_DATA_HERE", 
                             str(imageBuffer.buffer().toBase64()))
            return NetworkReply(request, QByteArray(html), "text/html")
        
        return NetworkProtocolUnknownErrorReply("pyrc")

eric ide

mercurial