当前位置: 首页>>代码示例>>Python>>正文


Python file_manager.get_file_extension函数代码示例

本文整理汇总了Python中ninja_ide.core.file_handling.file_manager.get_file_extension函数的典型用法代码示例。如果您正苦于以下问题:Python get_file_extension函数的具体用法?Python get_file_extension怎么用?Python get_file_extension使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_file_extension函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: open_file

    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_current_editor()
                ninjaide = IDE.get_service('ide')
                if ninjaide:
                    current_project = ninjaide.get_current_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)
开发者ID:pdorrell,项目名称:ninja-ide,代码行数:34,代码来源:main_container.py

示例2: save_file_as

    def save_file_as(self):
        editorWidget = self.get_current_editor()
        if not editorWidget:
            return False
        try:
            filters = "(*.py);;(*.*)"
            if editorWidget.file_path:
                ext = file_manager.get_file_extension(editorWidget.file_path)
                if ext != "py":
                    filters = "(*.%s);;(*.py);;(*.*)" % ext
            save_folder = self._get_save_folder(editorWidget.file_path)
            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)

            editorWidget.neditable.save_content(path=fileName)
            editorWidget.register_syntax(file_manager.get_file_extension(fileName))

            self.emit(SIGNAL("fileSaved(QString)"), (self.tr("File Saved: %s") % fileName))
            self.emit(SIGNAL("currentEditorChanged(QString)"), fileName)
            return True
        except file_manager.NinjaFileExistsException as ex:
            QMessageBox.information(
                self,
                self.tr("File Already Exists"),
                (self.tr("Invalid Path: the file '%s' " " already exists.") % ex.filename),
            )
        except Exception as reason:
            logger.error("save_file_as: %s", reason)
            QMessageBox.information(self, self.tr("Save Error"), self.tr("The file couldn't be saved!"))
        return False
开发者ID:perrito666,项目名称:ninja-ide,代码行数:34,代码来源:main_container.py

示例3: save_file_as

    def save_file_as(self):
        editorWidget = self.get_current_editor()
        if not editorWidget:
            return False
        nfile = editorWidget.nfile
        try:
            #editorWidget.just_saved = True
            filters = '(*.py);;(*.*)'
            if nfile.file_path:
                ext = file_manager.get_file_extension(nfile.file_path)
                if ext != 'py':
                    filters = '(*.%s);;(*.py);;(*.*)' % ext
            save_folder = self._get_save_folder(nfile.file_path)
            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) == ''
            nfile.save(editorWidget.get_text(), path=fileName)
            print editorWidget.nfile._file_path
            #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
开发者ID:pdorrell,项目名称:ninja-ide,代码行数:54,代码来源:main_container.py

示例4: save_file_as

    def save_file_as(self, editor_widget=None):
        force = False
        if editor_widget is None:
            # We invoque from menu
            editor_widget = self.get_current_editor()
            if editor_widget is None:
                # We haven't editor in main container
                return False
            force = True
        try:
            filters = "(*.py);;(*.*)"
            if editor_widget.file_path is not None:  # Existing file
                extension = file_manager.get_file_extension(
                    editor_widget.file_path)
                if extension != 'py':
                    filters = "(*.%s);;(*.py);;(*.*)" % extension
                save_folder = self._get_save_folder(editor_widget.file_path)
            else:
                save_folder = settings.WORKSPACE

            filename = QFileDialog.getSaveFileName(
                self,
                translations.TR_SAVE_FILE_DIALOG,
                save_folder,
                filters
            )[0]
            if not filename:
                return False
            # FIXME: remove trailing spaces
            extension = file_manager.get_file_extension(filename)
            if not extension:
                filename = "%s.%s" % (filename, "py")
            editor_widget.neditable.save_content(path=filename, force=force)
            # self._setter_language.set_language_from_extension(extension)
            self.fileSaved.emit(translations.TR_FILE_SAVED.format(filename))
            self.currentEditorChanged.emit(filename)
            return True
        except file_manager.NinjaFileExistsException as reason:
            QMessageBox.information(
                self,
                translations.TR_FILE_ALREADY_EXISTS_TITLE,
                translations.TR_FILE_ALREADY_EXISTS_BODY.format(
                    reason.filename)
            )
        except Exception as reason:
            logger.error("Save file as: %s", reason)
            QMessageBox.information(
                self,
                translations.TR_SAVE_FILE_ERROR_TITLE,
                translations.TR_SAVE_FILE_ERROR_BODY
            )
        return False
