本文整理汇总了Python中PyQt5.QtCore.QFile方法的典型用法代码示例。如果您正苦于以下问题:Python QtCore.QFile方法的具体用法?Python QtCore.QFile怎么用?Python QtCore.QFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore
的用法示例。
在下文中一共展示了QtCore.QFile方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QFile [as 别名]
def __init__(self, *args, **kwargs):
super(OpencvWidget, self).__init__(*args, **kwargs)
self.httpRequestAborted = False
self.fps = 24
self.resize(800, 600)
if not os.path.exists("Data/shape_predictor_68_face_landmarks.dat"):
self.setText("正在下载数据文件。。。")
self.outFile = QFile(
"Data/shape_predictor_68_face_landmarks.dat.bz2")
if not self.outFile.open(QIODevice.WriteOnly):
QMessageBox.critical(self, '错误', '无法写入文件')
return
self.qnam = QNetworkAccessManager(self)
self._reply = self.qnam.get(QNetworkRequest(QUrl(URL)))
self._reply.finished.connect(self.httpFinished)
self._reply.readyRead.connect(self.httpReadyRead)
self._reply.downloadProgress.connect(self.updateDataReadProgress)
else:
self.startCapture()
示例2: _set_js_api
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QFile [as 别名]
def _set_js_api(self):
def _register_window_object():
frame.addToJavaScriptWindowObject('external', self.js_bridge)
code = 'qtwebengine' if is_webengine else 'qtwebkit'
script = parse_api_js(self.js_bridge.window, code)
if is_webengine:
qwebchannel_js = QtCore.QFile('://qtwebchannel/qwebchannel.js')
if qwebchannel_js.open(QtCore.QFile.ReadOnly):
source = bytes(qwebchannel_js.readAll()).decode('utf-8')
self.view.page().runJavaScript(source)
self.channel.registerObject('external', self.js_bridge)
qwebchannel_js.close()
else:
frame = self.view.page().mainFrame()
_register_window_object()
try:
self.view.page().runJavaScript(script)
except AttributeError: # < QT 5.6
self.view.page().mainFrame().evaluateJavaScript(script)
self.loaded.set()
示例3: load
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QFile [as 别名]
def load(self, f):
if not QtCore.QFile.exists(f):
self.text_type = 'text'
return "File %s could not be found." % f
try:
file_handle = QtCore.QFile(f)
file_handle.open(QtCore.QFile.ReadOnly)
data = file_handle.readAll()
codec = QtCore.QTextCodec.codecForHtml(data)
return codec.toUnicode(data)
except:
self.text_type = 'text'
return 'Problem reading file %s' % f
示例4: set_dark_style
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QFile [as 别名]
def set_dark_style(onoff):
if (onoff):
stylefile = core.QFile("qstyle.qss")
stylefile.open(core.QFile.ReadOnly)
if qt5:
StyleSheet = str(stylefile.readAll())
else:
StyleSheet = core.QString(core.QLatin1String(stylefile.readAll()))
else:
StyleSheet = ""
app.setStyleSheet(StyleSheet)
示例5: dictionaryExists
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QFile [as 别名]
def dictionaryExists(self, path):
return QFile(path + ".dic").exists() and QFile(path + ".aff").exists();
示例6: switch_language
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QFile [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
示例7: __init__
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QFile [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()
示例8: savetext
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QFile [as 别名]
def savetext(self, fileName):
textout = self.codebox.text()
file = QtCore.QFile(fileName)
if file.open(QtCore.QIODevice.WriteOnly):
QtCore.QTextStream(file) << textout
else:
QtWidgets.QMessageBox.information(self.vindu,
'Unable to open file', file.errorString())
os.chdir(str(self.path))
示例9: savetexttemp
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QFile [as 别名]
def savetexttemp(self, fileName):
textout = self.TemptextEdit.text()
file = QtCore.QFile(fileName)
if file.open(QtCore.QIODevice.WriteOnly):
QtCore.QTextStream(file) << textout
else:
QtWidgets.QMessageBox.information(self.tempwizardPage,
'Unable to open file', file.errorString())
os.chdir(str(self.path))
示例10: savetextscript
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QFile [as 别名]
def savetextscript(self, fileName):
textout = self.script_textEdit.text()
file = QtCore.QFile(fileName)
if file.open(QtCore.QIODevice.WriteOnly):
QtCore.QTextStream(file) << textout
else:
QtWidgets.QMessageBox.information(self.wizardPage_3,
'Unable to open file', file.errorString())
os.chdir(str(self.path))
示例11: requestStarted
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QFile [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)
# 请求拦截器
示例12: open_in_directory_of
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QFile [as 别名]
def open_in_directory_of(file, path):
file = QtCore.QFile(os.path.join(os.path.dirname(file), path))
if not QtCore.QFile.exists(file):
raise FileNotFoundError(path)
file.open(QtCore.QFile.ReadOnly | QtCore.QFile.Text)
yield file
file.close()
示例13: dropEvent
# 需要导入模块: from PyQt5 import QtCore [as 别名]
# 或者: from PyQt5.QtCore import QFile [as 别名]
def dropEvent(self, event):
event.ignore()
return
if event.source():
QTreeView.dropEvent(self, event)
else:
ix = self.indexAt(event.pos())
if not self.model().isDir(ix):
ix = ix.parent()
pathDir = self.model().filePath(ix)
if not pathDir:
pathDir = self.model().filePath(self.rootIndex())
m = event.mimeData()
if m.hasUrls():
urlLocals = [url for url in m.urls() if url.isLocalFile()]
accepted = False
for urlLocal in urlLocals:
path = urlLocal.toLocalFile()
info = QFileInfo(path)
n_path = QDir(pathDir).filePath(info.fileName())
o_path = info.absoluteFilePath()
if n_path == o_path:
continue
if info.isDir():
if QDir(n_path).exists():
reply = QMessageBox.question(self, '提示', '所选的分组中存在同名文件夹,是否全部覆盖?',
QMessageBox.Yes | QMessageBox.No)
if reply == QMessageBox.Yes:
shutil.rmtree(n_path)
shutil.copytree(o_path, n_path)
else:
print(o_path)
for file in os.walk(o_path):
print(file)
shutil.copytree(o_path, n_path)
self.strategy_filters.append(os.path.split(n_path)[1])
self._model.setNameFilters(self.strategy_filters)
else:
qfile = QFile(o_path)
fname = qfile.fileName()
if not fname.endswith('.py'):
QMessageBox.warning(self, "提示", "暂不支持该类型文件", QMessageBox.Yes)
if QFile(n_path).exists():
reply = QMessageBox.question(self, '提示', '所选的分组中存在同名文件,是否覆盖?',
QMessageBox.Yes | QMessageBox.No)
if reply == QMessageBox.Yes:
shutil.copy(o_path, n_path)
# qfile.rename(n_path)
accepted = True
if accepted:
event.acceptProposedAction()