예제 #1
0
    def open_file(self, filename="", cursorPosition=0, tabIndex=None, positionIsLineNumber=False, notStart=True):
        filename = unicode(filename)
        if not filename:
            if settings.WORKSPACE:
                directory = settings.WORKSPACE
            else:
                directory = os.path.expanduser("~")
                editorWidget = self.get_actual_editor()
                current_project = self._parent.explorer.get_actual_project()
                if current_project is not None:
                    directory = current_project
                elif editorWidget is not None and editorWidget.ID:
                    directory = file_manager.get_folder(editorWidget.ID)
            extensions = ";;".join(["(*%s)" % e for e in settings.SUPPORTED_EXTENSIONS + [".*", ""]])
            fileNames = list(QFileDialog.getOpenFileNames(self, self.tr("Open File"), directory, extensions))
        else:
            fileNames = [filename]
        if not fileNames:
            return

        for filename in fileNames:
            filename = unicode(filename)
            if file_manager.get_file_extension(filename) in ("jpg", "png"):
                self.open_image(filename)
            elif file_manager.get_file_extension(filename).endswith("ui"):
                self.w = uic.loadUi(filename)
                self.w.show()
            else:
                self.__open_file(filename, cursorPosition, tabIndex, positionIsLineNumber, notStart)
예제 #2
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))
예제 #3
0
파일: locator.py 프로젝트: DevNIX/ninja-ide
    def _grep_file_locate(self, file_path, file_name):
        #type - file_name - file_path
        global mapping_locations
        exts = settings.SYNTAX.get('python')['extension']
        if file_manager.get_file_extension(file_name) not in exts:
            mapping_locations[file_path] = [
                ResultItem(type=FILTERS['non-python'], name=file_name,
                    path=file_path, lineno=0)]
        else:
            mapping_locations[file_path] = [
                ResultItem(type=FILTERS['files'], name=file_name,
                        path=file_path, lineno=0)]
        ext = file_manager.get_file_extension(file_path)
        #obtain a symbols handler for this file extension
        symbols_handler = settings.get_symbols_handler(ext)
        if symbols_handler is None:
            return
        results = []
        with open(file_path) as f:
            content = f.read()
            symbols = symbols_handler.obtain_symbols(content,
                filename=file_path)
            self.__parse_symbols(symbols, results, file_path)

        if results:
            mapping_locations[file_path] += results
예제 #4
0
    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))
예제 #5
0
    def open_file(self, filename='', cursorPosition=0, \
                    tabIndex=None, positionIsLineNumber=False, notStart=True):
        filename = unicode(filename)
        if not filename:
            if settings.WORKSPACE:
                directory = settings.WORKSPACE
            else:
                directory = self._workingDirectory
            extensions = ';;'.join(
                ['(*%s)' % e for e in \
                    settings.SUPPORTED_EXTENSIONS + ['.*', '']])
            fileNames = list(QFileDialog.getOpenFileNames(self,
                self.tr("Open File"), directory, extensions))
        else:
            fileNames = [filename]
        if not fileNames:
            return

        for filename in fileNames:
            filename = unicode(filename)
            if file_manager.get_file_extension(filename) in ('jpg', 'png'):
                self.open_image(filename)
            elif file_manager.get_file_extension(filename).endswith('ui'):
                self.w = uic.loadUi(filename)
                self.w.show()
            else:
                self.__open_file(filename, cursorPosition,
                    tabIndex, positionIsLineNumber, notStart)
        self._workingDirectory = os.path.dirname(unicode(fileNames[-1]))
예제 #6
0
    def open_file(self, filename='', cursorPosition=-1,
                    tabIndex=None, positionIsLineNumber=False, notStart=True):
        if not filename:
            if settings.WORKSPACE:
                directory = settings.WORKSPACE
            else:
                directory = os.path.expanduser("~")
                editorWidget = self.get_actual_editor()
                pexplorer = self._parent.explorer
                current_project = pexplorer and pexplorer.get_actual_project()
                if current_project is not None:
                    directory = current_project
                elif editorWidget is not None and editorWidget.ID:
                    directory = file_manager.get_folder(editorWidget.ID)
            extensions = ';;'.join(
                ['(*%s)' % e for e in
                    settings.SUPPORTED_EXTENSIONS + ['.*', '']])
            fileNames = list(QFileDialog.getOpenFileNames(self,
                self.tr("Open File"), directory, extensions))
        else:
            fileNames = [filename]
        if not fileNames:
            return

        for filename in fileNames:
            if file_manager.get_file_extension(filename) in ('jpg', 'png'):
                self.open_image(filename)
            elif file_manager.get_file_extension(filename).endswith('ui'):
                self.w = uic.loadUi(filename)
                self.w.show()
            else:
                self.__open_file(filename, cursorPosition,
                    tabIndex, positionIsLineNumber, notStart)
예제 #7
0
    def _grep_file_locate(self, file_path, file_name):
        #type - file_name - file_path
        global mapping_locations
        exts = settings.SYNTAX.get('python')['extension']
        if file_manager.get_file_extension(file_name) not in exts:
            mapping_locations[file_path] = [
                ResultItem(type=FILTERS['non-python'],
                           name=file_name,
                           path=file_path,
                           lineno=0)
            ]
        else:
            mapping_locations[file_path] = [
                ResultItem(type=FILTERS['files'],
                           name=file_name,
                           path=file_path,
                           lineno=0)
            ]
        ext = file_manager.get_file_extension(file_path)
        #obtain a symbols handler for this file extension
        symbols_handler = settings.get_symbols_handler(ext)
        if symbols_handler is None:
            return
        results = []
        with open(file_path) as f:
            content = f.read()
            symbols = symbols_handler.obtain_symbols(content,
                                                     filename=file_path)
            self.__parse_symbols(symbols, results, file_path)

        if results:
            mapping_locations[file_path] += results
예제 #8
0
    def open_file(self, filename='', cursorPosition=-1,
                    tabIndex=None, positionIsLineNumber=False, notStart=True):
        if not filename:
            if settings.WORKSPACE:
                directory = settings.WORKSPACE
            else:
                directory = os.path.expanduser("~")
                editorWidget = self.get_actual_editor()
                pexplorer = self._parent.explorer
                current_project = pexplorer and pexplorer.get_actual_project()
                if current_project is not None:
                    directory = current_project
                elif editorWidget is not None and editorWidget.ID:
                    directory = file_manager.get_folder(editorWidget.ID)
            extensions = ';;'.join(
                ['(*%s)' % e for e in
                    settings.SUPPORTED_EXTENSIONS + ['.*', '']])
            fileNames = list(QFileDialog.getOpenFileNames(self,
                self.tr("Open File"), directory, extensions))
        else:
            fileNames = [filename]
        if not fileNames:
            return

        for filename in fileNames:
            if file_manager.get_file_extension(filename) in ('jpg', 'png'):
                self.open_image(filename)
            elif file_manager.get_file_extension(filename).endswith('ui'):
                self.w = uic.loadUi(filename)
                self.w.show()
            else:
                self.__open_file(filename, cursorPosition,
                    tabIndex, positionIsLineNumber, notStart)
