• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python file_manager.get_basename函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: _add_file_to_project

 def _add_file_to_project(self, path):
     """Add the file for 'path' in the project the user choose here."""
     pathProject = [self.ide.explorer.get_actual_project()]
     addToProject = ui_tools.AddToProject(pathProject, self.ide)
     addToProject.exec_()
     if not addToProject.pathSelected:
         return
     editorWidget = self.ide.mainContainer.get_actual_editor()
     if not editorWidget.ID:
         name = unicode(QInputDialog.getText(None,
             self.tr("Add File To Project"), self.tr("File Name:"))[0])
         if not name:
             QMessageBox.information(self, self.tr("Invalid Name"),
                 self.tr("The file name is empty, please enter a name"))
             return
     else:
         name = file_manager.get_basename(editorWidget.ID)
     path = file_manager.create_path(
         unicode(addToProject.pathSelected), name)
     try:
         path = file_manager.store_file_content(
             path, editorWidget.get_text(), newFile=True)
         editorWidget.ID = path
         self.ide.explorer.add_existing_file(path)
         self.ide.change_window_title(path)
         name = file_manager.get_basename(path)
         self.ide.mainContainer.actualTab.setTabText(
             self.ide.mainContainer.actualTab.currentIndex(), name)
         editorWidget._file_saved()
     except file_manager.NinjaFileExistsException, ex:
         QMessageBox.information(self, self.tr("File Already Exists"),
             self.tr("Invalid Path: the file '%s' already exists." % \
                 ex.filename))
开发者ID:alekibango,项目名称:ninja-ide,代码行数:33,代码来源:actions.py


示例2: expand_tab_name

 def expand_tab_name(self, title):
     title = unicode(title)
     if title == 'New Document':
         return
     elif title not in self.titles:
         self.titles.append(title)
         return
     indexes = [i for i in xrange(self.count())
         if type(self.widget(i)) is editor.Editor and \
         self.tabText(i) == title and \
         self.widget(i).ID]
     self.dontLoopInExpandTitle = True
     for i in indexes:
         newName = file_manager.create_path(
             file_manager.get_basename(
                 file_manager.get_folder(self.widget(i).ID)),
             title)
         while newName in self.titles:
             path = self.widget(i).ID
             tempDir = path[:path.rfind(newName)]
             newName = file_manager.create_path(
                 file_manager.get_basename(
                     file_manager.get_folder(tempDir)),
                 '..',
                 title)
         self.titles.append(newName)
         self.setTabText(i, newName)
     self.dontLoopInExpandTitle = False
开发者ID:aguzubiaga,项目名称:ninja-ide,代码行数:28,代码来源:tab_widget.py


示例3: expand_tab_name

    def expand_tab_name(self, title):
        """Expand the tab title to differentiate files with the same name.

        The way it is currently implemented, it will only change the first
        conflicting title passed in, because it only searches until the new
        title isn't in the tab titles.
        """
        if title == 'New Document':
            return
        elif title not in self.titles:
            self.titles.append(title)
            return
        indexes = [i for i in range(self.count())
            if type(self.widget(i)) is editor.Editor and
            self.tabText(i) == title and
            self.widget(i).ID]  # self.widget.ID returns the basename
        self.dontLoopInExpandTitle = True
        for i in indexes:
            newName = file_manager.create_path(
                file_manager.get_basename(
                    file_manager.get_folder(self.widget(i).ID)), title)
            while newName in self.titles:
                # Keep prepending the folder name onto the title until it
                # does not conflict.
                path = self.widget(i).ID
                tempDir = path[:path.rfind(newName)]
                newName = file_manager.create_path(
                    file_manager.get_basename(
                        file_manager.get_folder(tempDir)),
                    '..',
                    title)
            self.titles.append(newName)
            self.setTabText(i, newName)
        self.dontLoopInExpandTitle = False
开发者ID:DevNIX,项目名称:ninja-ide,代码行数:34,代码来源:tab_widget.py


