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


Python QIODevice.ReadOnly方法代码示例

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


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

示例1: test_error_network_reply

# 需要导入模块: from PyQt5.QtCore import QIODevice [as 别名]
# 或者: from PyQt5.QtCore.QIODevice import ReadOnly [as 别名]
def test_error_network_reply(qtbot, req):
    reply = networkreply.ErrorNetworkReply(
        req, "This is an error", QNetworkReply.UnknownNetworkError)

    with qtbot.waitSignals([reply.error, reply.finished], order='strict'):
        pass

    reply.abort()  # shouldn't do anything
    assert reply.request() == req
    assert reply.url() == req.url()
    assert reply.openMode() == QIODevice.ReadOnly
    assert reply.isFinished()
    assert not reply.isRunning()
    assert reply.bytesAvailable() == 0
    assert reply.readData(1) == b''
    assert reply.error() == QNetworkReply.UnknownNetworkError
    assert reply.errorString() == "This is an error" 
开发者ID:qutebrowser,项目名称:qutebrowser,代码行数:19,代码来源:test_networkreply.py

示例2: __init__

# 需要导入模块: from PyQt5.QtCore import QIODevice [as 别名]
# 或者: from PyQt5.QtCore.QIODevice import ReadOnly [as 别名]
def __init__(self, req, errorstring, error, parent=None):
        """Constructor.

        Args:
            req: The QNetworkRequest associated with this reply.
            errorstring: The error string to print.
            error: The numerical error value.
            parent: The parent to pass to QNetworkReply.
        """
        super().__init__(parent)
        self.setRequest(req)
        self.setUrl(req.url())
        # We don't actually want to read anything, but we still need to open
        # the device to avoid getting a warning.
        self.setOpenMode(QIODevice.ReadOnly)
        self.setError(error, errorstring)
        QTimer.singleShot(0, lambda:
                          self.error.emit(error))  # type: ignore[attr-defined]
        QTimer.singleShot(0, lambda:
                          self.finished.emit())  # type: ignore[attr-defined] 
开发者ID:qutebrowser,项目名称:qutebrowser,代码行数:22,代码来源:networkreply.py

示例3: __init__

# 需要导入模块: from PyQt5.QtCore import QIODevice [as 别名]
# 或者: from PyQt5.QtCore.QIODevice import ReadOnly [as 别名]
def __init__(self, persepolis_setting):
        super().__init__(persepolis_setting)

        self.persepolis_setting = persepolis_setting

        # setting window size and position
        size = self.persepolis_setting.value(
            'AboutWindow/size', QSize(545, 375))
        position = self.persepolis_setting.value(
            'AboutWindow/position', QPoint(300, 300))

        # read translators.txt files.
        # this file contains all translators.
        f = QFile(':/translators.txt')

        f.open(QIODevice.ReadOnly | QFile.Text)
        f_text = QTextStream(f).readAll()
        f.close()

        self.translators_textEdit.insertPlainText(f_text)



        self.resize(size)
        self.move(position) 
开发者ID:persepolisdm,项目名称:persepolis,代码行数:27,代码来源:about.py

示例4: test_attributes

# 需要导入模块: from PyQt5.QtCore import QIODevice [as 别名]
# 或者: from PyQt5.QtCore.QIODevice import ReadOnly [as 别名]
def test_attributes(self, req):
        reply = networkreply.FixedDataNetworkReply(req, b'', 'test/foo')
        assert reply.request() == req
        assert reply.url() == req.url()
        assert reply.openMode() == QIODevice.ReadOnly
        assert reply.header(QNetworkRequest.ContentTypeHeader) == 'test/foo'
        http_code = reply.attribute(QNetworkRequest.HttpStatusCodeAttribute)
        http_reason = reply.attribute(
            QNetworkRequest.HttpReasonPhraseAttribute)
        assert http_code == 200
        assert http_reason == 'OK'
        assert reply.isFinished()
        assert not reply.isRunning() 
开发者ID:qutebrowser,项目名称:qutebrowser,代码行数:15,代码来源:test_networkreply.py

示例5: switch_language