예제 #9
0
    def open_file(self, fileName='', cursorPosition=0,\
                    tabIndex=None, positionIsLineNumber=False, notStart=True):
        fileName = unicode(fileName)
        if not fileName:
            if settings.WORKSPACE:
                directory = settings.WORKSPACE
            else:
                directory = self._workingDirectory
            extensions = ';;'.join(
                ['(*%s)' % e for e in \
                    settings.SUPPORTED_EXTENSIONS + ['.*', '']])
            fileName = unicode(QFileDialog.getOpenFileName(self,
                self.tr("Open File"), directory, extensions))
        if not fileName:
            return
        self._workingDirectory = os.path.dirname(fileName)

        if file_manager.get_file_extension(fileName) in ('jpg', 'png'):
            self.open_image(fileName)
        elif file_manager.get_file_extension(fileName).endswith('ui'):
            self.w = uic.loadUi(fileName)
            self.w.show()
        else:
            self.__open_file(fileName, cursorPosition,
                tabIndex, positionIsLineNumber, notStart)
예제 #10
0
파일: locator.py 프로젝트: uKev/ninja-ide
 def _grep_file_locate(self, file_path, file_name):
     #type - file_name - file_path
     global mapping_locations
     exts = settings.SYNTAX.get('python')['extension']
     if file_manager.get_file_extension(unicode(file_name)) not in exts:
         mapping_locations[unicode(file_path)] = [
             ResultItem(type=FILTERS['non-python'], name=unicode(file_name),
                 path=unicode(file_path), lineno=0)]
     else:
         mapping_locations[unicode(file_path)] = [
             ResultItem(type=FILTERS['files'], name=unicode(file_name),
                     path=unicode(file_path), lineno=0)]
     ext = file_manager.get_file_extension(file_path)
     #obtain a symbols handler for this file extension
     symbols_handler = settings.get_symbols_handler(ext)
     if symbols_handler is None:
         return
     results = []
     with open(file_path) as f:
         content = f.read()
         symbols = symbols_handler.obtain_symbols(content,
             filename=file_path)
         if "classes" in symbols:
             for claz in symbols['classes']:
                 line_number = symbols['classes'][claz][0] - 1
                 members = symbols['classes'][claz][1]
                 results.append(ResultItem(type=FILTERS['classes'],
                     name=claz, path=unicode(file_path),
                     lineno=line_number))
                 if 'attributes' in members:
                     for attr in members['attributes']:
                         line_number = members['attributes'][attr] - 1
                         results.append(ResultItem(type=FILTERS['attribs'],
                             name=attr, path=unicode(file_path),
                             lineno=line_number))
                 if 'functions' in members:
                     for func in members['functions']:
                         line_number = members['functions'][func] - 1
                         results.append(ResultItem(
                             type=FILTERS['functions'], name=func,
                             path=unicode(file_path), lineno=line_number))
         if 'attributes' in symbols:
             for attr in symbols['attributes']:
                 line_number = symbols['attributes'][attr] - 1
                 results.append(ResultItem(type=FILTERS['attribs'],
                     name=attr, path=unicode(file_path),
                     lineno=line_number))
         if 'functions' in symbols:
             for func in symbols['functions']:
                 line_number = symbols['functions'][func] - 1
                 results.append(ResultItem(
                     type=FILTERS['functions'], name=func,
                     path=unicode(file_path), lineno=line_number))
     if results:
         mapping_locations[unicode(file_path)] += results
예제 #11
0
 def _grep_file_locate(self, file_path, file_name):
     #type - file_name - file_path
     global mapping_locations
     exts = settings.SYNTAX.get('python')['extension']
     if file_manager.get_file_extension(unicode(file_name)) not in exts:
         mapping_locations[unicode(file_path)] = [
             ResultItem(type=FILTERS['non-python'], name=unicode(file_name),
                 path=unicode(file_path), lineno=0)]
     else:
         mapping_locations[unicode(file_path)] = [
             ResultItem(type=FILTERS['files'], name=unicode(file_name),
                     path=unicode(file_path), lineno=0)]
     ext = file_manager.get_file_extension(file_path)
     #obtain a symbols handler for this file extension
     symbols_handler = settings.get_symbols_handler(ext)
     if symbols_handler is None:
         return
     results = []
     with open(file_path) as f:
         content = f.read()
         symbols = symbols_handler.obtain_symbols(content,
             filename=file_path)
         if "classes" in symbols:
             for claz in symbols['classes']:
                 line_number = symbols['classes'][claz][0] - 1
                 members = symbols['classes'][claz][1]
                 results.append(ResultItem(type=FILTERS['classes'],
                     name=claz, path=unicode(file_path),
                     lineno=line_number))
                 if 'attributes' in members:
                     for attr in members['attributes']:
                         line_number = members['attributes'][attr] - 1
                         results.append(ResultItem(type=FILTERS['attribs'],
                             name=attr, path=unicode(file_path),
                             lineno=line_number))
                 if 'functions' in members:
                     for func in members['functions']:
                         line_number = members['functions'][func] - 1
                         results.append(ResultItem(
                             type=FILTERS['functions'], name=func,
                             path=unicode(file_path), lineno=line_number))
         if 'attributes' in symbols:
             for attr in symbols['attributes']:
                 line_number = symbols['attributes'][attr] - 1
                 results.append(ResultItem(type=FILTERS['attribs'],
                     name=attr, path=unicode(file_path),
                     lineno=line_number))
         if 'functions' in symbols:
             for func in symbols['functions']:
                 line_number = symbols['functions'][func] - 1
                 results.append(ResultItem(
                     type=FILTERS['functions'], name=func,
                     path=unicode(file_path), lineno=line_number))
     if results:
         mapping_locations[unicode(file_path)] += results
