本文整理汇总了Python中ninja_ide.core.file_handling.file_manager.create_path函数的典型用法代码示例。如果您正苦于以下问题:Python create_path函数的具体用法?Python create_path怎么用?Python create_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create_path函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: expand_tab_name
def expand_tab_name(self, title):
"""Expand the tab title to differentiate files with the same name.
The way it is currently implemented, it will only change the first
conflicting title passed in, because it only searches until the new
title isn't in the tab titles.
"""
if title == 'New Document':
return
elif title not in self.titles:
self.titles.append(title)
return
indexes = [i for i in range(self.count())
if type(self.widget(i)) is editor.Editor and
self.tabText(i) == title and
self.widget(i).ID] # self.widget.ID returns the basename
self.dontLoopInExpandTitle = True
for i in indexes:
newName = file_manager.create_path(
file_manager.get_basename(
file_manager.get_folder(self.widget(i).ID)), title)
while newName in self.titles:
# Keep prepending the folder name onto the title until it
# does not conflict.
path = self.widget(i).ID
tempDir = path[:path.rfind(newName)]
newName = file_manager.create_path(
file_manager.get_basename(
file_manager.get_folder(tempDir)),
'..',
title)
self.titles.append(newName)
self.setTabText(i, newName)
self.dontLoopInExpandTitle = False
示例2: execute_project
def execute_project(self):
"""Execute the project marked as Main Project."""
projects_explorer = IDE.get_service("projects_explorer")
if projects_explorer is None:
return
nproject = projects_explorer.current_project
if nproject:
main_file = nproject.main_file
if not main_file:
# Open project properties to specify the main file
projects_explorer.current_tree.open_project_properties()
else:
# Save project files
projects_explorer.save_project()
# Emit a signal for plugin!
self.projectExecuted.emit(nproject.path)
main_file = file_manager.create_path(
nproject.path, nproject.main_file)
self.start_process(
filename=main_file,
python_exec=nproject.python_exec,
pre_exec_script=nproject.pre_exec_script,
post_exec_script=nproject.post_exec_script,
program_params=nproject.program_params
)
示例3: _replace_results
def _replace_results(self):
"""Replace the search with the proper text in all the files."""
result = QMessageBox.question(self,
translations.TR_REPLACE_FILES_CONTENTS,
translations.TR_ARE_YOU_SURE_WANT_TO_REPLACE,
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: {} content, could not be replaced'.format(
file_path)))
示例4: execute_project
def execute_project(self):
"""Execute the project marked as Main Project."""
projects_explorer = IDE.get_service('projects_explorer')
if projects_explorer is None:
return
nproject = projects_explorer.current_project
if nproject:
main_file = nproject.main_file
if not main_file and projects_explorer.current_tree:
projects_explorer.current_tree.open_project_properties()
elif main_file:
projects_explorer.save_project()
#emit a signal for plugin!
self.projectExecuted.emit(nproject.path)
main_file = file_manager.create_path(nproject.path,
nproject.main_file)
self._run_application(
main_file,
pythonExec=nproject.python_exec_command,
PYTHONPATH=nproject.python_path,
programParams=nproject.program_params,
preExec=nproject.pre_exec_script,
postExec=nproject.post_exec_script)
else:
QMessageBox.information(self, translations.TR_INFO_TITLE_PROJECT_PROPERTIES,
translations.TR_INFO_MESSAGE_PROJECT_PROPERTIES)
示例5: _rename_file
def _rename_file(self):
path = self.model().filePath(self.currentIndex())
name = file_manager.get_basename(path)
new_name, ok = QInputDialog.getText(
self, translations.TR_RENAME_FILE,
translations.TR_ENTER_NEW_FILENAME,
text=name)
if ok and new_name.strip():
filename = file_manager.create_path(
file_manager.get_folder(path), new_name)
if path == filename:
return
ninjaide = IDE.get_service("ide")
print(ninjaide.filesystem.get_files())
current_nfile = ninjaide.get_or_create_nfile(path)
editable = ninjaide.get_editable(nfile=current_nfile)
current_nfile.move(filename)
if editable is not None:
main_container = IDE.get_service("main_container")
main_container.combo_area.bar.update_item_text(
editable, new_name)
tree = ninjaide.filesystem.get_files()
# FIXME: this is bad
tree[filename] = tree.pop(path)
print(ninjaide.filesystem.get_files())
示例6: _add_file_to_project
def _add_file_to_project(self, path):
"""Add the file for 'path' in the project the user choose here."""
if self._active_project:
pathProject = [self._active_project.project]
addToProject = add_to_project.AddToProject(pathProject, self)
addToProject.exec_()
if not addToProject.pathSelected:
return
main_container = IDE.get_service('main_container')
if not main_container:
return
editorWidget = main_container.get_current_editor()
if not editorWidget.file_path:
name = 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.file_path)
new_path = file_manager.create_path(addToProject.pathSelected, name)
ide_srv = IDE.get_service("ide")
old_file, ide_srv.get_or_create_nfile(path)
new_file = old_file.save(editorWidget.get_text(), path)
#FIXME: Make this file replace the original in the open tab
else:
pass
示例7: _add_file_to_project
def _add_file_to_project(self, path):
"""Add the file for 'path' in the project the user choose here."""
if self._active_project:
pathProject = [self._active_project.project]
addToProject = add_to_project.AddToProject(pathProject, self)
addToProject.exec_()
if not addToProject.pathSelected:
return
main_container = IDE.get_service('main_container')
if not main_container:
return
editorWidget = main_container.get_current_editor()
if not editorWidget.file_path:
name = QInputDialog.getText(None,
translations.TR_ADD_FILE_TO_PROJECT,
translations.TR_FILENAME + ": ")[0]
if not name:
QMessageBox.information(
self,
translations.TR_INVALID_FILENAME,
translations.TR_INVALID_FILENAME_ENTER_A_FILENAME)
return
else:
name = file_manager.get_basename(editorWidget.file_path)
new_path = file_manager.create_path(addToProject.pathSelected, name)
ide_srv = IDE.get_service("ide")
old_file = ide_srv.get_or_create_nfile(path)
new_file = old_file.save(editorWidget.get_text(), new_path)
#FIXME: Make this file replace the original in the open tab
else:
pass
示例8: delete_theme
def delete_theme(self):
if self.list_skins.currentRow() != 0:
file_name = ("%s.qss" % self.list_skins.currentItem().text())
qss_file = file_manager.create_path(resources.NINJA_THEME_DOWNLOAD,
file_name)
file_manager.delete_file(qss_file)
self._refresh_list()
示例9: save_scheme
def save_scheme(self):
name = self.line_name.text().strip()
if not self._is_valid_scheme_name(name):
QMessageBox.information(self, self.tr("Invalid Scheme Name"),
self.tr("The scheme name you have chosen is invalid.\nPlease "
"pick a different name."))
return
fileName = ('{0}.color'.format(
file_manager.create_path(resources.EDITOR_SKINS, name)))
answer = True
if file_manager.file_exists(fileName):
answer = QMessageBox.question(self,
self.tr("Scheme already exists"),
(self.tr("Do you want to override the file: %s?") % fileName),
QMessageBox.Yes, QMessageBox.No)
if answer in (QMessageBox.Yes, True):
scheme = self._preview_style()
self.original_style = copy.copy(scheme)
json_manager.save_editor_skins(fileName, scheme)
self._modified = False
self.saved = True
qsettings = IDE.ninja_settings()
qsettings.setValue('preferences/editor/scheme', name)
QMessageBox.information(self, self.tr("Scheme Saved"),
(self.tr("The scheme has been saved at: %s.") % fileName))
self.close()
elif answer == QMessageBox.Yes:
QMessageBox.information(self, self.tr("Scheme Not Saved"),
self.tr("The name probably is invalid."))
示例10: _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)
# Update path of opened file
main = IDE.get_service('main_container')
if main and 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, self.tr("File Already Exists"),
(self.tr("Invalid Path: the file '%s' already exists.") %
ex.filename))
示例11: _copy_file
def _copy_file(self):
#get the selected QTreeWidgetItem
path = self.model().filePath(self.currentIndex())
name = file_manager.get_basename(path)
global projectsColumn
pathProjects = [p.path for p in projectsColumn.projects]
addToProject = add_to_project.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=name)[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(path)
path = file_manager.store_file_content(path, content, newFile=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))
示例12: _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))
示例13: save_stylesheet
def save_stylesheet(self):
try:
file_name = "%s.qss" % self.line_name.text()
if not self._is_valid_scheme_name(file_name):
QMessageBox.information(
self, translations.TR_PREFERENCES_THEME,
translations.TR_SCHEME_INVALID_NAME)
file_name = ('{0}.qss'.format(
file_manager.create_path(
resources.NINJA_THEME_DOWNLOAD, file_name)))
content = self.edit_qss.toPlainText()
answer = True
if file_manager.file_exists(file_name):
answer = QMessageBox.question(
self, translations.TR_PREFERENCES_THEME,
translations.TR_WANT_OVERWRITE_FILE + ": {0}?".format(
file_name),
QMessageBox.Yes, QMessageBox.No)
if answer in (QMessageBox.Yes, True):
self.apply_stylesheet()
file_manager.store_file_content(
file_name, content, newFile=True)
self.close()
except file_manager.NinjaFileExistsException as ex:
QMessageBox.information(
self, self.tr("File Already Exists"),
(self.tr("Invalid File Name: the file '%s' already exists.") %
ex.filename))
示例14: _move_file
def _move_file(self):
path = self.model().filePath(self.currentIndex())
global projectsColumn
pathProjects = [p.path for p in projectsColumn.projects]
addToProject = add_to_project.AddToProject(pathProjects, self)
addToProject.setWindowTitle(self.tr("Copy File to"))
addToProject.exec_()
if not addToProject.pathSelected:
return
name = file_manager.get_basename(path)
path = file_manager.create_path(addToProject.pathSelected, name)
try:
content = file_manager.read_file_content(path)
path = file_manager.store_file_content(path, content, newFile=True)
file_manager.delete_file(path)
# Update path of opened file
main = IDE.get_service('main_container')
if main and main.is_open(path):
widget = main.get_widget_for_path(path)
if widget:
widget.ID = 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))
示例15: _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)