# 需要导入模块: from PyQt5.QtCore import QIODevice [as 别名]
# 或者: from PyQt5.QtCore.QIODevice import ReadOnly [as 别名]
def switch_language(core_config, lang_key=None):
    global _current_translator
    global _current_locale_language

    QCoreApplication.translate = qt_translate

    if not lang_key:
        lang_key = core_config.gui_language
    if not lang_key:
        lang_key = get_locale_language()
        logger.info(f"No language in settings, trying local language '{lang_key}'")
    if lang_key not in LANGUAGES.values():
        if lang_key != "en":
            logger.info(f"Language '{lang_key}' unavailable, defaulting to English")
        lang_key = "en"

    _current_locale_language = lang_key

    rc_file = QFile(f":/translations/translations/parsec_{lang_key}.mo")
    if not rc_file.open(QIODevice.ReadOnly):
        logger.warning(f"Unable to read the translations for language '{lang_key}'")
        return None

    try:
        data_stream = QDataStream(rc_file)
        out_stream = io.BytesIO()
        content = data_stream.readRawData(rc_file.size())
        out_stream.write(content)
        out_stream.seek(0)
        _current_translator = gettext.GNUTranslations(out_stream)
        _current_translator.install()
    except OSError:
        logger.warning(f"Unable to load the translations for language '{lang_key}'")
        return None
    finally:
        rc_file.close()
    return lang_key 
开发者ID:Scille,项目名称:parsec-cloud,代码行数:39,代码来源:lang.py

示例6: __init__

# 需要导入模块: from PyQt5.QtCore import QIODevice [as 别名]
# 或者: from PyQt5.QtCore.QIODevice import ReadOnly [as 别名]
def __init__(self, parent=None):
        super().__init__(parent)
        self.setupUi(self)
        rc_file = QFile(":/generated_misc/generated_misc/history.html")
        if not rc_file.open(QIODevice.ReadOnly):
            logger.warning("Unable to read the changelog")
        else:
            self.text_changelog.setHtml(rc_file.readAll().data().decode("utf-8"))
            rc_file.close() 
开发者ID:Scille,项目名称:parsec-cloud,代码行数:11,代码来源:changelog_widget.py

示例7: requestStarted

# 需要导入模块: from PyQt5.QtCore import QIODevice [as 别名]
# 或者: from PyQt5.QtCore.QIODevice import ReadOnly [as 别名]
def requestStarted(self, job):
        url = job.requestUrl().toString()
        if url == 'myurl://png':
            file = QFile('Data/app.png', job)
            file.open(QIODevice.ReadOnly)
            job.reply(b'image/png', file)

# 请求拦截器 
开发者ID:PyQt5,项目名称:PyQt,代码行数:10,代码来源:BlockRequestData.py

示例8: openFile

# 需要导入模块: from PyQt5.QtCore import QIODevice [as 别名]
# 或者: from PyQt5.QtCore.QIODevice import ReadOnly [as 别名]
def openFile(self):
        if settings.get("file_dialog_dir"):
            self.curDir = '~/'
        else:
            self.curDir = settings.get("file_dialog_dir")
        fn = QFileDialog.getOpenFileName(self,
                self.tr("Open File..."), self.curDir,
                self.tr("HTML-Files (*.htm *.html);;All Files (*)"))
        QApplication.setOverrideCursor(Qt.WaitCursor)
        if fn:
            self.lastFolder = os.path.dirname(fn)
            if os.path.exists(fn):
                if os.path.isfile(fn):
                    f = QFile(fn)
                    if not f.open(QIODevice.ReadOnly |
                                  QIODevice.Text):
                        QtGui.QMessageBox.information(self.parent(),
                        self.tr("Error - Lector"),
                        self.tr("Can't open '%s.'" % fn))
                    else:
                        stream = QTextStream(f)
                        text = stream.readAll()
                        self.setText(text)
                else:
                    QMessageBox.information(self.parent(),
                    self.tr("Error - Lector"),
                    self.tr("'%s' is not a file." % fn))
        QApplication.restoreOverrideCursor() 
开发者ID:zdenop,项目名称:lector,代码行数:30,代码来源:textwidget.py


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