예제 #12
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
예제 #13
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
예제 #14
0
    def open_file(self, filename='', cursorPosition=-1,
                    tabIndex=None, positionIsLineNumber=False, notStart=True):
        if not filename:
            if settings.WORKSPACE:
                directory = settings.WORKSPACE
            else:
                directory = os.path.expanduser("~")
                editorWidget = self.get_actual_editor()
                pexplorer = self._parent.explorer
                current_project = pexplorer and pexplorer.get_actual_project()
                if current_project is not None:
                    directory = current_project
                elif editorWidget is not None and editorWidget.ID:
                    directory = file_manager.get_folder(editorWidget.ID)
            extensions = ';;'.join(
                ['(*%s)' % e for e in
                    settings.SUPPORTED_EXTENSIONS + ['.*', '']])
            fileNames = QFileDialog.getOpenFileNames(self,
                _translate("_s_MainContainer", "Open File"), directory, extensions)[0]#list()
        else:
            fileNames = [filename]
            #print(":::filename:", filename)
        if not fileNames:
            return

        othersFileNames = []
        for filename in fileNames:
            if QFileInfo(filename).isDir():
                othersFileNames.extend( QFileDialog.getOpenFileNames(None,
                    "Select files", filename, "Files (*.*)")[0] )
            elif file_manager.get_file_extension(filename) in ('jpg', 'png'):
                self.open_image(filename)
            elif file_manager.get_file_extension(filename).endswith('ui'):
                self.w = uic.loadUi(filename)
                self.w.show()
            else:
                self.__open_file(filename, cursorPosition,
                    tabIndex, positionIsLineNumber, notStart)

        for filename in othersFileNames:
            print("fileNames:::", filename)
            if QFileInfo(filename).isDir():
                continue
            elif file_manager.get_file_extension(filename) in ('jpg', 'png'):
                self.open_image(filename)
            elif file_manager.get_file_extension(filename).endswith('ui'):
                self.w = uic.loadUi(filename)
                self.w.show()
            else:
                self.__open_file(filename, cursorPosition,
                    tabIndex, positionIsLineNumber, notStart)
예제 #15
0
    def contextMenuEvent(self, event):
        popup_menu = self.createStandardContextMenu()

        menu_lint = QMenu(self.tr("Ignore Lint"))
        ignoreLineAction = menu_lint.addAction(
            self.tr("Ignore This Line"))
        ignoreSelectedAction = menu_lint.addAction(
            self.tr("Ignore Selected Area"))
        self.connect(ignoreLineAction, SIGNAL("triggered()"),
            lambda: helpers.lint_ignore_line(self))
        self.connect(ignoreSelectedAction, SIGNAL("triggered()"),
            lambda: helpers.lint_ignore_selection(self))
        popup_menu.insertSeparator(popup_menu.actions()[0])
        popup_menu.insertMenu(popup_menu.actions()[0], menu_lint)
        popup_menu.insertAction(popup_menu.actions()[0],
            self.__actionFindOccurrences)
        #add extra menus (from Plugins)
        lang = file_manager.get_file_extension(self.ID)
        extra_menus = self.EXTRA_MENU.get(lang, None)
        if extra_menus:
            popup_menu.addSeparator()
            for menu in extra_menus:
                popup_menu.addMenu(menu)
        #show menu
        popup_menu.exec_(event.globalPos())
예제 #16
0
파일: editor.py 프로젝트: uKev/ninja-ide
    def contextMenuEvent(self, event):
        popup_menu = self.createStandardContextMenu()

        #        menuRefactor = QMenu(self.tr("Refactor"))
        #        extractMethodAction = menuRefactor.addAction(
        #            self.tr("Extract as Method"))
        #        organizeImportsAction = menuRefactor.addAction(
        #            self.tr("Organize Imports"))
        #        removeUnusedAction = menuRefactor.addAction(
        #            self.tr("Remove Unused Imports"))
        #TODO
        #        self.connect(organizeImportsAction, SIGNAL("triggered()"),
        #            self.organize_imports)
        #        self.connect(removeUnusedAction, SIGNAL("triggered()"),
        #            self.remove_unused_imports)
        #        self.connect(extractMethodAction, SIGNAL("triggered()"),
        #            self.extract_method)
        popup_menu.insertSeparator(popup_menu.actions()[0])
        #        popup_menu.insertMenu(popup_menu.actions()[0], menuRefactor)
        popup_menu.insertAction(popup_menu.actions()[0],
                                self.__actionFindOccurrences)
        #add extra menus (from Plugins)
        lang = file_manager.get_file_extension(self.ID)
        extra_menus = self.EXTRA_MENU.get(lang, None)
        if extra_menus:
            popup_menu.addSeparator()
            for menu in extra_menus:
                popup_menu.addMenu(menu)
        #show menu
        popup_menu.exec_(event.globalPos())
예제 #17
0
 def get_symbols_for_class(self, file_path, clazzName):
     lines = []
     with open(file_path) as f:
         content = f.read()
         ext = file_manager.get_file_extension(file_path)
         #obtain a symbols handler for this file extension
         symbols_handler = settings.get_symbols_handler(ext)
         symbols = symbols_handler.obtain_symbols(content,
             filename=file_path)
         if "classes" in symbols:
             for claz in symbols['classes']:
                 if claz != clazzName:
                     continue
                 clazz = symbols['classes'][claz]
                 line_number = clazz[0] - 1
                 lines.append(ResultItem(type=FILTERS['classes'], name=claz,
                     path=unicode(file_path), lineno=line_number))
                 if 'attributes' in clazz[1]:
                     for attr in clazz[1]['attributes']:
                         line_number = clazz[1]['attributes'][attr] - 1
                         lines.append(ResultItem(
                             type=FILTERS['attribs'], name=attr,
                             path=unicode(file_path), lineno=line_number))
                 if 'functions' in clazz[1]:
                     for func in clazz[1]['functions']:
                         line_number = clazz[1]['functions'][func] - 1
                         lines.append(ResultItem(type=FILTERS['functions'],
                             name=func, path=unicode(file_path),
                             lineno=line_number))
                 return lines
         return []
