本文整理汇总了Python中ninja_ide.core.file_handling.file_manager.file_exists函数的典型用法代码示例。如果您正苦于以下问题:Python file_exists函数的具体用法?Python file_exists怎么用?Python file_exists使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了file_exists函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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."))
示例2: save_properties
def save_properties(self):
if self.projectData.name.text().strip() == '':
QMessageBox.critical(self, self.tr("Properties Invalid"),
self.tr("The Project must have a name."))
return
tempName = self._item.name
self._item.name = self.projectData.name.text()
self._item.description = self.projectData.description.toPlainText()
self._item.license = self.projectData.cboLicense.currentText()
self._item.mainFile = self.projectExecution.path.text()
self._item.url = self.projectData.url.text()
self._item.projectType = self.projectData.txtType.text()
# FIXME
self._item.pythonPath = self.projectExecution.txtPythonPath.text()
self._item.PYTHONPATH = self.projectExecution.PYTHONPATH.toPlainText()
self._item.additional_builtins = filter(
lambda e: e, # remove empty names
self.projectExecution.additional_builtins.text().split(' '))
self._item.preExecScript = self.projectExecution.txtPreExec.text()
self._item.postExecScript = self.projectExecution.txtPostExec.text()
self._item.programParams = self.projectExecution.txtParams.text()
self._item.venv = self.projectExecution.txtVenvPath.text()
extensions = self.projectData.txtExtensions.text().split(', ')
self._item.extensions = tuple(extensions)
self._item.indentation = self.projectData.spinIndentation.value()
self._item.useTabs = self.projectData.checkUseTabs.isChecked()
related = self.projectMetadata.txt_projects.toPlainText()
related = [path for path in related.split('\n') if path != '']
self._item.related_projects = related
#save project properties
project = {}
project['name'] = self._item.name
project['description'] = self._item.description
project['url'] = self._item.url
project['license'] = self._item.license
project['mainFile'] = self._item.mainFile
project['project-type'] = self._item.projectType
project['supported-extensions'] = self._item.extensions
project['indentation'] = self._item.indentation
project['use-tabs'] = self._item.useTabs
project['pythonPath'] = self._item.pythonPath # FIXME
project['PYTHONPATH'] = self._item.PYTHONPATH
project['additional_builtins'] = self._item.additional_builtins
project['preExecScript'] = self._item.preExecScript
project['postExecScript'] = self._item.postExecScript
project['venv'] = self._item.venv
project['programParams'] = self._item.programParams
project['relatedProjects'] = self._item.related_projects
if tempName != self._item.name and \
file_manager.file_exists(self._item.path, tempName + '.nja'):
file_manager.delete_file(self._item.path, tempName + '.nja')
json_manager.create_ninja_project(
self._item.path, self._item.name, project)
self._item.setText(0, self._item.name)
self._item.setToolTip(0, self._item.name)
if self._item.extensions != settings.SUPPORTED_EXTENSIONS:
self._item._parent._refresh_project(self._item)
self._item.update_paths()
self.close()
示例3: save_scheme
def save_scheme(self):
"""Save current scheme."""
name = self.line_name.text().strip()
if not self._is_valid_scheme_name(name):
QMessageBox.information(
self, translations.TR_PREFERENCES_EDITOR_SCHEME_DESIGNER,
translations.TR_SCHEME_INVALID_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, translations.TR_PREFERENCES_EDITOR_SCHEME_DESIGNER,
translations.TR_WANT_OVERWRITE_FILE + ": {0}?".format(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, translations.TR_PREFERENCES_EDITOR_SCHEME_DESIGNER,
translations.TR_SCHEME_SAVED + ": {0}.".format(fileName))
self.close()
elif answer == QMessageBox.Yes:
QMessageBox.information(
self, translations.TR_PREFERENCES_EDITOR_SCHEME_DESIGNER,
translations.TR_INVALID_FILENAME)
示例4: 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))
示例5: load_session_files_projects
def load_session_files_projects(self, files, projects, current_file, recent_files=None):
"""Load the files and projects from previous session."""
main_container = IDE.get_service("main_container")
projects_explorer = IDE.get_service("projects_explorer")
if main_container and files:
for fileData in files:
if file_manager.file_exists(fileData[0]):
mtime = os.stat(fileData[0]).st_mtime
ignore_checkers = mtime == fileData[2]
main_container.open_file(fileData[0], fileData[1], ignore_checkers=ignore_checkers)
if current_file:
main_container.open_file(current_file)
if projects_explorer and projects:
projects_explorer.load_session_projects(projects)
示例6: _load_session_data
def _load_session_data(self, key):
"""Activate the selected session, closing the current files/projects"""
main_container = self._ide.get_service("main_container")
projects_explorer = self._ide.get_service("projects_explorer")
if projects_explorer and main_container:
projects_explorer.close_opened_projects()
for fileData in settings.SESSIONS[key][0]:
path, line, stat_value = fileData
if file_manager.file_exists(path):
mtime = os.stat(path).st_mtime
ignore_checkers = mtime == stat_value
main_container.open_file(path, line, ignore_checkers=ignore_checkers)
if projects_explorer:
projects_explorer.load_session_projects(settings.SESSIONS[key][1])
示例7: load_session_files_projects
def load_session_files_projects(self, files, projects,
current_file, recent_files=None):
"""Load the files and projects from previous session."""
main_container = IDE.get_service('main_container')
projects_explorer = IDE.get_service('projects_explorer')
if main_container and files:
#self.connect(explorer, SIGNAL("projectOpened(QString)"),
#self._set_editors_project_data)
for fileData in files:
if file_manager.file_exists(fileData[0]):
mtime = os.stat(fileData[0]).st_mtime
ignore_checkers = (mtime == fileData[2])
main_container.open_file(fileData[0], fileData[1],
ignore_checkers=ignore_checkers)
if current_file:
main_container.open_file(current_file)
if projects_explorer and projects:
projects_explorer.load_session_projects(projects)
示例8: load_session
def load_session(self, session_name):
"""Activate the selected session, closing the current files/projects"""
main_container = self._ide.get_service("main_container")
projects_explorer = self._ide.get_service("projects_explorer")
if projects_explorer and main_container:
projects_explorer.close_opened_projects()
for file_data in self.__sessions[session_name][0]:
path, (line, col), stat_value = file_data
if file_manager.file_exists(path):
mtime = os.stat(path).st_mtime
ignore_checkers = (mtime == stat_value)
main_container.open_file(path, line, col,
ignore_checkers=ignore_checkers)
if projects_explorer:
projects_explorer.load_session_projects(
self.__sessions[session_name][1])
示例9: _navigate_bookmarks
def _navigate_bookmarks(self, val):
"""Navigate between the bookmarks."""
bookList = list(settings.BOOKMARKS.keys())
bookList.sort()
if not bookList:
return
if self.__bookmarksFile not in bookList:
self.__bookmarksFile = bookList[0]
index = bookList.index(self.__bookmarksFile)
bookms = settings.BOOKMARKS.get(self.__bookmarksFile, [])
lineNumber = 0
#val == True: forward
if val:
if (len(bookms) - 1) > self.__bookmarksPos:
self.__bookmarksPos += 1
lineNumber = bookms[self.__bookmarksPos]
elif len(bookms) > 0:
if index < (len(bookList) - 1):
self.__bookmarksFile = bookList[index + 1]
else:
self.__bookmarksFile = bookList[0]
self.__bookmarksPos = 0
lineNumber = settings.BOOKMARKS[self.__bookmarksFile][0]
else:
if self.__bookmarksPos > 0:
self.__bookmarksPos -= 1
lineNumber = bookms[self.__bookmarksPos]
elif len(bookms) > 0:
self.__bookmarksFile = bookList[index - 1]
bookms = settings.BOOKMARKS[self.__bookmarksFile]
self.__bookmarksPos = len(bookms) - 1
lineNumber = bookms[self.__bookmarksPos]
if file_manager.file_exists(self.__bookmarksFile):
self.open_file(self.__bookmarksFile,
lineNumber, None, True)
else:
settings.BOOKMARKS.pop(self.__bookmarksFile)
if settings.BOOKMARKS:
self._navigate_bookmarks(val)
示例10: _navigate_breakpoints
def _navigate_breakpoints(self, val):
"""Navigate between the breakpoints."""
#FIXME: put navigate breakpoints and bookmarks as one method.
breakList = list(settings.BREAKPOINTS.keys())
breakList.sort()
if not breakList:
return
if self.__breakpointsFile not in breakList:
self.__breakpointsFile = breakList[0]
index = breakList.index(self.__breakpointsFile)
breaks = settings.BREAKPOINTS.get(self.__breakpointsFile, [])
lineNumber = 0
#val == True: forward
if val:
if (len(breaks) - 1) > self.__breakpointsPos:
self.__breakpointsPos += 1
lineNumber = breaks[self.__breakpointsPos]
elif len(breaks) > 0:
if index < (len(breakList) - 1):
self.__breakpointsFile = breakList[index + 1]
else:
self.__breakpointsFile = breakList[0]
self.__breakpointsPos = 0
lineNumber = settings.BREAKPOINTS[self.__breakpointsFile][0]
else:
if self.__breakpointsPos > 0:
self.__breakpointsPos -= 1
lineNumber = breaks[self.__breakpointsPos]
elif len(breaks) > 0:
self.__breakpointsFile = breakList[index - 1]
breaks = settings.BREAKPOINTS[self.__breakpointsFile]
self.__breakpointsPos = len(breaks) - 1
lineNumber = breaks[self.__breakpointsPos]
if file_manager.file_exists(self.__breakpointsFile):
self.open_file(self.__breakpointsFile, lineNumber, None, True)
else:
settings.BREAKPOINTS.pop(self.__breakpointsFile)
if settings.BREAKPOINTS:
self._navigate_breakpoints(val)
示例11: save_project_properties
def save_project_properties(self):
#save project properties
project = {}
project['name'] = self._name
project['description'] = self.description
project['url'] = self.url
project['license'] = self.license
project['mainFile'] = self.main_file
project['project-type'] = self.project_type
project['supported-extensions'] = self.extensions
project['indentation'] = self.indentation
project['use-tabs'] = self.use_tabs
project['pythonExec'] = self.python_exec # FIXME
project['PYTHONPATH'] = self.python_path
project['additional_builtins'] = self.additional_builtins
project['preExecScript'] = self.pre_exec_script
project['postExecScript'] = self.post_exec_script
project['venv'] = self.venv
project['programParams'] = self.program_params
project['relatedProjects'] = self.related_projects
if file_manager.file_exists(self.path, self._name + '.nja'):
file_manager.delete_file(self.path, self._name + '.nja')
json_manager.create_ninja_project(self.path, self._name, project)
示例12: start_ide
def start_ide(app, filenames, projects_path, extra_plugins, linenos):
"""Load all the settings necessary before loading the UI, and start IDE."""
QCoreApplication.setOrganizationName('NINJA-IDE')
QCoreApplication.setOrganizationDomain('NINJA-IDE')
QCoreApplication.setApplicationName('NINJA-IDE')
app.setWindowIcon(QIcon(":img/icon"))
# Check if there is another session of ninja-ide opened
# and in that case send the filenames and projects to that session
running = ipc.is_running()
start_server = not running[0]
if running[0] and (filenames or projects_path):
sended = ipc.send_data(running[1], filenames, projects_path, linenos)
running[1].close()
if sended:
sys.exit()
else:
running[1].close()
# Create and display the splash screen
splash_pix = QPixmap(":img/splash")
splash = QSplashScreen(splash_pix, Qt.WindowStaysOnTopHint)
splash.setMask(splash_pix.mask())
splash.show()
app.processEvents()
# Set the cursor to unblinking
if not settings.IS_WINDOWS:
app.setCursorFlashTime(0)
#Set the codec for strings (QString)
QTextCodec.setCodecForCStrings(QTextCodec.codecForName('utf-8'))
#Translator
qsettings = ide.IDE.ninja_settings()
data_qsettings = ide.IDE.data_settings()
language = QLocale.system().name()
lang = qsettings.value('preferences/interface/language',
defaultValue=language, type='QString') + '.qm'
lang_path = file_manager.create_path(resources.LANGS, lang)
if file_manager.file_exists(lang_path):
settings.LANGUAGE = lang_path
translator = QTranslator()
if settings.LANGUAGE:
translator.load(settings.LANGUAGE)
app.installTranslator(translator)
qtTranslator = QTranslator()
qtTranslator.load("qt_" + language,
QLibraryInfo.location(QLibraryInfo.TranslationsPath))
app.installTranslator(qtTranslator)
#Loading Syntax
splash.showMessage("Loading Syntax", Qt.AlignRight | Qt.AlignTop, Qt.black)
json_manager.load_syntax()
#Read Settings
splash.showMessage("Loading Settings", Qt.AlignRight | Qt.AlignTop,
Qt.black)
settings.load_settings()
#Set Stylesheet
style_applied = False
if settings.NINJA_SKIN not in ('Default', 'Classic Theme'):
file_name = ("%s.qss" % settings.NINJA_SKIN)
qss_file = file_manager.create_path(resources.NINJA_THEME_DOWNLOAD,
file_name)
if file_manager.file_exists(qss_file):
with open(qss_file) as f:
qss = f.read()
app.setStyleSheet(qss)
style_applied = True
if not style_applied:
if settings.NINJA_SKIN == 'Default':
with open(resources.NINJA_THEME) as f:
qss = f.read()
else:
with open(resources.NINJA_THEME_CLASSIC) as f:
qss = f.read()
app.setStyleSheet(qss)
#Loading Schemes
splash.showMessage("Loading Schemes",
Qt.AlignRight | Qt.AlignTop, Qt.black)
scheme = qsettings.value('preferences/editor/scheme', "default",
type='QString')
if scheme != 'default':
scheme = file_manager.create_path(resources.EDITOR_SKINS,
scheme + '.color')
if file_manager.file_exists(scheme):
resources.CUSTOM_SCHEME = json_manager.parse(open(scheme))
#Loading Shortcuts
resources.load_shortcuts()
#Loading GUI
splash.showMessage("Loading GUI", Qt.AlignRight | Qt.AlignTop, Qt.black)
ninjaide = ide.IDE(start_server)
#Showing GUI
ninjaide.show()
#.........这里部分代码省略.........
示例13: open_files
def open_files(self, files):
for fileData in files:
if file_manager.file_exists(fileData[0]):
self.open_file(fileData[0], fileData[1])
示例14: start_ide
def start_ide(app, filenames, projects_path, extra_plugins, linenos):
"""Load all the settings necessary before loading the UI, and start IDE."""
QCoreApplication.setOrganizationName("NINJA-IDE")
QCoreApplication.setOrganizationDomain("NINJA-IDE")
QCoreApplication.setApplicationName("NINJA-IDE")
app.setWindowIcon(QIcon(resources.IMAGES["icon"]))
# Check if there is another session of ninja-ide opened
# and in that case send the filenames and projects to that session
running = ipc.is_running()
start_server = not running[0]
if running[0] and (filenames or projects_path):
sended = ipc.send_data(running[1], filenames, projects_path, linenos)
running[1].close()
if sended:
sys.exit()
else:
running[1].close()
# Create and display the splash screen
splash_pix = QPixmap(resources.IMAGES["splash"])
splash = QSplashScreen(splash_pix, Qt.WindowStaysOnTopHint)
splash.setMask(splash_pix.mask())
splash.show()
app.processEvents()
# Set the cursor to unblinking
if not settings.IS_WINDOWS:
app.setCursorFlashTime(0)
# Set the codec for strings (QString)
QTextCodec.setCodecForCStrings(QTextCodec.codecForName("utf-8"))
# Translator
qsettings = QSettings(resources.SETTINGS_PATH, QSettings.IniFormat)
language = QLocale.system().name()
lang = qsettings.value("preferences/interface/language", defaultValue=language, type="QString") + ".qm"
lang_path = file_manager.create_path(resources.LANGS, lang)
if file_manager.file_exists(lang_path):
settings.LANGUAGE = lang_path
translator = QTranslator()
if settings.LANGUAGE:
translator.load(settings.LANGUAGE)
app.installTranslator(translator)
qtTranslator = QTranslator()
qtTranslator.load("qt_" + language, QLibraryInfo.location(QLibraryInfo.TranslationsPath))
app.installTranslator(qtTranslator)
# Loading Syntax
splash.showMessage("Loading Syntax", Qt.AlignRight | Qt.AlignTop, Qt.black)
json_manager.load_syntax()
# Read Settings
splash.showMessage("Loading Settings", Qt.AlignRight | Qt.AlignTop, Qt.black)
settings.load_settings()
# Set Stylesheet
style_applied = False
if settings.NINJA_SKIN not in ("Default", "Classic Theme"):
file_name = "%s.qss" % settings.NINJA_SKIN
qss_file = file_manager.create_path(resources.NINJA_THEME_DOWNLOAD, file_name)
if file_manager.file_exists(qss_file):
with open(qss_file) as f:
qss = f.read()
app.setStyleSheet(qss)
style_applied = True
if not style_applied:
if settings.NINJA_SKIN == "Default":
with open(resources.NINJA_THEME) as f:
qss = f.read()
else:
with open(resources.NINJA_THEME_CLASSIC) as f:
qss = f.read()
app.setStyleSheet(qss)
# Loading Schemes
splash.showMessage("Loading Schemes", Qt.AlignRight | Qt.AlignTop, Qt.black)
scheme = qsettings.value("preferences/editor/scheme", "default", type="QString")
if scheme != "default":
scheme = file_manager.create_path(resources.EDITOR_SKINS, scheme + ".color")
if file_manager.file_exists(scheme):
resources.CUSTOM_SCHEME = json_manager.parse(open(scheme))
# Loading Shortcuts
resources.load_shortcuts()
# Loading GUI
splash.showMessage("Loading GUI", Qt.AlignRight | Qt.AlignTop, Qt.black)
ninjaide = ide.IDE(start_server)
# Showing GUI
ninjaide.show()
# Loading Session Files
splash.showMessage("Loading Files and Projects", Qt.AlignRight | Qt.AlignTop, Qt.black)
# First check if we need to load last session files
if qsettings.value("preferences/general/loadFiles", True, type=bool):
# Files in Main Tab
main_files = qsettings.value("openFiles/mainTab", [])
#.........这里部分代码省略.........