示例4: go_to_definition

    def go_to_definition(self):
        self.dirty = True
        self.results = []
        locations = self.get_locations()
        if self._isVariable:
            preResults = [
                [file_manager.get_basename(x.path), x.path, x.lineno, '']
                for x in locations
                if (x.type == FILTERS['attribs']) and (x.name == self._search)]
        else:
            preResults = [
                [file_manager.get_basename(x.path), x.path, x.lineno, '']
                for x in locations
                if ((x.type == FILTERS['functions']) or
                   (x.type == FILTERS['classes'])) and
                   (x.name.startswith(self._search))]
        for data in preResults:
            file_object = QFile(data[1])
            if not file_object.open(QFile.ReadOnly):
                return

            stream = QTextStream(file_object)
            line_index = 0
            line = stream.readLine()
            while not self._cancel and not stream.atEnd():
                if line_index == data[2]:
                    data[3] = line
                    self.results.append(data)
                    break
                #take the next line!
                line = stream.readLine()
                line_index += 1
        self._search = None
        self._isVariable = None
开发者ID:DevNIX,项目名称:ninja-ide,代码行数:34,代码来源:locator.py


示例5: _add_new_file

    def _add_new_file(self):
        item = self.currentItem()
        if item.parent() is None:
            pathForFile = item.path
        else:
            pathForFile = os.path.join(item.path, unicode(item.text(0)))
        result = QInputDialog.getText(self, self.tr("New File"),
            self.tr("Enter the File Name:"))
        fileName = unicode(result[0])

        if result[1] and fileName.strip() != '':
            try:
                fileName = os.path.join(pathForFile, fileName)
                fileName = file_manager.store_file_content(
                    fileName, '', newFile=True)
                name = file_manager.get_basename(fileName)
                subitem = ProjectItem(item, name, pathForFile)
                subitem.setToolTip(0, name)
                subitem.setIcon(0, self._get_file_icon(name))
                item.sortChildren(0, Qt.AscendingOrder)
                mainContainer = main_container.MainContainer()
                mainContainer.open_file(fileName)
                editorWidget = mainContainer.get_actual_editor()
                editorWidget.textCursor().insertText("# -*- coding: utf-8 *-*")
                main_container.MainContainer().save_file()
            except file_manager.NinjaFileExistsException, ex:
                QMessageBox.information(self, self.tr("File Already Exists"),
                    self.tr("Invalid Path: the file '%s' already exists." % \
                        ex.filename))
开发者ID:sanyaade,项目名称:ninja-ide,代码行数:29,代码来源:tree_projects_widget.py


示例6: add_editor

    def add_editor(self, fileName="", project=None, tabIndex=None, content=None, syntax=None):
        editorWidget = editor.create_editor(fileName=fileName, project=project, syntax=syntax)

        if not fileName:
            tabName = "New Document"
        else:
            tabName = file_manager.get_basename(fileName)

        # add the tab
        inserted_index = self.add_tab(editorWidget, tabName, tabIndex=tabIndex)
        self.actualTab.setTabToolTip(inserted_index, fileName)
        self.connect(editorWidget, SIGNAL("modificationChanged(bool)"), self._editor_tab_was_modified)
        self.connect(editorWidget, SIGNAL("fileSaved(QPlainTextEdit)"), self._editor_tab_was_saved)
        self.connect(editorWidget, SIGNAL("openDropFile(QString)"), self.open_file)
        self.connect(
            editorWidget, SIGNAL("addBackItemNavigation()"), lambda: self.emit(SIGNAL("addBackItemNavigation()"))
        )
        self.connect(editorWidget, SIGNAL("locateFunction(QString, QString, bool)"), self._editor_locate_function)
        self.connect(editorWidget, SIGNAL("warningsFound(QPlainTextEdit)"), self._show_warning_tab_indicator)
        self.connect(editorWidget, SIGNAL("errorsFound(QPlainTextEdit)"), self._show_error_tab_indicator)
        self.connect(editorWidget, SIGNAL("cleanDocument(QPlainTextEdit)"), self._hide_icon_tab_indicator)
        self.connect(editorWidget, SIGNAL("findOcurrences(QString)"), self._find_occurrences)
        # Cursor position changed
        self.connect(editorWidget, SIGNAL("cursorPositionChange(int, int)"), self._cursor_position_changed)
        # keyPressEventSignal for plugins
        self.connect(editorWidget, SIGNAL("keyPressEvent(QEvent)"), self._editor_keyPressEvent)

        # insert the content if present
        if content:
            editorWidget.setPlainText(content)
        # emit a signal about the file open
        self.emit(SIGNAL("fileOpened(QString)"), fileName)

        return editorWidget