예제 #18
0
 def get_symbols_for_class(self, file_path, clazzName):
     lines = []
     with open(file_path) as f:
         content = f.read()
         ext = file_manager.get_file_extension(file_path)
         #obtain a symbols handler for this file extension
         symbols_handler = settings.get_symbols_handler(ext)
         symbols = symbols_handler.obtain_symbols(content)
         if "classes" in symbols:
             for claz in symbols['classes']:
                 if claz != clazzName:
                     continue
                 clazz = symbols['classes'][claz]
                 #type - class name - file_path - lineNumber
                 lines.append(('<', claz, unicode(file_path), clazz[0] - 1))
                 if 'attributes' in clazz[1]:
                     for attr in clazz[1]['attributes']:
                         #type - attribute name - file_path - lineNumber
                         lines.append(('-', attr, unicode(file_path),
                                       clazz[1]['attributes'][attr] - 1))
                 if 'functions' in clazz[1]:
                     for func in clazz[1]['functions']:
                         #type - function name - file_path - lineNumber
                         lines.append(('>', func, unicode(file_path),
                                       clazz[1]['functions'][func] - 1))
                 return lines
         return []
예제 #19
0
    def run(self):
        self.sleep(1)
        exts = settings.SYNTAX.get('python')['extension']
        file_ext = file_manager.get_file_extension(self._path)
        if file_ext in exts:
            try:
                self.reset()
                source = self._editor.get_text()
                if self._encoding is not None:
                    source = source.encode(self._encoding)
                parseResult = compiler.parse(source)
                lint_checker = checker.Checker(parseResult, self._path)
                for m in lint_checker.messages:
                    lineno = m.lineno - 1
                    if lineno not in self.errorsSummary:
                        message = [m.message % m.message_args]
                    else:
                        message = self.errorsSummary[lineno]
                        message += [m.message % m.message_args]
                    self.errorsSummary[lineno] = message
            except Exception, reason:
                message = ''
                if hasattr(reason, 'msg'):
                    message = reason.msg
                else:
                    message = reason.message

                if hasattr(reason, 'lineno'):
                    self.errorsSummary[reason.lineno - 1] = [message]
                else:
                    self.errorsSummary[0] = [message]
            finally:
예제 #20
0
    def contextMenuEvent(self, event):
        popup_menu = self.createStandardContextMenu()

        menu_lint = QMenu(self.tr("Ignore Lint"))
        ignoreLineAction = menu_lint.addAction(
            self.tr("Ignore This Line"))
        ignoreSelectedAction = menu_lint.addAction(
            self.tr("Ignore Selected Area"))
        self.connect(ignoreLineAction, SIGNAL("triggered()"),
            lambda: helpers.lint_ignore_line(self))
        self.connect(ignoreSelectedAction, SIGNAL("triggered()"),
            lambda: helpers.lint_ignore_selection(self))
        popup_menu.insertSeparator(popup_menu.actions()[0])
        popup_menu.insertMenu(popup_menu.actions()[0], menu_lint)
        popup_menu.insertAction(popup_menu.actions()[0],
            self.__actionFindOccurrences)
        #add extra menus (from Plugins)
        lang = file_manager.get_file_extension(self.ID)
        extra_menus = self.EXTRA_MENU.get(lang, None)
        if extra_menus:
            popup_menu.addSeparator()
            for menu in extra_menus:
                popup_menu.addMenu(menu)
        #show menu
        popup_menu.exec_(event.globalPos())
예제 #21
0
 def run(self):
     if file_manager.get_file_extension(self._editor.ID) == 'py':
         self.reset()
         tempData = pep8mod.run_check(self._editor.ID)
         i = 0
         while i < len(tempData):
             lineno = -1
             try:
                 startPos = tempData[i].find('.py:') + 4
                 endPos = tempData[i].find(':', startPos)
                 lineno = int(tempData[i][startPos:endPos])
                 error = unicode(
                     tempData[i][tempData[i].find(':', endPos + 1) + 2:])
                 line = u'\n'.join(
                     [error, tempData[i + 1], tempData[i + 2]])
             except:
                 line = ''
             finally:
                 i += 3
             if line and lineno > -1:
                 if lineno not in self.pep8checks:
                     self.pep8checks[lineno] = [line]
                 else:
                     message = self.pep8checks[lineno]
                     message += [line]
                     self.pep8checks[lineno] = message
     else:
         self.reset()
예제 #22
0
파일: helpers.py 프로젝트: ntcong/ninja-ide
def uncomment(editorWidget):
    lang = file_manager.get_file_extension(editorWidget.ID)
    key = settings.EXTENSIONS.get(lang, 'python')
    comment_wildcard = settings.SYNTAX[key].get('comment', ['#'])[0]

    #cursor is a COPY all changes do not affect the QPlainTextEdit's cursor!!!
    cursor = editorWidget.textCursor()
    block = editorWidget.document().findBlock(
        cursor.selectionStart())
    end = editorWidget.document().findBlock(
        cursor.selectionEnd()).next()

    #Start a undo block
    cursor.beginEditBlock()

    while block != end:
        #Move the COPY cursor
        cursor.setPosition(block.position())
        cursor.movePosition(QTextCursor.Right, QTextCursor.KeepAnchor)
        text = cursor.selectedText()
        if text == comment_wildcard:
            cursor.removeSelectedText()
        block = block.next()

    #End a undo block
    cursor.endEditBlock()
예제 #23
0
 def _open_item(self, data):
     """Open the item received."""
     if file_manager.get_file_extension(data[2]) in ('jpg', 'png'):
         main_container.MainContainer().open_image(data[2])
     else:
         main_container.MainContainer().open_file(
             data[2], data[3], None, True)
    def _prettify(self):
        exts = settings.SYNTAX.get('html')['extension']
        file_ext = file_manager.get_file_extension(
            self.editor_s.get_editor_path())

        if file_ext in exts:
            editorWidget = self.editor_s.get_editor()
            if editorWidget:
                last_cursor_pos = editorWidget.get_cursor_position()

                source = self.editor_s.get_text()
                code_soup = BeautifulSoup(source, "html.parser")
                pretty_code = code_soup.prettify(formatter=inTagPrettify)
                #Cleaning the forgotten comments of the parser
                pretty_code = re.sub(r'<!--(.*?)-->',
                                     reformat_comments,
                                     pretty_code,
                                     flags=re.S)
                #Indenting all the code
                pretty_code = re.sub(r'^( *)(.*)$',
                                     r'%s\2' % (r'\1' * settings.INDENT),
                                     pretty_code,
                                     flags=re.M)
                editorWidget.selectAll()
                editorWidget.textCursor().insertText(pretty_code)

                editorWidget.set_cursor_position(last_cursor_pos)
