本文整理汇总了Python中ninja_ide.core.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: expand_tab_name
def expand_tab_name(self, title):
title = unicode(title)
if title == 'New Document':
return
elif title not in self.titles:
self.titles.append(title)
return
indexes = [i for i in xrange(self.count())
if type(self.widget(i)) is editor.Editor and \
self.tabText(i) == title and \
self.widget(i).ID]
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:
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
示例3: on_wizard_finish
def on_wizard_finish(self, wizard):
global PROJECT_TYPE
ids = wizard.pageIds()
# Manipulate default data for NINJA-IDE projects
page = wizard.page(ids[2])
place = str(page.txtPlace.text())
if place == '':
QMessageBox.critical(self, 'Incorrect Location',
'The project couldn\'t be create')
return
folder = str(page.txtFolder.text())
path = file_manager.create_path(place, folder)
if not file_manager.folder_exists(path):
file_manager.create_folder(path)
project = {}
name = unicode(page.txtName.text())
project['name'] = name
project['project-type'] = PROJECT_TYPE
project['description'] = unicode(page.txtDescription.toPlainText())
project['license'] = unicode(page.cboLicense.currentText())
project['venv'] = unicode(page.vtxtPlace.text())
# Manipulate plugin project data
page = wizard.page(ids[1])
json_manager.create_ninja_project(path, name, project)
plugin_dict = self.create_descriptor(page, path)
self.create_plugin_class(page, path, plugin_dict)
# Load the project!
wizard._load_project(path)
示例4: execute_project
def execute_project(self):
"""Execute the project marked as Main Project."""
mainFile = self.ide.explorer.get_project_main_file()
if not mainFile and self.ide.explorer._treeProjects and \
self.ide.explorer._treeProjects._actualProject:
self.ide.explorer._treeProjects.open_project_properties()
elif mainFile:
self.save_project()
path = self.ide.explorer.get_actual_project()
#emit a signal for plugin!
self.emit(SIGNAL("projectExecuted(QString)"), path)
# load our jutsus!
project = json_manager.read_ninja_project(path)
python_exec = project.get('venv', False)
if not python_exec:
python_exec = project.get('pythonPath', 'python')
PYTHONPATH = project.get('PYTHONPATH', None)
params = project.get('programParams', '')
preExec = project.get('preExecScript', '')
postExec = project.get('postExecScript', '')
mainFile = file_manager.create_path(path, mainFile)
self.ide.misc.run_application(mainFile, pythonPath=python_exec,
PYTHONPATH=PYTHONPATH,
programParams=params, preExec=preExec, postExec=postExec)
示例5: _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))
示例6: _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))
示例7: _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))
示例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(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))
示例9: _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)
示例10: _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)
示例11: _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))
示例12: _go_to
def _go_to(self, item, val):
if item.text(1):
parent = item.parent()
file_name = parent.text(0)
lineno = item.text(1)
root_dir_name = parent.dir_name_root
file_path = file_manager.create_path(root_dir_name, file_name)
#open the file and jump_to_line
self._main_container.open_file(file_path)
self._main_container.editor_jump_to_line(lineno=int(lineno) - 1)
示例13: _delete_file
def _delete_file(self):
item = self.currentItem()
val = QMessageBox.question(self, self.tr("Delete File"),
self.tr("Do you want to delete the following file: ") \
+ os.path.join(item.path, unicode(item.text(0))),
QMessageBox.Yes, QMessageBox.No)
if val == QMessageBox.Yes:
path = file_manager.create_path(item.path, unicode(item.text(0)))
file_manager.delete_file(item.path, unicode(item.text(0)))
self.removeItemWidget(item, 0)
mainContainer = main_container.MainContainer()
if mainContainer.is_open(path):
mainContainer.close_deleted_file(path)
示例14: _delete_file
def _delete_file(self):
item = self.currentItem()
val = QMessageBox.question(self, self.tr("Delete File"),
self.tr("Do you want to delete the following file: ")
+ os.path.join(item.path, item.text(0)),
QMessageBox.Yes, QMessageBox.No)
if val == QMessageBox.Yes:
path = file_manager.create_path(item.path, item.text(0))
file_manager.delete_file(item.path, item.text(0))
index = item.parent().indexOfChild(item)
item.parent().takeChild(index)
mainContainer = main_container.MainContainer()
if mainContainer.is_open(path):
mainContainer.close_deleted_file(path)
示例15: execute_project
def execute_project(self):
mainFile = self.ide.explorer.get_project_main_file()
if not mainFile and self.ide.explorer._treeProjects and \
self.ide.explorer._treeProjects._actualProject:
self.ide.explorer._treeProjects.open_project_properties()
elif mainFile:
self.save_project()
#emit a signal for plugin!
self.emit(SIGNAL("projectExecuted(QString)"), mainFile)
path = self.ide.explorer.get_actual_project()
project = json_manager.read_ninja_project(path)
venv = project.get('venv', False)
params = project.get('programParams', '')
mainFile = file_manager.create_path(path, mainFile)
self.ide.misc.run_application(mainFile, pythonPath=venv,
programParams=params)