当前位置: 首页>>代码示例>>Python>>正文


Python Qutepart.textForSaving方法代码示例

本文整理汇总了Python中qutepart.Qutepart.textForSaving方法的典型用法代码示例。如果您正苦于以下问题:Python Qutepart.textForSaving方法的具体用法?Python Qutepart.textForSaving怎么用?Python Qutepart.textForSaving使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在qutepart.Qutepart的用法示例。


在下文中一共展示了Qutepart.textForSaving方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Document

# 需要导入模块: from qutepart import Qutepart [as 别名]
# 或者: from qutepart.Qutepart import textForSaving [as 别名]

#.........这里部分代码省略.........
        core.workspace().documentClosed.emit(self)
        self._filePath = newPath
        self._fileWatcher.setPath(newPath)
        self._neverSaved = True
        core.workspace().documentOpened.emit(self)
        core.workspace().currentDocumentChanged.emit(self, self)

    def _stripTrailingWhiteSpace(self):
        lineHasTrailingSpace = ((line and line[-1].isspace())
                                for line in self.qutepart.lines)
        if any(lineHasTrailingSpace):
            with self.qutepart:
                for lineNo, line in enumerate(self.qutepart.lines):
                    if line and line[-1].isspace():
                        self.qutepart.lines[lineNo] = line.rstrip()
        else:
            pass  # Do not enter with statement, because it causes wrong textChanged signal

    def _saveToFs(self, filePath):
        """Low level method. Always saves file, even if not modified
        """
        # Create directory
        dirPath = os.path.dirname(filePath)
        if not os.path.exists(dirPath):
            try:
                os.makedirs(dirPath)
            except OSError as ex:
                error = str(ex)
                QMessageBox.critical(None,
                                     self.tr("Cannot save file"),
                                     self.tr("Cannot create directory '%s'. Error '%s'." % (dirPath, error)))
                return

        text = self.qutepart.textForSaving()

        # Write file
        data = text.encode('utf8')

        self._fileWatcher.disable()
        try:
            with open(filePath, 'wb') as openedFile:
                openedFile.write(data)
            self._fileWatcher.setContents(data)
        except IOError as ex:
            QMessageBox.critical(None,
                                 self.tr("Cannot write to file"),
                                 str(ex))
            return
        finally:
            self._fileWatcher.enable()

        # Update states
        self._neverSaved = False
        self._externallyRemoved = False
        self._externallyModified = False
        self.qutepart.document().setModified(False)
        self.documentDataChanged.emit()

        if self.qutepart.language() is None:
            self._tryDetectSyntax()

    def saveFile(self):
        """Save the file to file system.

        Show QFileDialog if file name is not known.
        Return False, if user cancelled QFileDialog, True otherwise
开发者ID:,项目名称:,代码行数:70,代码来源:


注:本文中的qutepart.Qutepart.textForSaving方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。