开发者ID:Fieldbyte,项目名称:ninja-ide,代码行数:34,代码来源:main_container.py


示例7: save_recent_projects

    def save_recent_projects(self, folder):
        recent_project_list = QSettings(
            resources.SETTINGS_PATH,
            QSettings.IniFormat).value('recentProjects', {})
        #if already exist on the list update the date time
        projectProperties = json_manager.read_ninja_project(folder)
        name = projectProperties.get('name', '')
        description = projectProperties.get('description', '')

        if name == '':
            name = file_manager.get_basename(folder)

        if description == '':
            description = _translate("_s_ExplorerContainer", 'no description available')

        if folder in recent_project_list:
            properties = recent_project_list[folder]
            properties["lastopen"] = QDateTime.currentDateTime()
            properties["name"] = name
            properties["description"] = description
            recent_project_list[folder] = properties
        else:
            recent_project_list[folder] = {
                "name": name,
                "description": description,
                "isFavorite": False, "lastopen": QDateTime.currentDateTime()}
            #if the length of the project list it's high that 10 then delete
            #the most old
            #TODO: add the length of available projects to setting
            if len(recent_project_list) > 10:
                del recent_project_list[self.find_most_old_open()]
        QSettings(resources.SETTINGS_PATH, QSettings.IniFormat).setValue(
            'recentProjects', recent_project_list)
开发者ID:Salmista-94,项目名称:Ninja_PyQt5,代码行数:33,代码来源:explorer_container.py


示例8: 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


示例9: _move_file

 def _move_file(self):
     item = self.currentItem()
     if item.parent() is None:
         pathForFile = item.path
     else:
         pathForFile = os.path.join(item.path, item.text(0))
     pathProjects = [p.path for p in self.get_open_projects()]
     addToProject = ui_tools.AddToProject(pathProjects, self)
     addToProject.setWindowTitle(_translate("TreeProjectsWidget", "Copy File to"))
     addToProject.exec_()
     if not addToProject.pathSelected:
         return
     name = file_manager.get_basename(pathForFile)
     path = file_manager.create_path(addToProject.pathSelected, name)
     try:
         content = file_manager.read_file_content(pathForFile)
         path = file_manager.store_file_content(path, content, newFile=True)
         file_manager.delete_file(pathForFile)
         index = item.parent().indexOfChild(item)
         item.parent().takeChild(index)
         self.add_existing_file(path)
         # Update path of opened file
         main = main_container.MainContainer()
         if main.is_open(pathForFile):
             widget = main.get_widget_for_path(pathForFile)
             if widget:
                 widget.ID = path
     except file_manager.NinjaFileExistsException as ex:
             QMessageBox.information(self, _translate("TreeProjectsWidget", "File Already Exists"),
                 (_translate("TreeProjectsWidget", "Invalid Path: the file '%s' already exists.") %
                  ex.filename))
开发者ID:Salmista-94,项目名称:Ninja_PyQt5,代码行数:31,代码来源:tree_projects_widget.py


示例10: save_recent_projects

    def save_recent_projects(self, folder):
        recent_project_list = QSettings().value('recentProjects', {}).toMap()
        #if already exist on the list update the date time
        projectProperties = json_manager.read_ninja_project(folder)
        name = projectProperties.get('name', '')
        description = projectProperties.get('description', '')

        if name == '':
            name = file_manager.get_basename(folder)

        if description == '':
            description = self.tr('no description available')

        if QString(folder) in recent_project_list:
            properties = recent_project_list[QString(folder)].toMap()
            properties[QString("lastopen")] = QDateTime.currentDateTime()
            properties[QString("name")] = name
            properties[QString("description")] = description
            recent_project_list[QString(folder)] = properties
        else:
            recent_project_list[QString(folder)] = {
                "name": name,
                "description": description,
                "isFavorite": False, "lastopen": QDateTime.currentDateTime()}
            #if the length of the project list it's high that 10 then delete
            #the most old
            #TODO: add the length of available projects to setting
            if len(recent_project_list) > 10:
                del recent_project_list[self.find_most_old_open()]
        QSettings().setValue('recentProjects', recent_project_list)
