本文整理汇总了Python中ninja_ide.core.file_manager.store_file_content函数的典型用法代码示例。如果您正苦于以下问题:Python store_file_content函数的具体用法?Python store_file_content怎么用?Python store_file_content使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了store_file_content函数的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _replace_results
def _replace_results(self):
result = QMessageBox.question(self, self.tr("Replace Files Contents"),
self.tr("Are you sure you want to replace the content in "
"this files?\n(The change is not reversible)"),
buttons=QMessageBox.Yes | QMessageBox.No)
if result == QMessageBox.Yes:
for index in range(self._result_widget.topLevelItemCount()):
parent = self._result_widget.topLevelItem(index)
root_dir_name = parent.dir_name_root
file_name = parent.text(0)
file_path = file_manager.create_path(root_dir_name, file_name)
try:
content = file_manager.read_file_content(file_path)
pattern = self._find_widget.pattern_line_edit.text()
flags = 0
if not self._find_widget.case_checkbox.isChecked():
flags |= re.IGNORECASE
if self._find_widget.type_checkbox.isChecked():
pattern = r'\b%s\b' % pattern
new_content = re.sub(pattern,
self._find_widget.replace_line.text(),
content, flags=flags)
file_manager.store_file_content(file_path,
new_content, False)
except:
print('File: %s content, could not be replaced' %
file_path)
开发者ID:AlexaProjects,项目名称:Alexa2,代码行数:28,代码来源:find_in_files.py
示例2: _replace_results
def _replace_results(self):
result = QMessageBox.question(self, self.tr("Replace Files Contents"),
self.tr("Are you sure you want to replace the content in "
"this files?\n(The change is not reversible)"),
buttons=QMessageBox.Yes | QMessageBox.No)
if result == QMessageBox.Yes:
for index in xrange(self._result_widget.topLevelItemCount()):
parent = self._result_widget.topLevelItem(index)
root_dir_name = unicode(parent.dir_name_root)
file_name = unicode(parent.text(0))
file_path = file_manager.create_path(root_dir_name, file_name)
file_object = QFile(file_path)
if not file_object.open(QFile.ReadOnly):
return
stream = QTextStream(file_object)
content = stream.readAll()
file_object.close()
pattern = self._find_widget.pattern_line_edit.text()
case_sensitive = self._find_widget.case_checkbox.isChecked()
type_ = QRegExp.RegExp if \
self._find_widget.type_checkbox.isChecked() else \
QRegExp.FixedString
target = QRegExp(pattern, case_sensitive, type_)
content.replace(target, self._find_widget.replace_line.text())
file_manager.store_file_content(file_path, content, False)
开发者ID:alekibango,项目名称:ninja-ide,代码行数:25,代码来源:find_in_files.py
示例3: 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!"))
开发者ID:dlitvakb,项目名称:ninja-ide,代码行数:35,代码来源:main_container.py
示例4: _move_file
def _move_file(self):
item = self.currentItem()
if item.parent() is None:
pathForFile = item.path
else:
pathForFile = os.path.join(item.path, item.text(0))
pathProjects = [p.path for p in self.get_open_projects()]
addToProject = ui_tools.AddToProject(pathProjects, self)
addToProject.setWindowTitle(self.tr("Copy File to"))
addToProject.exec_()
if not addToProject.pathSelected:
return
name = file_manager.get_basename(pathForFile)
path = file_manager.create_path(addToProject.pathSelected, name)
try:
content = file_manager.read_file_content(pathForFile)
path = file_manager.store_file_content(path, content, newFile=True)
file_manager.delete_file(pathForFile)
index = item.parent().indexOfChild(item)
item.parent().takeChild(index)
self.add_existing_file(path)
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))
开发者ID:Bengt,项目名称:ninja-ide,代码行数:25,代码来源:tree_projects_widget.py
示例5: _copy_file
def _copy_file(self):
#get the selected QTreeWidgetItem
item = self.currentItem()
if item.parent() is None:
pathForFile = item.path
else:
pathForFile = os.path.join(item.path, item.text(0))
pathProjects = [p.path for p in self.get_open_projects()]
addToProject = ui_tools.AddToProject(pathProjects, self)
addToProject.setWindowTitle(self.tr("Copy File to"))
addToProject.exec_()
if not addToProject.pathSelected:
return
name = QInputDialog.getText(self, self.tr("Copy File"),
self.tr("File Name:"), text=item.text(0))[0]
if not name:
QMessageBox.information(self, self.tr("Invalid Name"),
self.tr("The file name is empty, please enter a name"))
return
path = file_manager.create_path(addToProject.pathSelected, name)
try:
content = file_manager.read_file_content(pathForFile)
path = file_manager.store_file_content(path, content, newFile=True)
self.add_existing_file(path)
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))
开发者ID:Bengt,项目名称:ninja-ide,代码行数:28,代码来源:tree_projects_widget.py
示例6: _add_new_file
def _add_new_file(self):
item = self.currentItem()
if item.parent() is None:
pathForFile = item.path
else:
pathForFile = os.path.join(item.path, item.text(0))
result = QInputDialog.getText(self, self.tr("New File"),
self.tr("Enter the File Name:"))
fileName = result[0]
if result[1] and fileName.strip() != '':
try:
fileName = os.path.join(pathForFile, fileName)
fileName = file_manager.store_file_content(
fileName, '', newFile=True)
name = file_manager.get_basename(fileName)
subitem = ProjectItem(item, name, pathForFile)
subitem.setToolTip(0, name)
subitem.setIcon(0, self._get_file_icon(name))
mainContainer = main_container.MainContainer()
mainContainer.open_file(fileName)
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))
开发者ID:Bengt,项目名称:ninja-ide,代码行数:25,代码来源:tree_projects_widget.py
示例7: 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))
开发者ID:beefsack,项目名称:ninja-ide,代码行数:34,代码来源:main_container.py
示例8: _move_file
def _move_file(self):
item = self.currentItem()
if item.parent() is None:
pathForFile = item.path
else:
pathForFile = os.path.join(item.path, item.text(0))
pathProjects = [p.path for p in self.get_open_projects()]
addToProject = ui_tools.AddToProject(pathProjects, self)
addToProject.setWindowTitle(_translate("TreeProjectsWidget", "Copy File to"))
addToProject.exec_()
if not addToProject.pathSelected:
return
name = file_manager.get_basename(pathForFile)
path = file_manager.create_path(addToProject.pathSelected, name)
try:
content = file_manager.read_file_content(pathForFile)
path = file_manager.store_file_content(path, content, newFile=True)
file_manager.delete_file(pathForFile)
index = item.parent().indexOfChild(item)
item.parent().takeChild(index)
self.add_existing_file(path)
# Update path of opened file
main = main_container.MainContainer()
if main.is_open(pathForFile):
widget = main.get_widget_for_path(pathForFile)
if widget:
widget.ID = path
except file_manager.NinjaFileExistsException as ex:
QMessageBox.information(self, _translate("TreeProjectsWidget", "File Already Exists"),
(_translate("TreeProjectsWidget", "Invalid Path: the file '%s' already exists.") %
ex.filename))
开发者ID:Salmista-94,项目名称:Ninja_PyQt5,代码行数:31,代码来源:tree_projects_widget.py
示例9: _add_file_to_project
def _add_file_to_project(self, path):
"""Add the file for 'path' in the project the user choose here."""
pathProject = [self.ide.explorer.get_actual_project()]
addToProject = ui_tools.AddToProject(pathProject, self.ide)
addToProject.exec_()
if not addToProject.pathSelected:
return
editorWidget = self.ide.mainContainer.get_actual_editor()
if not editorWidget.ID:
name = unicode(QInputDialog.getText(None,
self.tr("Add File To Project"), self.tr("File Name:"))[0])
if not name:
QMessageBox.information(self, self.tr("Invalid Name"),
self.tr("The file name is empty, please enter a name"))
return
else:
name = file_manager.get_basename(editorWidget.ID)
path = file_manager.create_path(
unicode(addToProject.pathSelected), name)
try:
path = file_manager.store_file_content(
path, editorWidget.get_text(), newFile=True)
editorWidget.ID = path
self.ide.explorer.add_existing_file(path)
self.ide.change_window_title(path)
name = file_manager.get_basename(path)
self.ide.mainContainer.actualTab.setTabText(
self.ide.mainContainer.actualTab.currentIndex(), name)
editorWidget._file_saved()
except file_manager.NinjaFileExistsException, ex:
QMessageBox.information(self, self.tr("File Already Exists"),
self.tr("Invalid Path: the file '%s' already exists." % \
ex.filename))
开发者ID:alekibango,项目名称:ninja-ide,代码行数:33,代码来源:actions.py
示例10: _copy_file
def _copy_file(self):
item = self.currentItem()
if item.parent() is None:
pathForFile = item.path
else:
pathForFile = os.path.join(item.path, unicode(item.text(0)))
pathProject = self.get_selected_project_path()
addToProject = ui_tools.AddToProject(pathProject, self)
addToProject.setWindowTitle(self.tr("Copy File to"))
addToProject.exec_()
if not addToProject.pathSelected:
return
name = unicode(QInputDialog.getText(None,
self.tr("Copy File"),
self.tr("File Name:"))[0])
if not name:
QMessageBox.information(self, self.tr("Indalid Name"),
self.tr("The file name is empty, please enter a name"))
return
path = file_manager.create_path(
unicode(addToProject.pathSelected), name)
try:
content = file_manager.read_file_content(pathForFile)
path = file_manager.store_file_content(path, content, newFile=True)
self.add_existing_file(path)
except file_manager.NinjaFileExistsException, ex:
QMessageBox.information(self, self.tr("File Already Exists"),
self.tr("Invalid Path: the file '%s' already exists." % \
ex.filename))
开发者ID:sanyaade,项目名称:ninja-ide,代码行数:29,代码来源:tree_projects_widget.py
示例11: _add_new_file
def _add_new_file(self):
item = self.currentItem()
if item.parent() is None:
pathForFile = item.path
else:
pathForFile = os.path.join(item.path, unicode(item.text(0)))
result = QInputDialog.getText(self, self.tr("New File"),
self.tr("Enter the File Name:"))
fileName = unicode(result[0])
if result[1] and fileName.strip() != '':
try:
fileName = os.path.join(pathForFile, fileName)
fileName = file_manager.store_file_content(
fileName, '', newFile=True)
name = file_manager.get_basename(fileName)
subitem = ProjectItem(item, name, pathForFile)
subitem.setToolTip(0, name)
subitem.setIcon(0, self._get_file_icon(name))
item.sortChildren(0, Qt.AscendingOrder)
mainContainer = main_container.MainContainer()
mainContainer.open_file(fileName)
editorWidget = mainContainer.get_actual_editor()
editorWidget.textCursor().insertText("# -*- coding: utf-8 *-*")
main_container.MainContainer().save_file()
except file_manager.NinjaFileExistsException, ex:
QMessageBox.information(self, self.tr("File Already Exists"),
self.tr("Invalid Path: the file '%s' already exists." % \
ex.filename))
开发者ID:sanyaade,项目名称:ninja-ide,代码行数:29,代码来源:tree_projects_widget.py
示例12: create_plugin_class
def create_plugin_class(self, page, path, plugin_dict):
module = plugin_dict['module']
className = plugin_dict['class']
completed = False
# Start the template
content = TEMPLATE_PLUGIN_BEGIN % className
if page.checkEditorS.checkState() == Qt.Checked:
content += TEMPLATE_EDITOR_S
completed = True
if page.checkToolbarS.checkState() == Qt.Checked:
content += TEMPLATE_TOOLBAR_S
completed = True
if page.checkMenuPluginS.checkState() == Qt.Checked:
content += TEMPLATE_MENU_S
completed = True
if page.checkMiscS.checkState() == Qt.Checked:
content += TEMPLATE_MISC_S
completed = True
if page.checkExplorerS.checkState() == Qt.Checked:
content += TEMPLATE_EXPLORER_S
completed = True
if not completed:
content += TEMPLATE_PASS_STATMENT
content += TEMPLATE_PLUGIN_FINISH
content = content
# Create the folder
file_manager.create_folder(os.path.join(path, module))
# Create the file
fileName = os.path.join(os.path.join(path, module), module + '.py')
# Write to the file
file_manager.store_file_content(fileName, content)
# Create the __init__.py with the imports!
file_manager.create_init_file_complete(os.path.join(path, module))
开发者ID:AlexaProjects,项目名称:Alexa2,代码行数:40,代码来源:pluginProject.py
示例13: 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, 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) == ''
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
开发者ID:sbellem,项目名称:ninja-ide,代码行数:51,代码来源:main_container.py
示例14: 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!"))
开发者ID:sanyaade,项目名称:ninja-ide,代码行数:23,代码来源:main_container.py
示例15: _add_file_to_project
def _add_file_to_project(self, path):
"""Add the file for 'path' in the project the user choose here."""
pathProject = [self.ide.explorer.get_actual_project()]
addToProject = ui_tools.AddToProject(pathProject, self.ide)
addToProject.exec_()
if not addToProject.pathSelected:
return
editorWidget = self.ide.mainContainer.get_actual_editor()
if not editorWidget.ID:
name = QInputDialog.getText(None,
_translate("_s_Actions", "Add File To Project"), _translate("_s_Actions", "File Name:"))[0]
if not name:
QMessageBox.information(None, _translate("_s_Actions", "Invalid Name"),
_translate("_s_Actions", "The file name is empty, please enter a name"))
return
else:
name = file_manager.get_basename(editorWidget.ID)
path = file_manager.create_path(addToProject.pathSelected, name)
try:
path = file_manager.store_file_content(
path, editorWidget.get_text(), newFile=True)
self.ide.mainContainer._file_watcher.allow_kill = False
if path != editorWidget.ID:
self.ide.mainContainer.remove_standalone_watcher(
editorWidget.ID)
editorWidget.ID = path
self.ide.mainContainer.add_standalone_watcher(path)
self.ide.mainContainer._file_watcher.allow_kill = True
self.ide.explorer.add_existing_file(path)
self.ide.change_window_title(path)
name = file_manager.get_basename(path)
self.ide.mainContainer.actualTab.setTabText(
self.ide.mainContainer.actualTab.currentIndex(), name)
editorWidget._file_saved()
except file_manager.NinjaFileExistsException as ex:
QMessageBox.information(None, _translate("_s_Actions", "File Already Exists"),
(_translate("_s_Actions", "Invalid Path: the file '%s' already exists.") %
ex.filename))
开发者ID:Salmista-94,项目名称:Ninja_PyQt5,代码行数:38,代码来源:actions.py
示例16: create_plugin_class
def create_plugin_class(self, page, path, plugin_dict):
name = plugin_dict['name']
author = plugin_dict['author']
website = plugin_dict['website']
description = plugin_dict['description']
logFolder = plugin_dict['logfolder']
ocrFolder = plugin_dict['ocrdatafolder']
authWebsDesc = "# -*- coding: UTF-8 -*-"
if author != "":
authWebsDesc = authWebsDesc + os.linesep + "'''" + os.linesep + "AUTHOR: " + author + os.linesep
if website != "":
if author != "":
authWebsDesc = authWebsDesc + "WEBSITE: " + website + os.linesep
else:
authWebsDesc = authWebsDesc + os.linesep + "'''" + os.linesep + "WEBSITE: " + website + os.linesep
if description != "":
if author != "" or website != "":
authWebsDesc = authWebsDesc + "DESCRIPTION:" + os.linesep + description + os.linesep
else:
authWebsDesc = authWebsDesc + os.linesep + "'''" + os.linesep + "DESCRIPTION: " + description + os.linesep
if authWebsDesc != "# -*- coding: UTF-8 -*-":
authWebsDesc = authWebsDesc + "'''"
content = TEMPLATE_PLUGIN_HEADER % authWebsDesc
content = content + TEMPLATE_PLUGIN_BEGIN
content = content + TEMPLATE_USERCODE_SECTION
content = content + TEMPLATE_SETUP_SECTION
content = content + TEMPLATE_OCR_SECTION % ocrFolder.replace("\\", "\\\\")
content = content + TEMPLATE_LOG_SECTION % logFolder.replace("\\", "\\\\")
content = content + TEMPLATE_NAGIOS_SECTION
content = content + TEMPLATE_END_SECTION
'''
if page.checkEditorS.checkState() == Qt.Checked:
content += TEMPLATE_EDITOR_S
completed = True
if page.checkToolbarS.checkState() == Qt.Checked:
content += TEMPLATE_TOOLBAR_S
completed = True
if page.checkMenuPluginS.checkState() == Qt.Checked:
content += TEMPLATE_MENU_S
completed = True
if page.checkMiscS.checkState() == Qt.Checked:
content += TEMPLATE_MISC_S
completed = True
if page.checkExplorerS.checkState() == Qt.Checked:
content += TEMPLATE_EXPLORER_S
completed = True
if not completed:
content += TEMPLATE_PASS_STATMENT
content += TEMPLATE_PLUGIN_FINISH
'''
content = content
# Create the folder
#file_manager.create_folder(os.path.join(path, module))
# Create the file
fileName = os.path.join(path, name + '.py')
# Write to the file
file_manager.store_file_content(fileName, content)
开发者ID:AlexaProjects,项目名称:Alexa2,代码行数:66,代码来源:alexatools.py
注:本文中的ninja_ide.core.file_manager.store_file_content函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论