예제 #25
0
 def run(self):
     if file_manager.get_file_extension(self._editor.ID) == 'py':
         self.reset()
         tempData = pep8mod.run_check(self._editor.ID)
         i = 0
         while i < len(tempData):
             lineno = -1
             try:
                 startPos = tempData[i].find('.py:') + 4
                 endPos = tempData[i].find(':', startPos)
                 lineno = int(tempData[i][startPos:endPos])
                 error = unicode(tempData[i][tempData[i].find(
                     ':', endPos + 1) + 2:])
                 line = u'\n'.join(
                     [error, tempData[i + 1], tempData[i + 2]])
             except:
                 line = ''
             finally:
                 i += 3
             if line and lineno > -1:
                 if lineno not in self.pep8checks:
                     self.pep8checks[lineno] = [line]
                 else:
                     message = self.pep8checks[lineno]
                     message += [line]
                     self.pep8checks[lineno] = message
     else:
         self.reset()
예제 #26
0
    def run(self):
        self.sleep(1)
        exts = settings.SYNTAX.get("python")["extension"]
        file_ext = file_manager.get_file_extension(self._editor.ID)
        if file_ext in exts:
            try:
                self.reset()
                source = self._editor.get_text()
                if self._editor.encoding is not None:
                    source = source.encode(self._editor.encoding)
                parseResult = compiler.parse(source)
                lint_checker = checker.Checker(parseResult, self._editor.ID)
                for m in lint_checker.messages:
                    lineno = m.lineno - 1
                    if lineno not in self.errorsSummary:
                        message = [m.message % m.message_args]
                    else:
                        message = self.errorsSummary[lineno]
                        message += [m.message % m.message_args]
                    self.errorsSummary[lineno] = message
            except Exception, reason:
                message = ""
                if hasattr(reason, "msg"):
                    message = reason.msg
                else:
                    message = reason.message

                if hasattr(reason, "lineno"):
                    self.errorsSummary[reason.lineno - 1] = [message]
                else:
                    self.errorsSummary[0] = [message]
            finally:
예제 #27
0
 def get_file_type(self, fileName):
     fileExtension = file_manager.get_file_extension(fileName)
     if fileExtension == "tx":
         return METAMODEL
     elif not fileExtension == "py":
         return MODEL
     return "py"
예제 #28
0
    def contextMenuEvent(self, event):
        popup_menu = self.createStandardContextMenu()

#        menuRefactor = QMenu(self.tr("Refactor"))
#        extractMethodAction = menuRefactor.addAction(
#            self.tr("Extract as Method"))
#        organizeImportsAction = menuRefactor.addAction(
#            self.tr("Organize Imports"))
#        removeUnusedAction = menuRefactor.addAction(
#            self.tr("Remove Unused Imports"))
        #TODO
#        self.connect(organizeImportsAction, SIGNAL("triggered()"),
#            self.organize_imports)
#        self.connect(removeUnusedAction, SIGNAL("triggered()"),
#            self.remove_unused_imports)
#        self.connect(extractMethodAction, SIGNAL("triggered()"),
#            self.extract_method)
        popup_menu.insertSeparator(popup_menu.actions()[0])
#        popup_menu.insertMenu(popup_menu.actions()[0], menuRefactor)
        popup_menu.insertAction(popup_menu.actions()[0],
            self.__actionFindOccurrences)
        #add extra menus (from Plugins)
        lang = file_manager.get_file_extension(self.ID)
        extra_menus = self.EXTRA_MENU.get(lang, None)
        if extra_menus:
            popup_menu.addSeparator()
            for menu in extra_menus:
                popup_menu.addMenu(menu)
        #show menu
        popup_menu.exec_(event.globalPos())
예제 #29
0
 def run(self):
     self.sleep(1)
     exts = settings.SYNTAX.get('python')['extension']
     file_ext = file_manager.get_file_extension(self._path)
     if file_ext in exts:
         self.reset()
         source = self._editor.get_text()
         tempData = pep8mod.run_check(self._path, source)
         i = 0
         while i < len(tempData):
             lineno = -1
             try:
                 offset = 2 + len(file_ext)
                 startPos = tempData[i].find('.%s:' % file_ext) + offset
                 endPos = tempData[i].find(':', startPos)
                 lineno = int(tempData[i][startPos:endPos]) - 1
                 error = tempData[i][tempData[i].find(
                     ':', endPos + 1) + 2:]
                 line = '\n'.join(
                     [error, tempData[i + 1], tempData[i + 2]])
             except Exception:
                 line = ''
             finally:
                 i += 3
             if line and lineno > -1:
                 if lineno not in self.pep8checks:
                     self.pep8checks[lineno] = [line]
                 else:
                     message = self.pep8checks[lineno]
                     message += [line]
                     self.pep8checks[lineno] = message
     else:
         self.reset()
예제 #30
0
파일: locator.py 프로젝트: DevNIX/ninja-ide
 def get_symbols_for_class(self, file_path, clazzName):
     lines = []
     with open(file_path) as f:
         content = f.read()
         ext = file_manager.get_file_extension(file_path)
         #obtain a symbols handler for this file extension
         symbols_handler = settings.get_symbols_handler(ext)
         symbols = symbols_handler.obtain_symbols(content,
             filename=file_path)
         if "classes" in symbols:
             for claz in symbols['classes']:
                 if claz != clazzName:
                     continue
                 clazz = symbols['classes'][claz]
                 line_number = clazz[0] - 1
                 lines.append(ResultItem(type=FILTERS['classes'], name=claz,
                     path=file_path, lineno=line_number))
                 if 'attributes' in clazz[1]:
                     for attr in clazz[1]['attributes']:
                         line_number = clazz[1]['attributes'][attr] - 1
                         lines.append(ResultItem(
                             type=FILTERS['attribs'], name=attr,
                             path=file_path, lineno=line_number))
                 if 'functions' in clazz[1]:
                     for func in clazz[1]['functions']:
                         line_number = clazz[1]['functions'][func][0] - 1
                         lines.append(ResultItem(type=FILTERS['functions'],
                             name=func, path=file_path,
                             lineno=line_number))
                 return lines
         return []
예제 #31
0
 def run(self):
     self.sleep(1)
     exts = settings.SYNTAX.get('python')['extension']
     file_ext = file_manager.get_file_extension(self._path)
     if file_ext in exts:
         self.reset()
         source = self._editor.get_text()
         if self._encoding is not None:
             source = source.encode(self._encoding)
         tempData = pep8mod.run_check(self._path, source)
         i = 0
         while i < len(tempData):
             lineno = -1
             try:
                 offset = 2 + len(file_ext)
                 startPos = tempData[i].find('.%s:' % file_ext) + offset
                 endPos = tempData[i].find(':', startPos)
                 lineno = int(tempData[i][startPos:endPos]) - 1
                 error = unicode(tempData[i][tempData[i].find(
                     ':', endPos + 1) + 2:])
                 line = u'\n'.join(
                     [error, tempData[i + 1], tempData[i + 2]])
             except:
                 line = ''
             finally:
                 i += 3
             if line and lineno > -1:
                 if lineno not in self.pep8checks:
                     self.pep8checks[lineno] = [line]
                 else:
                     message = self.pep8checks[lineno]
                     message += [line]
                     self.pep8checks[lineno] = message
     else:
         self.reset()
