当前位置: 首页>>代码示例>>Python>>正文


Python QBuffer.setData方法代码示例

本文整理汇总了Python中PyQt5.QtCore.QBuffer.setData方法的典型用法代码示例。如果您正苦于以下问题:Python QBuffer.setData方法的具体用法?Python QBuffer.setData怎么用?Python QBuffer.setData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt5.QtCore.QBuffer的用法示例。


在下文中一共展示了QBuffer.setData方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: loadFromMemory

# 需要导入模块: from PyQt5.QtCore import QBuffer [as 别名]
# 或者: from PyQt5.QtCore.QBuffer import setData [as 别名]
    def loadFromMemory(self):
        """ This slot function is called in the second Dialog process, when the
        user presses the "Load Image from Shared Memory" button.  First, it
        attaches the process to the shared memory segment created by the first
        Dialog process.  Then it locks the segment for exclusive access, copies
        the image data from the segment into a QBuffer, and streams the QBuffer
        into a QImage.  Then it unlocks the shared memory segment, detaches
        from it, and finally displays the QImage in the Dialog.
        """

        if not self.sharedMemory.attach():
            self.ui.label.setText(
                    "Unable to attach to shared memory segment.\nLoad an "
                    "image first.")
            return
 
        buf = QBuffer()
        ins = QDataStream(buf)
        image = QImage()

        self.sharedMemory.lock()
        buf.setData(self.sharedMemory.constData())
        buf.open(QBuffer.ReadOnly)
        ins >> image
        self.sharedMemory.unlock()
        self.sharedMemory.detach()

        self.ui.label.setPixmap(QPixmap.fromImage(image))
开发者ID:death-finger,项目名称:Scripts,代码行数:30,代码来源:sharedmemory.py

示例2: perform_delete

# 需要导入模块: from PyQt5.QtCore import QBuffer [as 别名]
# 或者: from PyQt5.QtCore.QBuffer import setData [as 别名]
    def perform_delete(self, endpoint, data, url):
        """
        Perform an HTTP DELETE request.

        :param endpoint: the name of the Tribler endpoint.
        :param data: the data/body to send with the request.
        :param url: the url to send the request to.
        """
        buf = QBuffer()
        buf.setData(data)
        buf.open(QIODevice.ReadOnly)
        delete_request = QNetworkRequest(QUrl(url))
        reply = self.sendCustomRequest(delete_request, "DELETE", buf)
        buf.setParent(reply)
        return reply
开发者ID:synctext,项目名称:tribler,代码行数:17,代码来源:tribler_request_manager.py

示例3: HelpSchemeReply

# 需要导入模块: from PyQt5.QtCore import QBuffer [as 别名]
# 或者: from PyQt5.QtCore.QBuffer import setData [as 别名]
class HelpSchemeReply(QIODevice):
    """
    Class implementing a reply for a requested qthelp: page.

    The Qt signal *closed* is emitted to signal that the web engine has read the data.

    see: https://fossies.org/linux/eric6/eric/WebBrowser/Network/QtHelpSchemeHandler.py
    All credits for this class go to:
    Detlev Offenbach, the developer of The Eric Python IDE(https://eric-ide.python-projects.org)

    """
    closed = pyqtSignal()

    def __init__(self, job, engine, parent=None):
        """
        Constructor

        :param job: reference to the URL request
        :type job: QWebEngineUrlRequestJob
        :param engine: reference to the help engine
        :type engine: QHelpEngine
        :param parent: reference to the parent object
        :type parent: QObject
        """
        super(HelpSchemeReply, self).__init__(parent)

        url = job.requestUrl()
        strUrl = url.toString()

        self.__buffer = QBuffer()

        # For some reason the url to load maybe wrong (passed from web engine)
        # though the css file and the references inside should work that way.
        # One possible problem might be that the css is loaded at the same
        # level as the html, thus a path inside the css like
        # (../images/foo.png) might cd out of the virtual folder
        if not engine.findFile(url).isValid():
            if strUrl.startswith(QtHelp_DOCROOT):
                newUrl = job.requestUrl()
                if not newUrl.path().startswith("/qdoc/"):
                    newUrl.setPath("/qdoc" + newUrl.path())
                    url = newUrl
                    strUrl = url.toString()

        self.__mimeType = mimetypes.guess_type(strUrl)[0]
        if self.__mimeType is None:
            # do our own (limited) guessing
            self.__mimeType = self.__mimeFromUrl(url)

        if engine.findFile(url).isValid():
            data = engine.fileData(url)
        else:
            data = QByteArray(self.tr(
                """<html>"""
                """<head><title>Error 404...</title></head>"""
                """<body><div align="center"><br><br>"""
                """<h1>The page could not be found</h1><br>"""
                """<h3>'{0}'</h3></div></body>"""
                """</html>""").format(strUrl)
                              .encode("utf-8"))

        self.__buffer.setData(data)
        self.__buffer.open(QIODevice.ReadOnly)
        self.open(QIODevice.ReadOnly)

    def bytesAvailable(self):
        """
        Public method to get the number of available bytes.

        :returns: number of available bytes
        :rtype: int
        """
        return self.__buffer.bytesAvailable()

    def readData(self, maxlen):
        """
        Public method to retrieve data from the reply object.

        :param maxlen: maximum number of bytes to read (integer)
        :returns: string containing the data (bytes)
        """
        return self.__buffer.read(maxlen)

    def close(self):
        """
        Public method used to close the reply.
        """
        super(HelpSchemeReply, self).close()
        self.closed.emit()

    def __mimeFromUrl(self, url):
        """
        Private method to guess the mime type given an URL.

        :param url: URL to guess the mime type from (QUrl)
        :returns: mime type for the given URL (string)
        """
        path = url.path()
        ext = os.path.splitext(path)[1].lower()
        if ext in ExtensionMap:
#.........这里部分代码省略.........
开发者ID:pandel,项目名称:opsiPackageBuilder,代码行数:103,代码来源:helpviewer.py


注:本文中的PyQt5.QtCore.QBuffer.setData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。