コード例 #1
0
ファイル: find_in_files.py プロジェクト: alekibango/ninja-ide
 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)
コード例 #2
0
    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
            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)
            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!"))
コード例 #3
0
ファイル: find_in_files.py プロジェクト: manuq/ninja-ide
 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)
             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)
コード例 #4
0
ファイル: main_container.py プロジェクト: dlitvakb/ninja-ide
    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!"))
コード例 #5
0
ファイル: find_in_files.py プロジェクト: ardfard/ninja-ide
    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)
コード例 #6
0
ファイル: find_in_files.py プロジェクト: AlexaProjects/Alexa2
    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)
コード例 #7
0
 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))
コード例 #8
0
    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))
コード例 #9
0
ファイル: actions.py プロジェクト: alekibango/ninja-ide
 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))
コード例 #10
0
 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))
コード例 #11
0
 def _add_file_to_project(self, path):
     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))
コード例 #12
0
    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))
コード例 #13
0
    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))
コード例 #14
0
    def save_file_as(self):
        editorWidget = self.get_actual_editor()
        if not editorWidget:
            return False
        try:
            fileName = unicode(QFileDialog.getSaveFileName(
                self._parent, self.tr("Save File"), '', '(*.py);;(*.*)'))
            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))
コード例 #15
0
 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))
コード例 #16
0
 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))
コード例 #17
0
 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))
コード例 #18
0
ファイル: main_container.py プロジェクト: beefsack/ninja-ide
    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))
コード例 #19
0
 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))
コード例 #20
0
    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
コード例 #21
0
    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))
コード例 #22
0
ファイル: pluginProject.py プロジェクト: AlexaProjects/Alexa2
    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))
コード例 #23
0
    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: %s" % fileName))
            editorWidget._file_saved()
            return True
        except Exception as reason:
            print(reason)
            raise
            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
コード例 #24
0
ファイル: main_container.py プロジェクト: sbellem/ninja-ide
    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
コード例 #25
0
ファイル: main_container.py プロジェクト: sanyaade/ninja-ide
    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!"))
コード例 #26
0
 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, 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(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(
             self, self.tr("File Already Exists"),
             (self.tr("Invalid Path: the file '%s' already exists.") %
              ex.filename))
コード例 #27
0
ファイル: actions.py プロジェクト: Salmista-94/Ninja_PyQt5
 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))
コード例 #28
0
ファイル: alexatools.py プロジェクト: AlexaProjects/Alexa2
    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)
コード例 #29
0
ファイル: alexatools.py プロジェクト: vafaronaghi/Alexa2
    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)