本文整理汇总了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"
示例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]
示例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)
示例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()
示例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
示例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()
示例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)
# 请求拦截器
示例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()