开发者ID:beefsack,项目名称:ninja-ide,代码行数:30,代码来源:explorer_container.py


示例11: _move_file

 def _move_file(self):
     item = self.currentItem()
     if item.parent() is None:
         pathForFile = item.path
     else:
         pathForFile = os.path.join(item.path, item.text(0))
     pathProjects = [p.path for p in self.get_open_projects()]
     addToProject = ui_tools.AddToProject(pathProjects, self)
     addToProject.setWindowTitle(self.tr("Copy File to"))
     addToProject.exec_()
     if not addToProject.pathSelected:
         return
     name = file_manager.get_basename(pathForFile)
     path = file_manager.create_path(addToProject.pathSelected, name)
     try:
         content = file_manager.read_file_content(pathForFile)
         path = file_manager.store_file_content(path, content, newFile=True)
         file_manager.delete_file(pathForFile)
         index = item.parent().indexOfChild(item)
         item.parent().takeChild(index)
         self.add_existing_file(path)
     except file_manager.NinjaFileExistsException as ex:
             QMessageBox.information(self, self.tr("File Already Exists"),
                 self.tr("Invalid Path: the file '%s' already exists." %
                     ex.filename))
开发者ID:Bengt,项目名称:ninja-ide,代码行数:25,代码来源:tree_projects_widget.py


示例12: _rename_file

    def _rename_file(self):
        item = self.currentItem()
        if item.parent() is None:
            pathForFile = item.path
        else:
            pathForFile = os.path.join(item.path, item.text(0))
        result = QInputDialog.getText(self, self.tr("Rename File"),
            self.tr("Enter New File Name:"), text=item.text(0))
        fileName = result[0]

        if result[1] and fileName.strip() != '':
            fileName = os.path.join(
                file_manager.get_folder(pathForFile), fileName)
            if pathForFile == fileName:
                return
            try:
                fileName = file_manager.rename_file(pathForFile, fileName)
                name = file_manager.get_basename(fileName)
                mainContainer = main_container.MainContainer()
                if mainContainer.is_open(pathForFile):
                    mainContainer.change_open_tab_name(pathForFile, fileName)
                subitem = ProjectItem(item.parent(), name,
                    file_manager.get_folder(fileName))
                subitem.setToolTip(0, name)
                subitem.setIcon(0, self._get_file_icon(name))
                index = item.parent().indexOfChild(item)
                subitem.parent().takeChild(index)
            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))
开发者ID:Bengt,项目名称:ninja-ide,代码行数:31,代码来源:tree_projects_widget.py


示例13: load_project

    def load_project(self, folderStructure, folder):
        if not folder:
            return

        name = file_manager.get_basename(folder)
        item = ProjectTree(self, name, folder)
        item.isFolder = True
        item.setToolTip(0, name)
        item.setIcon(0, QIcon(resources.IMAGES['tree-app']))
        self._projects[folder] = item
        if folderStructure[folder][1] is not None:
            folderStructure[folder][1].sort()
        if item.extensions != settings.SUPPORTED_EXTENSIONS:
            folderStructure = file_manager.open_project_with_extensions(
                item.path, item.extensions)
        self._load_folder(folderStructure, folder, item)
        item.setExpanded(True)
        if len(self._projects) == 1:
            self.set_default_project(item)
        if self.currentItem() is None:
            item.setSelected(True)
            self.setCurrentItem(item)
        if folder not in self._fileWatcher.directories():
            DEBUG("Ading '%s' to watcher" % folder)
            self._fileWatcher.addPath(folder)
开发者ID:dawee,项目名称:ninja-ide,代码行数:25,代码来源:tree_projects_widget.py


示例14: get_item_for_path

 def get_item_for_path(self, path):
     items = self.findItems(file_manager.get_basename(path),
         Qt.MatchRecursive, 0)
     folder = file_manager.get_folder(path)
     for item in items:
         if file_manager.belongs_to_folder(folder, item.path):
             return item
开发者ID:Bengt,项目名称:ninja-ide,代码行数:7,代码来源:tree_projects_widget.py


