本文整理汇总了Python中ninja_ide.gui.editor.helpers.remove_trailing_spaces函数的典型用法代码示例。如果您正苦于以下问题:Python remove_trailing_spaces函数的具体用法?Python remove_trailing_spaces怎么用?Python remove_trailing_spaces使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了remove_trailing_spaces函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_file_as
def save_file_as(self):
editorWidget = self.get_actual_editor()
if not editorWidget:
return False
try:
filter = '(*.py);;(*.*)'
if editorWidget.ID:
ext = file_manager.get_file_extension(editorWidget.ID)
if ext != 'py':
filter = '(*.%s);;(*.py);;(*.*)' % ext
fileName = unicode(QFileDialog.getSaveFileName(
self._parent, self.tr("Save File"), editorWidget.ID, filter))
if not fileName:
return False
if settings.REMOVE_TRAILING_SPACES:
helpers.remove_trailing_spaces(editorWidget)
newFile = file_manager.get_file_extension(fileName) == ''
fileName = file_manager.store_file_content(
fileName, editorWidget.get_text(),
addExtension=True, newFile=newFile)
self.actualTab.setTabText(self.actualTab.currentIndex(),
file_manager.get_basename(fileName))
editorWidget.register_syntax(
file_manager.get_file_extension(fileName))
editorWidget.ID = fileName
self.emit(SIGNAL("fileSaved(QString)"),
self.tr("File Saved: %1").arg(fileName))
editorWidget._file_saved()
return True
except file_manager.NinjaFileExistsException, ex:
QMessageBox.information(self, self.tr("File Already Exists"),
self.tr("Invalid Path: the file '%s' already exists." % \
ex.filename))
示例2: save_file
def save_file(self, editorWidget=None):
if not editorWidget:
editorWidget = self.get_actual_editor()
if not editorWidget:
return False
try:
editorWidget.just_saved = True
if editorWidget.newDocument or \
not file_manager.has_write_permission(editorWidget.ID):
return self.save_file_as()
fileName = editorWidget.ID
self.emit(SIGNAL("beforeFileSaved(QString)"), fileName)
if settings.REMOVE_TRAILING_SPACES:
helpers.remove_trailing_spaces(editorWidget)
content = editorWidget.get_text()
file_manager.store_file_content(
fileName, content, addExtension=False)
self._file_watcher.allow_kill = False
if editorWidget.ID != fileName:
self.remove_standalone_watcher(editorWidget.ID)
self.add_standalone_watcher(fileName)
self._file_watcher.allow_kill = True
editorWidget.ID = fileName
encoding = file_manager.get_file_encoding(content)
editorWidget.encoding = encoding
self.emit(SIGNAL("fileSaved(QString)"),
self.tr("File Saved: %1").arg(fileName))
editorWidget._file_saved()
return True
except Exception, reason:
editorWidget.just_saved = False
logger.error('save_file: %s', reason)
QMessageBox.information(self, self.tr("Save Error"),
self.tr("The file couldn't be saved!"))
示例3: save_file
def save_file(self, editorWidget=None):
#FIXME: check how we handle this
if not editorWidget:
editorWidget = self.get_current_editor()
if not editorWidget:
return False
try:
#editorWidget.just_saved = True
nfile = editorWidget.nfile
if nfile.is_new_file or not nfile.has_write_permission():
return self.save_file_as()
self.emit(SIGNAL("beforeFileSaved(QString)"), nfile.file_path)
if settings.REMOVE_TRAILING_SPACES:
helpers.remove_trailing_spaces(editorWidget)
content = editorWidget.get_text()
nfile.save(content)
#file_manager.store_file_content(
#fileName, content, addExtension=False)
encoding = file_manager.get_file_encoding(content)
editorWidget.encoding = encoding
self.emit(SIGNAL("fileSaved(QString)"),
(self.tr("File Saved: %s") % nfile.file_path))
editorWidget._file_saved()
return True
except Exception as reason:
#editorWidget.just_saved = False
logger.error('save_file: %s', reason)
QMessageBox.information(self, self.tr("Save Error"),
self.tr("The file couldn't be saved!"))
return False
示例4: save_file_as
def save_file_as(self):
editorWidget = self.get_current_editor()
if not editorWidget:
return False
try:
filters = "(*.py);;(*.*)"
if editorWidget.file_path:
ext = file_manager.get_file_extension(editorWidget.file_path)
if ext != "py":
filters = "(*.%s);;(*.py);;(*.*)" % ext
save_folder = self._get_save_folder(editorWidget.file_path)
fileName = QFileDialog.getSaveFileName(self._parent, self.tr("Save File"), save_folder, filters)
if not fileName:
return False
if settings.REMOVE_TRAILING_SPACES:
helpers.remove_trailing_spaces(editorWidget)
editorWidget.neditable.save_content(path=fileName)
editorWidget.register_syntax(file_manager.get_file_extension(fileName))
self.emit(SIGNAL("fileSaved(QString)"), (self.tr("File Saved: %s") % fileName))
self.emit(SIGNAL("currentEditorChanged(QString)"), fileName)
return True
except file_manager.NinjaFileExistsException as ex:
QMessageBox.information(
self,
self.tr("File Already Exists"),
(self.tr("Invalid Path: the file '%s' " " already exists.") % ex.filename),
)
except Exception as reason:
logger.error("save_file_as: %s", reason)
QMessageBox.information(self, self.tr("Save Error"), self.tr("The file couldn't be saved!"))
return False
示例5: save_file
def save_file(self, editorWidget=None):
# FIXME: check how we handle this
if not editorWidget:
editorWidget = self.get_current_editor()
if editorWidget is None:
return False
# Ok, we have an editor instance
# Save to file only if editor really was modified
if editorWidget.is_modified:
try:
if (editorWidget.nfile.is_new_file or
not editorWidget.nfile.has_write_permission()):
return self.save_file_as()
self.beforeFileSaved.emit(editorWidget.file_path)
if settings.REMOVE_TRAILING_SPACES:
helpers.remove_trailing_spaces(editorWidget)
# New line at end
# FIXME: from settings
helpers.insert_block_at_end(editorWidget)
# Save convent
editorWidget.neditable.save_content()
encoding = file_manager.get_file_encoding(editorWidget.text)
editorWidget.encoding = encoding
self.fileSaved.emit(
self.tr("File Saved: {}".format(editorWidget.file_path)))
return True
except Exception as reason:
logger.error('save_file: %s', reason)
QMessageBox.information(self, self.tr("Save Error"),
self.tr("The file couldn't be saved!"))
return False
示例6: save_file_as
def save_file_as(self):
editorWidget = self.get_current_editor()
if not editorWidget:
return False
nfile = editorWidget.nfile
try:
#editorWidget.just_saved = True
filters = '(*.py);;(*.*)'
if nfile.file_path:
ext = file_manager.get_file_extension(nfile.file_path)
if ext != 'py':
filters = '(*.%s);;(*.py);;(*.*)' % ext
save_folder = self._get_save_folder(nfile.file_path)
fileName = QFileDialog.getSaveFileName(
self._parent, self.tr("Save File"), save_folder, filters)
if not fileName:
return False
if settings.REMOVE_TRAILING_SPACES:
helpers.remove_trailing_spaces(editorWidget)
#newFile = file_manager.get_file_extension(fileName) == ''
nfile.save(editorWidget.get_text(), path=fileName)
print editorWidget.nfile._file_path
#fileName = file_manager.store_file_content(
#fileName, editorWidget.get_text(),
#addExtension=True, newFile=newFile)
#self.actualTab.setTabText(self.actualTab.currentIndex(),
#file_manager.get_basename(fileName))
editorWidget.register_syntax(
file_manager.get_file_extension(fileName))
#self._file_watcher.allow_kill = False
#if editorWidget.ID != fileName:
#self.remove_standalone_watcher(editorWidget.ID)
#editorWidget.ID = fileName
self.emit(SIGNAL("fileSaved(QString)"),
(self.tr("File Saved: %s") % fileName))
self.emit(SIGNAL("currentTabChanged(QString)"), fileName)
editorWidget._file_saved()
#self.add_standalone_watcher(fileName)
#self._file_watcher.allow_kill = True
return True
except file_manager.NinjaFileExistsException as ex:
#editorWidget.just_saved = False
QMessageBox.information(self, self.tr("File Already Exists"),
(self.tr("Invalid Path: the file '%s' already exists.") %
ex.filename))
except Exception as reason:
#editorWidget.just_saved = False
logger.error('save_file_as: %s', reason)
QMessageBox.information(self, self.tr("Save Error"),
self.tr("The file couldn't be saved!"))
self.actualTab.setTabText(self.actualTab.currentIndex(),
self.tr("New Document"))
return False
示例7: save_file_as
def save_file_as(self):
editorWidget = self.get_actual_editor()
if not editorWidget:
return False
try:
editorWidget.just_saved = True
filters = '(*.py);;(*.*)'
if editorWidget.ID:
ext = file_manager.get_file_extension(editorWidget.ID)
if ext != 'py':
filters = '(*.%s);;(*.py);;(*.*)' % ext
save_folder = self._get_save_folder(editorWidget.ID)
fileName = QFileDialog.getSaveFileName(
self._parent, _translate("_s_MainContainer", "Save File"), save_folder, filters)
if not fileName:
return False
if settings.REMOVE_TRAILING_SPACES:
helpers.remove_trailing_spaces(editorWidget)
newFile = file_manager.get_file_extension(fileName) == ''
fileName = file_manager.store_file_content(
fileName, editorWidget.get_text(),
addExtension=True, newFile=newFile)
self.actualTab.setTabText(self.actualTab.currentIndex(),
file_manager.get_basename(fileName))
editorWidget.register_syntax(
file_manager.get_file_extension(fileName))
self._file_watcher.allow_kill = False
if editorWidget.ID != fileName:
self.remove_standalone_watcher(editorWidget.ID)
editorWidget.ID = fileName
self.fileSaved.emit((_translate("_s_MainContainer", "File Saved: %s") % fileName))
self.currentTabChanged.emit(fileName)
editorWidget._file_saved()
self.add_standalone_watcher(fileName)
self._file_watcher.allow_kill = True
return True
except file_manager.NinjaFileExistsException as ex:
editorWidget.just_saved = False
QMessageBox.information(self, _translate("_s_MainContainer", "File Already Exists"),
(_translate("_s_MainContainer", "Invalid Path: the file '%s' already exists.") %
ex.filename))
except Exception as reason:
editorWidget.just_saved = False
logger.error('save_file_as: %s', reason)
QMessageBox.information(self, _translate("_s_MainContainer", "Save Error"),
_translate("_s_MainContainer", "The file couldn't be saved!"))
self.actualTab.setTabText(self.actualTab.currentIndex(),
_translate("_s_MainContainer", "New Document"))
return False
示例8: save_file_as
def save_file_as(self):
editorWidget = self.get_current_editor()
if not editorWidget:
return False
try:
filters = '(*.py);;(*.*)'
if editorWidget.file_path: # existing file
ext = file_manager.get_file_extension(editorWidget.file_path)
if ext != 'py':
filters = '(*.%s);;(*.py);;(*.*)' % ext
save_folder = self._get_save_folder(editorWidget.file_path)
fileName = QFileDialog.getSaveFileName(
self._parent, self.tr("Save File"), save_folder, filters)[0]
if not fileName:
return False
if settings.REMOVE_TRAILING_SPACES:
helpers.remove_trailing_spaces(editorWidget)
ext = file_manager.get_file_extension(fileName)
if not ext:
fileName = '%s.%s' % (fileName, 'py',)
editorWidget.neditable.save_content(path=fileName)
# editorWidget.register_syntax(
# file_manager.get_file_extension(fileName))
self.fileSaved.emit(self.tr("File Saved: {}".format(fileName)))
self.currentEditorChanged.emit(fileName)
return True
except file_manager.NinjaFileExistsException as ex:
QMessageBox.information(self, self.tr("File Already Exists"),
(self.tr("Invalid Path: the file '%s' "
" already exists.") %
ex.filename))
except Exception as reason:
logger.error('save_file_as: %s', reason)
QMessageBox.information(self, self.tr("Save Error"),
self.tr("The file couldn't be saved!"))
return False
示例9: save_file
def save_file(self, editorWidget=None):
if not editorWidget:
editorWidget = self.get_actual_editor()
if not editorWidget:
return False
try:
if editorWidget.newDocument or not file_manager.has_write_permission(editorWidget.ID):
return self.save_file_as()
fileName = editorWidget.ID
if settings.REMOVE_TRAILING_SPACES:
helpers.remove_trailing_spaces(editorWidget)
content = editorWidget.get_text()
file_manager.store_file_content(fileName, content, addExtension=False)
editorWidget.ID = fileName
encoding = file_manager._search_coding_line(content)
editorWidget.encoding = encoding
self.emit(SIGNAL("fileSaved(QString)"), self.tr("File Saved: %1").arg(fileName))
editorWidget._file_saved()
return True
except Exception, reason:
logger.error("save_file: %s", reason)
QMessageBox.information(self, self.tr("Save Error"), self.tr("The file couldn't be saved!"))
示例10: editor_remove_trailing_spaces
def editor_remove_trailing_spaces(self):
"""Remove the trailing spaces in the current editor."""
editorWidget = self.ide.mainContainer.get_actual_editor()
if editorWidget:
helpers.remove_trailing_spaces(editorWidget)
示例11: editor_remove_trailing_spaces
def editor_remove_trailing_spaces(self):
"""Remove the trailing spaces in the current editor."""
editorWidget = self.get_current_editor()
if editorWidget:
helpers.remove_trailing_spaces(editorWidget)
示例12: editor_remove_trailing_spaces
def editor_remove_trailing_spaces(self):
editorWidget = self.ide.mainContainer.get_actual_editor()
if editorWidget:
helpers.remove_trailing_spaces(editorWidget)