本文整理汇总了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