示例15: save_recent_projects

    def save_recent_projects(self, folder):
        recent_project_list = QSettings().value("recentProjects", {})
        # if already exist on the list update the date time
        projectProperties = json_manager.read_ninja_project(folder)
        name = projectProperties.get("name", "")
        description = projectProperties.get("description", "")

        if name == "":
            name = file_manager.get_basename(folder)

        if description == "":
            description = self.tr("no description available")

        if folder in recent_project_list:
            properties = recent_project_list[folder]
            properties["lastopen"] = QDateTime.currentDateTime()
            properties["name"] = name
            properties["description"] = description
            recent_project_list[folder] = properties
        else:
            recent_project_list[folder] = {
                "name": name,
                "description": description,
                "isFavorite": False,
                "lastopen": QDateTime.currentDateTime(),
            }
            # if the length of the project list it's high that 10 then delete
            # the most old
            # TODO: add the length of available projects to setting
            if len(recent_project_list) > 10:
                del recent_project_list[self.find_most_old_open()]
        QSettings().setValue("recentProjects", recent_project_list)
开发者ID:jamzo,项目名称:ninja-ide,代码行数:32,代码来源:explorer_container.py


示例16: _add_new_file

    def _add_new_file(self):
        item = self.currentItem()
        if item.parent() is None:
            pathForFile = item.path
        else:
            pathForFile = os.path.join(item.path, item.text(0))
        result = QInputDialog.getText(self, self.tr("New File"),
            self.tr("Enter the File Name:"))
        fileName = result[0]

        if result[1] and fileName.strip() != '':
            try:
                fileName = os.path.join(pathForFile, fileName)
                fileName = file_manager.store_file_content(
                    fileName, '', newFile=True)
                name = file_manager.get_basename(fileName)
                subitem = ProjectItem(item, name, pathForFile)
                subitem.setToolTip(0, name)
                subitem.setIcon(0, self._get_file_icon(name))
                mainContainer = main_container.MainContainer()
                mainContainer.open_file(fileName)
            except file_manager.NinjaFileExistsException as ex:
                QMessageBox.information(self, self.tr("File Already Exists"),
                    self.tr("Invalid Path: the file '%s' already exists." %
                        ex.filename))
开发者ID:Bengt,项目名称:ninja-ide,代码行数:25,代码来源:tree_projects_widget.py


示例17: _advanced_filter_by_file

 def _advanced_filter_by_file(self, filterOptions):
     if filterOptions[1] == '@':
         index = 2
     else:
         index = 3
     self.tempLocations = [x for x in self.tempLocations \
         if file_manager.get_basename(x[2]).lower().find(
             filterOptions[index]) > -1]
开发者ID:Fieldbyte,项目名称:ninja-ide,代码行数:8,代码来源:locator.py


示例18: locate_file_code

 def locate_file_code(self):
     file_name = file_manager.get_basename(self._file_path)
     try:
         self._grep_file_locate(self._file_path, file_name)
         self.dirty = True
         self.execute = self.locate_code
     except Exception as reason:
         logger.error('locate_file_code, error: %r' % reason)
开发者ID:DevNIX,项目名称:ninja-ide,代码行数:8,代码来源:locator.py


示例19: _advanced_filter_by_file

 def _advanced_filter_by_file(self, filterOptions):
     if filterOptions[1] == FILTERS['files']:
         index = 2
     else:
         index = 3
     self.tempLocations = [x for x in self.tempLocations
         if file_manager.get_basename(x.path).lower().find(
             filterOptions[index]) > -1]
开发者ID:DevNIX,项目名称:ninja-ide,代码行数:8,代码来源:locator.py


示例20: only_expand

 def only_expand(self):
     for tab in self.tabs:
         tabName = file_manager.get_basename(tab.ID)
         self.actions.ide.mainContainer.add_tab(tab, tabName)
     index = self.actions.ide.mainContainer._tabMain.indexOf(self)
     self.actions.ide.mainContainer._tabMain.removeTab(index)
     self.tabs = []
     self.listWidget.clear()
开发者ID:AlexaProjects,项目名称:Alexa2,代码行数:8,代码来源:tab_group.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python file_manager.get_file_extension函数代码示例发布时间:2022-05-27
下一篇:
Python file_manager.file_exists函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap