當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。