예제 #32
0
 def run(self):
     self.sleep(2)
     exts = settings.SYNTAX.get('python')['extension']
     file_ext = file_manager.get_file_extension(self._editor.ID)
     if file_ext in exts:
         try:
             self.reset()
             source = self._editor.get_text()
             if self._editor.encoding is not None:
                 source = source.encode(self._editor.encoding)
             parseResult = compiler.parse(source)
             self.checker = checker.Checker(parseResult, self._editor.ID)
             for m in self.checker.messages:
                 lineno = m.lineno - 1
                 if lineno not in self.errorsSummary:
                     message = [m.message % m.message_args]
                 else:
                     message = self.errorsSummary[lineno]
                     message += [m.message % m.message_args]
                 self.errorsSummary[lineno] = message
         except Exception, reason:
             if hasattr(reason, 'lineno'):
                 self.errorsSummary[reason.lineno - 1] = [reason.message]
             else:
                 self.errorsSummary[0] = [reason.message]
예제 #33
0
 def get_symbols_for_class(self, file_path, clazzName):
     lines = []
     with open(file_path) as f:
         content = f.read()
         ext = file_manager.get_file_extension(file_path)
         #obtain a symbols handler for this file extension
         symbols_handler = settings.get_symbols_handler(ext)
         symbols = symbols_handler.obtain_symbols(content)
         if "classes" in symbols:
             for claz in symbols['classes']:
                 if claz != clazzName:
                     continue
                 clazz = symbols['classes'][claz]
                 #type - class name - file_path - lineNumber
                 lines.append(('<', claz, unicode(file_path),
                     clazz[0] - 1))
                 if 'attributes' in clazz[1]:
                     for attr in clazz[1]['attributes']:
                         #type - attribute name - file_path - lineNumber
                         lines.append(('-', attr, unicode(file_path),
                             clazz[1]['attributes'][attr] - 1))
                 if 'functions' in clazz[1]:
                     for func in clazz[1]['functions']:
                         #type - function name - file_path - lineNumber
                         lines.append(('>', func, unicode(file_path),
                             clazz[1]['functions'][func] - 1))
                 return lines
         return []
예제 #34
0
파일: locator.py 프로젝트: uKev/ninja-ide
 def _open_item(self, data):
     """Open the item received."""
     if file_manager.get_file_extension(data.path) in ('jpg', 'png'):
         main_container.MainContainer().open_image(data.path)
     else:
         main_container.MainContainer().open_file(data.path, data.lineno,
                                                  None, True)
예제 #35
0
 def get_file_syntax(self, editorWidget=None):
     """Return the syntax for this file -> {}."""
     if editorWidget is None:
         editorWidget = self._main.get_actual_editor()
     ext = file_manager.get_file_extension(editorWidget.ID)
     lang = settings.EXTENSIONS.get(ext, "")
     syntax = settings.SYNTAX.get(lang, {})
     return syntax
예제 #36
0
 def preview_in_browser(self):
     editorWidget = self.ide.mainContainer.get_actual_editor()
     if editorWidget:
         if not editorWidget.ID:
             self.ide.mainContainer.save_file()
         ext = file_manager.get_file_extension(editorWidget.ID)
         if ext == 'html':
             webbrowser.open(editorWidget.ID)
예제 #37
0
 def preview_in_browser(self):
     editorWidget = self.ide.mainContainer.get_actual_editor()
     if editorWidget:
         if not editorWidget.ID:
             self.ide.mainContainer.save_file()
         ext = file_manager.get_file_extension(editorWidget.ID)
         if ext == 'html':
             webbrowser.open(editorWidget.ID)
예제 #38
0
    def _grep_file_locate(self, file_path, file_name):
        #type - file_name - file_path
        global mapping_locations
        if file_manager.get_file_extension(unicode(file_name)) != 'py':
            mapping_locations[unicode(file_path)] = [('!',
                unicode(file_name), unicode(file_path), 0)]
            return
        mapping_locations[unicode(file_path)] = [('@', unicode(file_name),
            unicode(file_path), 0)]

        lines = []
        with open(file_path) as f:
            content = f.read()
            ext = file_manager.get_file_extension(file_path)
            #obtain a symbols handler for this file extension
            symbols_handler = settings.get_symbols_handler(ext)
            symbols = symbols_handler.obtain_symbols(content)
            if "classes" in symbols:
                for claz in symbols['classes']:
                    clazz = symbols['classes'][claz]
                    #type - class name - file_path - lineNumber
                    lines.append(('<', claz, unicode(file_path),
                        clazz[0] - 1))
                    if 'attributes' in clazz[1]:
                        for attr in clazz[1]['attributes']:
                            #type - attribute name - file_path - lineNumber
                            lines.append(('-', attr, unicode(file_path),
                                clazz[1]['attributes'][attr] - 1))
                    if 'functions' in clazz[1]:
                        for func in clazz[1]['functions']:
                            #type - function name - file_path - lineNumber
                            lines.append(('>', func, unicode(file_path),
                                clazz[1]['functions'][func] - 1))
            if 'attributes' in symbols:
                for attr in symbols['attributes']:
                    #type - attribute name - file_path - lineNumber
                    lines.append(('-', attr, unicode(file_path),
                        symbols['attributes'][attr] - 1))
            if 'functions' in symbols:
                for func in symbols['functions']:
                    #type - function name - file_path - lineNumber
                    lines.append(('>', func, unicode(file_path),
                        symbols['functions'][func] - 1))
        if lines:
            mapping_locations[unicode(file_path)] += lines
예제 #39
0
 def preview_in_browser(self):
     """Load the current html file in the default browser."""
     editorWidget = self.ide.mainContainer.get_actual_editor()
     if editorWidget:
         if not editorWidget.ID:
             self.ide.mainContainer.save_file()
         ext = file_manager.get_file_extension(editorWidget.ID)
         if ext == 'html':
             webbrowser.open(editorWidget.ID)
