當前位置: 首頁>>代碼示例>>Python>>正文


Python QTextCodec.codecForLocale方法代碼示例

本文整理匯總了Python中PyQt5.QtCore.QTextCodec.codecForLocale方法的典型用法代碼示例。如果您正苦於以下問題:Python QTextCodec.codecForLocale方法的具體用法?Python QTextCodec.codecForLocale怎麽用?Python QTextCodec.codecForLocale使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PyQt5.QtCore.QTextCodec的用法示例。


在下文中一共展示了QTextCodec.codecForLocale方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: run

# 需要導入模塊: from PyQt5.QtCore import QTextCodec [as 別名]
# 或者: from PyQt5.QtCore.QTextCodec import codecForLocale [as 別名]
    def run(self, argv, error_message, in_build_dir=False):
        """ Execute a command and capture the output. """

        if in_build_dir:
            project = self._project

            saved_cwd = os.getcwd()
            build_dir = project.path_from_user(project.build_dir)
            build_dir = QDir.toNativeSeparators(build_dir)
            os.chdir(build_dir)
            self._message_handler.verbose_message(
                    "{0} is now the current directory".format(build_dir))
        else:
            saved_cwd = None

        self._message_handler.verbose_message(
                "Running '{0}'".format(' '.join(argv)))

        QCoreApplication.processEvents()

        process = QProcess()

        process.readyReadStandardOutput.connect(
                lambda: self._message_handler.progress_message(
                        QTextCodec.codecForLocale().toUnicode(
                                process.readAllStandardOutput()).strip()))

        stderr_output = QByteArray()
        process.readyReadStandardError.connect(
                lambda: stderr_output.append(process.readAllStandardError()))

        process.start(argv[0], argv[1:])
        finished = process.waitForFinished()

        if saved_cwd is not None:
            os.chdir(saved_cwd)
            self._message_handler.verbose_message(
                    "{0} is now the current directory".format(saved_cwd))

        if not finished:
            raise UserException(error_message, process.errorString())

        if process.exitStatus() != QProcess.NormalExit or process.exitCode() != 0:
            raise UserException(error_message,
                    QTextCodec.codecForLocale().toUnicode(stderr_output).strip())
開發者ID:doudz,項目名稱:pyqtdeploy,代碼行數:47,代碼來源:builder.py

示例2: read

# 需要導入模塊: from PyQt5.QtCore import QTextCodec [as 別名]
# 或者: from PyQt5.QtCore.QTextCodec import codecForLocale [as 別名]
    def read(self):
        """ Reads the file and returns the content """

        _file = QFile(self.filename)
        if not _file.open(QIODevice.ReadOnly | QIODevice.Text):
            raise Exception(_file.errorString())

        # Codec
        codec = QTextCodec.codecForLocale()
        stream = QTextStream(_file)
        stream.setCodec(codec)
        return stream.readAll()
開發者ID:centaurialpha,項目名稱:pireal,代碼行數:14,代碼來源:pfile.py

示例3: __init__

# 需要導入模塊: from PyQt5.QtCore import QTextCodec [as 別名]
# 或者: from PyQt5.QtCore.QTextCodec import codecForLocale [as 別名]
    def __init__(self, parent=None):
        super().__init__(parent=parent)

        # merge stderr channel into stdout channel
        self.setProcessChannelMode(QProcess.MergedChannels)

        # prepare decoding process' output to Unicode
        codec = QTextCodec.codecForLocale()
        self._decoder_stdout = codec.makeDecoder()
        # only necessary when stderr channel isn't merged into stdout:
        # self._decoder_stderr = codec.makeDecoder()

        self.readyReadStandardOutput.connect(self._ready_read_standard_output)
開發者ID:jcornford,項目名稱:pyecog,代碼行數:15,代碼來源:pyqtgraph_playing.py

示例4: save

# 需要導入模塊: from PyQt5.QtCore import QTextCodec [as 別名]
# 或者: from PyQt5.QtCore.QTextCodec import codecForLocale [as 別名]
    def save(self, data, path=None):
        if path:
            self.filename = path
            self.is_new = False

        _file = QFile(self.filename)
        if not _file.open(QIODevice.WriteOnly | QIODevice.Truncate):
            raise Exception(_file.errorString())

        stream = QTextStream(_file)
        stream.setCodec(QTextCodec.codecForLocale())
        stream << data
        stream.flush()
        _file.close()
        # Emit the signal
        self.fileSaved.emit(self.filename)
開發者ID:centaurialpha,項目名稱:pireal,代碼行數:18,代碼來源:pfile.py


注:本文中的PyQt5.QtCore.QTextCodec.codecForLocale方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。