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


Python file_manager.get_file_extension函数代码示例

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


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

示例1: save_file_as

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

示例2: _grep_file_locate

    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
开发者ID:DevNIX,项目名称:ninja-ide,代码行数:26,代码来源:locator.py

示例3: open_file

    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]))
开发者ID:beefsack,项目名称:ninja-ide,代码行数:29,代码来源:main_container.py

示例4: open_file

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

示例5: 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_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)
开发者ID:sbellem,项目名称:ninja-ide,代码行数:33,代码来源:main_container.py

示例6: _grep_file_locate

 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
开发者ID:uKev,项目名称:ninja-ide,代码行数:55,代码来源:locator.py

示例7: save_file_as

    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
开发者ID:sbellem,项目名称:ninja-ide,代码行数:51,代码来源:main_container.py

示例8: 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_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)
开发者ID:Salmista-94,项目名称:Ninja_PyQt5,代码行数:51,代码来源:main_container.py

示例9: 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:akatrevorjay,项目名称:ninja-ide,代码行数:25,代码来源:editor.py

示例10: uncomment

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

示例11: get_symbols_for_class

 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 []
开发者ID:Fieldbyte,项目名称:ninja-ide,代码行数:28,代码来源:locator.py

示例12: run

    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:
开发者ID:netantho,项目名称:ninja-ide,代码行数:32,代码来源:errors_checker.py

示例13: run

 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()
开发者ID:Salmista-94,项目名称:Ninja_PyQt5,代码行数:33,代码来源:pep8_checker.py

示例14: run

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

示例15: run

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


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