예제 #40
0
 def preview_in_browser(self):
     """Load the current html file in the default browser."""
     editorWidget = self.ide.mainContainer.get_actual_editor()
     if editorWidget:
         if not editorWidget.ID:
             self.ide.mainContainer.save_file()
         ext = file_manager.get_file_extension(editorWidget.ID)
         if ext == 'html':
             webbrowser.open(editorWidget.ID)
예제 #41
0
def insert_horizontal_line(editorWidget):
    editorWidget.moveCursor(QTextCursor.StartOfLine, QTextCursor.KeepAnchor)
    text = unicode(editorWidget.textCursor().selection().toPlainText())
    editorWidget.moveCursor(QTextCursor.EndOfLine, QTextCursor.MoveAnchor)
    lang = file_manager.get_file_extension(editorWidget.ID)
    key = settings.EXTENSIONS.get(lang, 'python')
    comment_wildcard = settings.SYNTAX[key].get('comment', ['#'])[0]
    comment = comment_wildcard * ((79 - len(text)) / len(comment_wildcard))
    editorWidget.textCursor().insertText(comment)
예제 #42
0
파일: helpers.py 프로젝트: uKev/ninja-ide
def insert_horizontal_line(editorWidget):
    editorWidget.moveCursor(QTextCursor.StartOfLine, QTextCursor.KeepAnchor)
    text = unicode(editorWidget.textCursor().selection().toPlainText())
    editorWidget.moveCursor(QTextCursor.EndOfLine, QTextCursor.MoveAnchor)
    lang = file_manager.get_file_extension(editorWidget.ID)
    key = settings.EXTENSIONS.get(lang, 'python')
    comment_wildcard = settings.SYNTAX[key].get('comment', ['#'])[0]
    comment = comment_wildcard * ((79 - len(text)) / len(comment_wildcard))
    editorWidget.textCursor().insertText(comment)
예제 #43
0
    def _grep_file_locate(self, file_path, file_name):
        #type - file_name - file_path
        global mapping_locations
        if file_manager.get_file_extension(unicode(file_name)) != 'py':
            mapping_locations[unicode(file_path)] = [('!', unicode(file_name),
                                                      unicode(file_path), 0)]
            return
        mapping_locations[unicode(file_path)] = [('@', unicode(file_name),
                                                  unicode(file_path), 0)]

        lines = []
        with open(file_path) as f:
            content = f.read()
            ext = file_manager.get_file_extension(file_path)
            #obtain a symbols handler for this file extension
            symbols_handler = settings.get_symbols_handler(ext)
            symbols = symbols_handler.obtain_symbols(content)
            if "classes" in symbols:
                for claz in symbols['classes']:
                    clazz = symbols['classes'][claz]
                    #type - class name - file_path - lineNumber
                    lines.append(('<', claz, unicode(file_path), clazz[0] - 1))
                    if 'attributes' in clazz[1]:
                        for attr in clazz[1]['attributes']:
                            #type - attribute name - file_path - lineNumber
                            lines.append(('-', attr, unicode(file_path),
                                          clazz[1]['attributes'][attr] - 1))
                    if 'functions' in clazz[1]:
                        for func in clazz[1]['functions']:
                            #type - function name - file_path - lineNumber
                            lines.append(('>', func, unicode(file_path),
                                          clazz[1]['functions'][func] - 1))
            if 'attributes' in symbols:
                for attr in symbols['attributes']:
                    #type - attribute name - file_path - lineNumber
                    lines.append(('-', attr, unicode(file_path),
                                  symbols['attributes'][attr] - 1))
            if 'functions' in symbols:
                for func in symbols['functions']:
                    #type - function name - file_path - lineNumber
                    lines.append(('>', func, unicode(file_path),
                                  symbols['functions'][func] - 1))
        if lines:
            mapping_locations[unicode(file_path)] += lines
 def _open_with_pep8(self):
     exts = settings.SYNTAX.get('python')['extension']
     file_ext = file_manager.get_file_extension(
         self.editor_s.get_editor_path())
     if file_ext in exts:
         editorWidget = self.editor_s.get_editor()
         if editorWidget:
             source = self.editor_s.get_text()
             fixed_source = autopep8.fix_string(source)
             self.editor_s.add_editor("", fixed_source, "py")
예제 #45
0
파일: locator.py 프로젝트: DevNIX/ninja-ide
 def _open_item(self, data):
     """Open the item received."""
     main = main_container.MainContainer()
     if file_manager.get_file_extension(data.path) in ('jpg', 'png'):
         main.open_image(data.path)
     else:
         if self._line_jump != -1:
             main.open_file(data.path, self._line_jump, None, True)
         else:
             main.open_file(data.path, data.lineno, None, True)
예제 #46
0
 def restyle(self, syntaxLang=None):
     styles.set_editor_style(self, resources.CUSTOM_SCHEME)
     if not syntaxLang:
         ext = file_manager.get_file_extension(self.ID)
         self.highlighter.apply_highlight(
             settings.EXTENSIONS.get(ext, 'python'),
             resources.CUSTOM_SCHEME)
     else:
         self.highlighter.apply_highlight(
             str(syntaxLang), resources.CUSTOM_SCHEME)
 def _open_with_pep8(self):
     exts = settings.SYNTAX.get('python')['extension']
     file_ext = file_manager.get_file_extension(
         self.editor_s.get_editor_path())
     if file_ext in exts:
         editorWidget = self.editor_s.get_editor()
         if editorWidget:
             source = self.editor_s.get_text()
             fixed_source = autopep8.fix_string(source)
             self.editor_s.add_editor("", fixed_source, "py")
예제 #48
0
 def get_symbols_for_class(self, file_path, clazzName):
     results = []
     with open(file_path) as f:
         content = f.read()
         ext = file_manager.get_file_extension(file_path)
         #obtain a symbols handler for this file extension
         symbols_handler = settings.get_symbols_handler(ext)
         symbols = symbols_handler.obtain_symbols(content,
                                                  filename=file_path)
         self.__parse_symbols(symbols, results, file_path)
     return results
예제 #49
0
    def get_file_syntax(self, editorWidget=None):
        """Return the syntax for this file -> {}."""
        if editorWidget is None:
            editorWidget = self._main.get_actual_editor()

        if editorWidget is not None:
            ext = file_manager.get_file_extension(editorWidget.ID)
            lang = settings.EXTENSIONS.get(ext, '')
            syntax = settings.SYNTAX.get(lang, {})
            return syntax
        return {}