开发者ID:ninja-ide,项目名称:ninja-ide,代码行数:52,代码来源:main_container.py

示例5: contextMenuEvent

    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())
开发者ID:pdorrell,项目名称:ninja-ide,代码行数:25,代码来源:editor.py

示例6: run

 def run(self):
     exts = settings.SYNTAX.get('python')['extension']
     file_ext = file_manager.get_file_extension(self._path)
     not_imports = dict()
     if file_ext in exts:
         self.reset()
         # source = self._editor.text
         path = self._editor.file_path
         checker = nic.Checker(path)
         not_imports = checker.get_not_imports_on_file(
             checker.get_imports())
         if not_imports is None:
             pass
         else:
             for key, values in not_imports.items():
                 if isinstance(values['mod_name'], dict):
                     for v in values['mod_name']:
                         message = '[NOTIMP] {}: Dont exist'.format(
                             v)
                 else:
                     message = '[NOTIMP] {}: Dont exist'.format(
                             values['mod_name'])
                 range_ = helpers.get_range(
                     self._editor, values['lineno'] - 1)
                 self.checks[values['lineno'] - 1].append(
                     (range_, message, ""))
     self.checkerCompleted.emit()
开发者ID:ninja-ide,项目名称:ninja-ide,代码行数:27,代码来源:not_import_checker.py

示例7: _filter_this_file

 def _filter_this_file(self, filterOptions, index):
     at_start = (index == 0)
     if at_start:
         main_container = IDE.get_service('main_container')
         editorWidget = None
         if main_container:
             editorWidget = main_container.get_current_editor()
         index += 2
         if editorWidget:
             exts = settings.SYNTAX.get('python')['extension']
             file_ext = file_manager.get_file_extension(
                 editorWidget.file_path)
             if file_ext in exts:
                 filterOptions.insert(0, locator.FILTERS['files'])
             else:
                 filterOptions.insert(0, locator.FILTERS['non-python'])
             filterOptions.insert(1, editorWidget.file_path)
             self.tempLocations = \
                 self.locate_symbols.get_this_file_symbols(
                     editorWidget.file_path)
             search = filterOptions[index + 1].lstrip().lower()
             self.tempLocations = [x for x in self.tempLocations
                                   if x.comparison.lower().find(search) > -1]
     else:
         del filterOptions[index + 1]
         del filterOptions[index]
     return index
开发者ID:ninja-ide,项目名称:ninja-ide,代码行数:27,代码来源:locator_widget.py

示例8: _filter_lines

 def _filter_lines(self, filterOptions, index):
     at_start = (index == 0)
     if at_start:
         main_container = IDE.get_service('main_container')
         editorWidget = None
         if main_container:
             editorWidget = main_container.get_current_editor()
         index = 2
         if editorWidget:
             exts = settings.SYNTAX.get('python')['extension']
             file_ext = file_manager.get_file_extension(
                 editorWidget.file_path)
             if file_ext in exts:
                 filterOptions.insert(0, locator.FILTERS['files'])
             else:
                 filterOptions.insert(0, locator.FILTERS['non-python'])
             filterOptions.insert(1, editorWidget.file_path)
         self.tempLocations = [
             x for x in self.locate_symbols.get_locations()
             if x.type == filterOptions[0] and
             x.path == filterOptions[1]]
     else:
         currentItem = self._root.currentItem()
         if currentItem is not None:
             currentItem = currentItem.toVariant()
             self.tempLocations = [
                 x for x in self.locate_symbols.get_locations()
                 if x.type == currentItem[0] and
                 x.path == currentItem[2]]
     if filterOptions[index + 1].isdigit():
         self._line_jump = int(filterOptions[index + 1]) - 1
     return index + 2
开发者ID:ninja-ide,项目名称:ninja-ide,代码行数:32,代码来源:locator_widget.py

示例9: run

    def run(self):
        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.text
                path = self._editor.file_path
                pep8_style = pycodestyle.StyleGuide(
                    parse_argv=False,
                    config_file='',
                    checker_class=CustomChecker
                )
                temp_data = pep8_style.input_file(
                    path,
                    lines=source.splitlines(True)
                )

                source_lines = source.split('\n')
                # for lineno, offset, code, text, doc in temp_data:
                for lineno, col, code, text in temp_data:
                    message = '[PEP8]: %s' % text
                    range_ = helpers.get_range(self._editor, lineno - 1, col)
                    self.checks[lineno - 1].append(
                        (range_, message, source_lines[lineno - 1].strip()))
            except Exception as reason:
                logger.warning("Checker not finished: {}".format(reason))
        self.checkerCompleted.emit()
开发者ID:ninja-ide,项目名称:ninja-ide,代码行数:28,代码来源:pep8_checker.py

示例10: _grep_file_locate

    def _grep_file_locate(self, file_path, file_name):
        #type - file_name - file_path
        global mapping_locations
        #TODO: Check if the last know state of the file is valid and load that
        exts = settings.SYNTAX.get('python')['extension']
        file_ext = file_manager.get_file_extension(file_path)
        if file_ext 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)]
        #obtain a symbols handler for this file extension
        symbols_handler = settings.get_symbols_handler(file_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
开发者ID:jsargiot,项目名称:ninja-ide,代码行数:27,代码来源:locator.py

示例11: _grep_file_symbols

    def _grep_file_symbols(self, file_path, file_name):
        #type - file_name - file_path
        global mapping_symbols
        exts = settings.SYNTAX.get('python')['extension']
        file_ext = file_manager.get_file_extension(file_path)
        if file_ext not in exts:
            mapping_symbols[file_path] = [
                ResultItem(symbol_type=FILTERS['non-python'], name=file_name,
                    path=file_path, lineno=-1)]
        else:
            mapping_symbols[file_path] = [
                ResultItem(symbol_type=FILTERS['files'], name=file_name,
                        path=file_path, lineno=-1)]
        data = self._get_file_symbols(file_path)
        #FIXME: stat not int
        mtime = int(os.stat(file_path).st_mtime)
        if data is not None and (mtime == int(data[1])):
            results = pickle.loads(str(data[2]))
            mapping_symbols[file_path] += results
            return
        #obtain a symbols handler for this file extension
        symbols_handler = handlers.get_symbols_handler(file_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:
            self._save_file_symbols(file_path, mtime, results)
            mapping_symbols[file_path] += results
开发者ID:jhg,项目名称:ninja-ide,代码行数:34,代码来源:locator.py

示例12: _menu_context_tree

    def _menu_context_tree(self, point, isRoot=False, root_path=None):
        index = self.indexAt(point)
        if not index.isValid() and not isRoot:
            return

        handler = None
        menu = QMenu(self)
        if isRoot or self.model().isDir(index):
            self._add_context_menu_for_folders(menu, isRoot, root_path)
        else:
            filename = self.model().fileName(index)
            lang = file_manager.get_file_extension(filename)
            self._add_context_menu_for_files(menu, lang)
        if isRoot:
            #get the extra context menu for this projectType
            handler = settings.get_project_type_handler(
                self.project.project_type)
            self._add_context_menu_for_root(menu)

        menu.addMenu(self._folding_menu)

        #menu for the Project Type(if present)
        if handler:
            for m in handler.get_context_menus():
                if isinstance(m, QMenu):
                    menu.addSeparator()
                    menu.addMenu(m)
        #show the menu!
        menu.exec_(QCursor.pos())
开发者ID:LeoYao,项目名称:ninja-ide,代码行数:29,代码来源:tree_projects_widget.py

示例13: run

    def run(self):
        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._neditor.text
                text = "[Error]: %s"
                # Compile into an AST and handle syntax errors
                try:
                    tree = compile(source, self._path, "exec", _ast.PyCF_ONLY_AST)
                except SyntaxError as reason:
                    if reason.text is None:
                        logger.error("Syntax error")
                    else:
                        text = text % reason.args[0]
                        range_ = helpers.get_range(
                            self._neditor, reason.lineno - 1, reason.offset)
                        self.checks[reason.lineno - 1].append((range_, text, ""))
                else:
                    # Okay, now check it
                    lint_checker = checker.Checker(tree, self._path)
                    lint_checker.messages.sort(key=lambda msg: msg.lineno)
                    source_lines = source.split('\n')
                    for message in lint_checker.messages:
                        lineno = message.lineno - 1
                        text = message.message % message.message_args
                        range_ = helpers.get_range(
                            self._neditor, lineno, message.col)
                        self.checks[lineno].append(
                            (range_, text, source_lines[lineno].strip()))
            except Exception as reason:
                logger.warning("Checker not finished: {}".format(reason))

        self.checkerCompleted.emit()
开发者ID:ninja-ide,项目名称:ninja-ide,代码行数:35,代码来源:errors_checker.py

示例14: restyle

 def restyle(self, syntaxLang=None):
     self.apply_editor_style()
     if self.lang == 'python':
         parts_scanner, code_scanner, formats = \
             syntax_highlighter.load_syntax(python_syntax.syntax)
         self.highlighter = syntax_highlighter.SyntaxHighlighter(
             self.document(),
             parts_scanner, code_scanner, formats,
             errors=self.errors, pep8=self.pep8, migration=self.migration)
         if self._mini:
             self._mini.highlighter = syntax_highlighter.SyntaxHighlighter(
                 self._mini.document(), parts_scanner,
                 code_scanner, formats)
         return
     if self.highlighter is None or isinstance(self.highlighter,
        highlighter.EmpyHighlighter):
         self.highlighter = highlighter.Highlighter(self.document(),
             None, resources.CUSTOM_SCHEME, self.errors, self.pep8,
             self.migration)
     if not syntaxLang:
         ext = file_manager.get_file_extension(self.ID)
         self.highlighter.apply_highlight(
             settings.EXTENSIONS.get(ext, 'python'),
             resources.CUSTOM_SCHEME)
         if self._mini:
             self._mini.highlighter.apply_highlight(
                 settings.EXTENSIONS.get(ext, 'python'),
                 resources.CUSTOM_SCHEME)
     else:
         self.highlighter.apply_highlight(
             syntaxLang, resources.CUSTOM_SCHEME)
         if self._mini:
             self._mini.highlighter.apply_highlight(
                 syntaxLang, resources.CUSTOM_SCHEME)
开发者ID:pdorrell,项目名称:ninja-ide,代码行数:34,代码来源:editor.py

示例15: update_explorer

    def update_explorer(self):
        """Update the symbols in the Symbol Explorer when a file is saved."""
        main_container = IDE.get_service('main_container')
        if not main_container:
            return
        editorWidget = main_container.get_current_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 = editorWidget.toPlainText()
                if editorWidget.encoding is not None:
                    source = source.encode(editorWidget.encoding)
                if ext == 'py':
                    args = (source, True)
                else:
                    args = (source,)
                symbols = symbols_handler.obtain_symbols(*args)
                self.update_symbols(symbols, editorWidget.ID)

            #TODO: Should we change the code below similar to the code above?
            exts = settings.SYNTAX.get('python')['extension']
            if ext in exts or editorWidget.newDocument:
                self.update_errors(editorWidget.errors, editorWidget.pep8)
开发者ID:jsargiot,项目名称:ninja-ide,代码行数:25,代码来源:explorer_container.py


注:本文中的ninja_ide.core.file_handling.file_manager.get_file_extension函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。