Python PyQt5.QtCore.QFile() Examples

The following are 17 code examples for showing how to use PyQt5.QtCore.QFile(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module PyQt5.QtCore , or try the search function .

Example 1
Project: pywebview   Author: r0x0r   File: qt.py    License: BSD 3-Clause "New" or "Revised" License 7 votes vote down vote up
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() 
Example 2
Project: PyQt   Author: PyQt5   File: FacePoints.py    License: GNU General Public License v3.0 6 votes vote down vote up
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() 
Example 3
Project: easygui_qt   Author: aroberge   File: show_text_window.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 
Example 4
Project: ddt4all   Author: cedricp   File: ddt4all.py    License: GNU General Public License v3.0 5 votes vote down vote up
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) 
Example 5
Project: scudcloud   Author: raelgc   File: speller.py    License: MIT License 5 votes vote down vote up
def dictionaryExists(self, path):
        return QFile(path + ".dic").exists() and QFile(path + ".aff").exists(); 
Example 6
Project: parsec-cloud   Author: Scille   File: lang.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
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 
Example 7
Project: parsec-cloud   Author: Scille   File: changelog_widget.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
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() 
Example 8
Project: Python_editor   Author: techbliss   File: pyeditor.py    License: The Unlicense 5 votes vote down vote up
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)) 
Example 9
Project: Python_editor   Author: techbliss   File: pyeditor.py    License: The Unlicense 5 votes vote down vote up
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)) 
Example 10
Project: Python_editor   Author: techbliss   File: pyeditor.py    License: The Unlicense 5 votes vote down vote up
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)) 
Example 11
Project: Python_editor   Author: techbliss   File: pyeditor.py    License: The Unlicense 5 votes vote down vote up
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)) 
Example 12
Project: Python_editor   Author: techbliss   File: pyeditor.py    License: The Unlicense 5 votes vote down vote up
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)) 
Example 13
Project: Python_editor   Author: techbliss   File: pyeditor.py    License: The Unlicense 5 votes vote down vote up
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)) 
Example 14
Project: PyQt   Author: PyQt5   File: BlockRequestData.py    License: GNU General Public License v3.0 5 votes vote down vote up
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)

# 请求拦截器 
Example 15
Project: track   Author: frans-fuerst   File: util.py    License: Apache License 2.0 5 votes vote down vote up
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() 
Example 16
Project: X64dbg_script_editor   Author: techbliss   File: Editor_x64dbg.py    License: The Unlicense 5 votes vote down vote up
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)) 
Example 17
Project: equant   Author: epolestar   File: utils.py    License: GNU General Public License v2.0 4 votes vote down vote up
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()