예제 #50
0
    def open_file(self, fileName="", cursorPosition=0, tabIndex=None, positionIsLineNumber=False, notStart=True):
        fileName = unicode(fileName)
        if not fileName:
            if settings.WORKSPACE:
                directory = settings.WORKSPACE
            else:
                directory = self._workingDirectory
            extensions = ";;".join(["(*%s)" % e for e in settings.SUPPORTED_EXTENSIONS + [".*", ""]])
            fileName = unicode(QFileDialog.getOpenFileName(self, self.tr("Open File"), directory, extensions))
        if not fileName:
            return
        self._workingDirectory = os.path.dirname(fileName)

        if file_manager.get_file_extension(fileName) in ("jpg", "png"):
            self.open_image(fileName)
        elif file_manager.get_file_extension(fileName).endswith("ui"):
            self.w = uic.loadUi(fileName)
            self.w.show()
        else:
            self.__open_file(fileName, cursorPosition, tabIndex, positionIsLineNumber, notStart)
예제 #51
0
 def __post_execution(self):
     """Execute a script after executing the project."""
     filePostExec = QFile(self.postExec)
     if filePostExec.exists() and bool(QFile.ExeUser & filePostExec.permissions()):
         ext = file_manager.get_file_extension(self.postExec)
         if not self.pythonPath:
             self.pythonPath = settings.PYTHON_PATH
         self.currentProcess = self._postExecScriptProc
         if ext == "py":
             self._postExecScriptProc.start(self.pythonPath, [self.postExec])
         else:
             self._postExecScriptProc.start(self.postExec)
예제 #52
0
 def execute_file(self):
     """Execute the current file."""
     editorWidget = self.ide.mainContainer.get_actual_editor()
     #emit a signal for plugin!
     self.emit(SIGNAL("fileExecuted(QString)"), editorWidget.ID)
     if editorWidget:
         self.ide.mainContainer.save_file(editorWidget)
         ext = file_manager.get_file_extension(editorWidget.ID)
         #TODO: Remove the IF statment with polymorphism using Handler
         if ext == 'py':
             self.ide.misc.run_application(editorWidget.ID)
         elif ext == 'html':
             self.ide.misc.render_web_page(editorWidget.ID)
예제 #53
0
 def execute_file(self):
     """Execute the current file."""
     editorWidget = self.ide.mainContainer.get_actual_editor()
     #emit a signal for plugin!
     self.emit(SIGNAL("fileExecuted(QString)"), editorWidget.ID)
     if editorWidget:
         self.ide.mainContainer.save_file(editorWidget)
         ext = file_manager.get_file_extension(editorWidget.ID)
         #TODO: Remove the IF statment with polymorphism using Handler
         if ext == 'py':
             self.ide.misc.run_application(editorWidget.ID)
         elif ext == 'html':
             self.ide.misc.render_web_page(editorWidget.ID)
예제 #54
0
 def restyle(self, syntaxLang=None):
     styles.set_editor_style(self, resources.CUSTOM_SCHEME)
     if self.highlighter is None:
         self.highlighter = highlighter.Highlighter(self.document(), None,
                                                    resources.CUSTOM_SCHEME)
     if not syntaxLang:
         ext = file_manager.get_file_extension(self.ID)
         self.highlighter.apply_highlight(
             settings.EXTENSIONS.get(ext, 'python'),
             resources.CUSTOM_SCHEME)
     else:
         self.highlighter.apply_highlight(str(syntaxLang),
                                          resources.CUSTOM_SCHEME)
예제 #55
0
def create_editor(fileName='', project=None, syntax=None):
    editor = Editor(fileName, project)
    #if syntax is specified, use it
    if syntax:
        editor.register_syntax(syntax)
    else:
        #try to set a syntax based on the file extension
        ext = file_manager.get_file_extension(fileName)
        if ext not in settings.EXTENSIONS and fileName == '':
            #by default use python syntax
            editor.register_syntax('py')
        else:
            editor.register_syntax(ext)
    return editor
예제 #56
0
 def __post_execution(self):
     """Execute a script after executing the project."""
     filePostExec = QFile(self.postExec)
     if filePostExec.exists() and \
       bool(QFile.ExeUser & filePostExec.permissions()):
         ext = file_manager.get_file_extension(self.postExec)
         if not self.pythonPath:
             self.pythonPath = settings.PYTHON_PATH
         self.currentProcess = self._postExecScriptProc
         if ext == 'py':
             self._postExecScriptProc.start(self.pythonPath,
                 [self.postExec])
         else:
             self._postExecScriptProc.start(self.postExec)
    def _rewrite_pep8(self):
        exts = settings.SYNTAX.get('python')['extension']
        file_ext = file_manager.get_file_extension(
            self.editor_s.get_editor_path())
        if file_ext in exts:
            editorWidget = self.editor_s.get_editor()
            if editorWidget:
                last_cursor_pos = editorWidget.get_cursor_position()

                source = self.editor_s.get_text()
                fixed_source = autopep8.fix_string(source)
                editorWidget.selectAll()
                editorWidget.textCursor().insertText(fixed_source)

                editorWidget.set_cursor_position(last_cursor_pos)
예제 #58
0
 def run(self):
     if file_manager.get_file_extension(self._editor.ID) == 'py':
         try:
             self.reset()
             parseResult = compiler.parse(open(self._editor.ID).read())
             self.checker = checker.Checker(parseResult, self._editor.ID)
             for m in self.checker.messages:
                 if m.lineno not in self.errorsSummary:
                     message = [m.message % m.message_args]
                 else:
                     message = self.errorsSummary[m.lineno]
                     message += [m.message % m.message_args]
                 self.errorsSummary[m.lineno] = message
         except Exception, reason:
             self.errorsSummary[reason.lineno] = reason.msg
예제 #59
0
    def update_explorer(self):
        editorWidget = self.ide.mainContainer.get_actual_editor()
        if editorWidget:
            ext = file_manager.get_file_extension(editorWidget.ID)
            #obtain a symbols handler for this file extension
            symbols_handler = settings.get_symbols_handler(ext)
            if symbols_handler:
                source = unicode(editorWidget.toPlainText())
                source = source.encode(editorWidget.encoding)
                symbols = symbols_handler.obtain_symbols(source)
                self.ide.explorer.update_symbols(symbols, editorWidget.ID)

            #TODO: Should we change the code below similar to the code above?
            if ext == 'py' or editorWidget.newDocument:
                self.ide.explorer.update_errors(
                    editorWidget.errors, editorWidget.pep8)