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

Python file_manager.get_basename函数代码示例

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

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



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

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


示例2: 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:olemis,项目名称:ninja-ide,代码行数:34,代码来源:tab_widget.py


示例3: _rename_file

 def _rename_file(self):
     path = self.model().filePath(self.currentIndex())
     name = file_manager.get_basename(path)
     new_name, ok = QInputDialog.getText(
         self, translations.TR_RENAME_FILE,
         translations.TR_ENTER_NEW_FILENAME,
         text=name)
     if ok and new_name.strip():
         filename = file_manager.create_path(
             file_manager.get_folder(path), new_name)
         if path == filename:
             return
         ninjaide = IDE.get_service("ide")
         print(ninjaide.filesystem.get_files())
         current_nfile = ninjaide.get_or_create_nfile(path)
         editable = ninjaide.get_editable(nfile=current_nfile)
         current_nfile.move(filename)
         if editable is not None:
             main_container = IDE.get_service("main_container")
             main_container.combo_area.bar.update_item_text(
                 editable, new_name)
             tree = ninjaide.filesystem.get_files()
             # FIXME: this is bad
             tree[filename] = tree.pop(path)
         print(ninjaide.filesystem.get_files())
开发者ID:ninja-ide,项目名称:ninja-ide,代码行数:25,代码来源:tree_projects_widget.py


示例4: __init__

    def __init__(self, parent):
        super(ProjectData, self).__init__()
        self._parent = parent
        grid = QGridLayout(self)
        grid.addWidget(QLabel(translations.TR_PROJECT_NAME), 0, 0)
        self.name = QLineEdit()
        if not len(self._parent.project.name):
            self.name.setText(file_manager.get_basename(
                self._parent.project.path))
        else:
            self.name.setText(self._parent.project.name)
        grid.addWidget(self.name, 0, 1)
        grid.addWidget(QLabel(translations.TR_PROJECT_LOCATION), 1, 0)
        self.txtPath = QLineEdit()
        self.txtPath.setReadOnly(True)
        self.txtPath.setText(self._parent.project.path)
        grid.addWidget(self.txtPath, 1, 1)
        grid.addWidget(QLabel(translations.TR_PROJECT_TYPE), 2, 0)
        self.txtType = QLineEdit()
        completer = QCompleter(sorted(settings.PROJECT_TYPES))
        completer.setCompletionMode(QCompleter.UnfilteredPopupCompletion)
        self.txtType.setCompleter(completer)
        self.txtType.setPlaceholderText("python")
        self.txtType.setText(self._parent.project.project_type)
        grid.addWidget(self.txtType, 2, 1)
        grid.addWidget(QLabel(translations.TR_PROJECT_DESCRIPTION), 3, 0)
        self.description = QPlainTextEdit()
        self.description.setPlainText(self._parent.project.description)
        grid.addWidget(self.description, 3, 1)
        grid.addWidget(QLabel(translations.TR_PROJECT_URL), 4, 0)
        self.url = QLineEdit()
        self.url.setText(self._parent.project.url)
        self.url.setPlaceholderText('https://www.{}.com'.format(getuser()))
        grid.addWidget(self.url, 4, 1)
        grid.addWidget(QLabel(translations.TR_PROJECT_LICENSE), 5, 0)
        self.cboLicense = QComboBox()
        self.cboLicense.addItems(LICENCES)
        self.cboLicense.setCurrentIndex(12)
        index = self.cboLicense.findText(self._parent.project.license)
        self.cboLicense.setCurrentIndex(index)
        grid.addWidget(self.cboLicense, 5, 1)

        self.txtExtensions = QLineEdit()
        self.txtExtensions.setText(', '.join(self._parent.project.extensions))
        grid.addWidget(QLabel(translations.TR_PROJECT_EXTENSIONS), 6, 0)
        grid.addWidget(self.txtExtensions, 6, 1)

        grid.addWidget(QLabel(translations.TR_PROJECT_INDENTATION), 7, 0)
        self.spinIndentation = QSpinBox()
        self.spinIndentation.setValue(self._parent.project.indentation)
        self.spinIndentation.setRange(2, 10)
        self.spinIndentation.setValue(4)
        self.spinIndentation.setSingleStep(2)
        grid.addWidget(self.spinIndentation, 7, 1)
        self.checkUseTabs = QComboBox()
        self.checkUseTabs.addItems([
            translations.TR_PREFERENCES_EDITOR_CONFIG_SPACES.capitalize(),
            translations.TR_PREFERENCES_EDITOR_CONFIG_TABS.capitalize()])
        self.checkUseTabs.setCurrentIndex(int(self._parent.project.use_tabs))
        grid.addWidget(self.checkUseTabs, 7, 2)
开发者ID:AnyBucket,项目名称:ninja-ide,代码行数:60,代码来源:project_properties_widget.py


示例5: save_recent_projects

    def save_recent_projects(self, folder):
        settings = IDE.data_settings()
        recent_project_list = settings.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 = translations.TR_NO_DESCRIPTION

        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(
                    recent_project_list)]
        settings.setValue('recentProjects', recent_project_list)
开发者ID:LeoYao,项目名称:ninja-ide,代码行数:32,代码来源:tree_projects_widget.py


示例6: _copy_file

 def _copy_file(self):
     #get the selected QTreeWidgetItem
     path = self.model().filePath(self.currentIndex())
     name = file_manager.get_basename(path)
     global projectsColumn
     pathProjects = [p.path for p in projectsColumn.projects]
     addToProject = add_to_project.AddToProject(pathProjects, self)
     addToProject.setWindowTitle(self.tr("Copy File to"))
     addToProject.exec_()
     if not addToProject.pathSelected:
         return
     name = QInputDialog.getText(self, self.tr("Copy File"),
         self.tr("File Name:"), text=name)[0]
     if not name:
         QMessageBox.information(self, self.tr("Invalid Name"),
             self.tr("The file name is empty, please enter a name"))
         return
     path = file_manager.create_path(addToProject.pathSelected, name)
     try:
         content = file_manager.read_file_content(path)
         path = file_manager.store_file_content(path, content, newFile=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))
开发者ID:WeAreLaVelle,项目名称:ninja-ide,代码行数:25,代码来源:tree_projects_widget.py


示例7: _move_file

 def _move_file(self):
     path = self.model().filePath(self.currentIndex())
     global projectsColumn
     pathProjects = [p.path for p in projectsColumn.projects]
     addToProject = add_to_project.AddToProject(pathProjects, self)
     addToProject.setWindowTitle(self.tr("Copy File to"))
     addToProject.exec_()
     if not addToProject.pathSelected:
         return
     name = file_manager.get_basename(path)
     path = file_manager.create_path(addToProject.pathSelected, name)
     try:
         content = file_manager.read_file_content(path)
         path = file_manager.store_file_content(path, content, newFile=True)
         file_manager.delete_file(path)
         # Update path of opened file
         main = IDE.get_service('main_container')
         if main and main.is_open(path):
             widget = main.get_widget_for_path(path)
             if widget:
                 widget.ID = 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:WeAreLaVelle,项目名称:ninja-ide,代码行数:25,代码来源:tree_projects_widget.py


示例8: __init__

    def __init__(self, path):
        super(NProject, self).__init__()
        project = json_manager.read_ninja_project(path)

        self.path = path
        self._name = project.get('name', '')
        if self._name == '':
            self._name = file_manager.get_basename(path)
        self.project_type = project.get('project-type', '')
        self.description = project.get('description', '')
        if self.description == '':
            self.description = translations.TR_NO_DESCRIPTION
        self.url = project.get('url', '')
        self.license = project.get('license', '')
        self.main_file = project.get('mainFile', '')
        self.pre_exec_script = project.get('preExecScript', '')
        self.post_exec_script = project.get('postExecScript', '')
        self.indentation = project.get('indentation', settings.INDENT)
        self.use_tabs = project.get('use-tabs', settings.USE_TABS)
        self.extensions = project.get('supported-extensions',
            settings.SUPPORTED_EXTENSIONS)
        self.python_exec = project.get('pythonExec', settings.PYTHON_EXEC)
        self.python_path = project.get('PYTHONPATH', '')
        self.additional_builtins = project.get('additional_builtins', [])
        self.program_params = project.get('programParams', '')
        self.venv = project.get('venv', '')
        self.related_projects = project.get('relatedProjects', [])
        self.added_to_console = False
        self.is_current = False
        #Model is a QFileSystemModel to be set on runtime
        self.__model = None
开发者ID:AnyBucket,项目名称:ninja-ide,代码行数:31,代码来源:nproject.py


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


示例10: _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)
         # Update path of opened file
         main = IDE.get_service('main_container')
         if main and 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, self.tr("File Already Exists"),
                 (self.tr("Invalid Path: the file '%s' already exists.") %
                     ex.filename))
开发者ID:skela,项目名称:ninja-ide,代码行数:31,代码来源:tree_projects_widget.py


示例11: _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)
                main_container = IDE.get_service('main_container')
                if main_container and main_container.is_open(pathForFile):
                    main_container.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:skela,项目名称:ninja-ide,代码行数:31,代码来源:tree_projects_widget.py


示例12: _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))
                main_container = IDE.get_service('main_container')
                if main_container:
                    main_container.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:skela,项目名称:ninja-ide,代码行数:26,代码来源:tree_projects_widget.py


示例13: _add_file_to_project

 def _add_file_to_project(self, path):
     """Add the file for 'path' in the project the user choose here."""
     if self._active_project:
         pathProject = [self._active_project.project]
         addToProject = add_to_project.AddToProject(pathProject, self)
         addToProject.exec_()
         if not addToProject.pathSelected:
             return
         main_container = IDE.get_service('main_container')
         if not main_container:
             return
         editorWidget = main_container.get_current_editor()
         if not editorWidget.file_path:
             name = QInputDialog.getText(None,
                 self.tr("Add File To Project"), self.tr("File Name:"))[0]
             if not name:
                 QMessageBox.information(self, self.tr("Invalid Name"),
                     self.tr("The file name is empty, please enter a name"))
                 return
         else:
             name = file_manager.get_basename(editorWidget.file_path)
         new_path = file_manager.create_path(addToProject.pathSelected, name)
         ide_srv = IDE.get_service("ide")
         old_file, ide_srv.get_or_create_nfile(path)
         new_file = old_file.save(editorWidget.get_text(), path)
         #FIXME: Make this file replace the original in the open tab
     else:
         pass
开发者ID:abracadaber,项目名称:ninja-ide,代码行数:28,代码来源:tree_projects_widget.py


示例14: _add_file_to_project

 def _add_file_to_project(self, path):
     """Add the file for 'path' in the project the user choose here."""
     if self._active_project:
         pathProject = [self._active_project.project]
         addToProject = add_to_project.AddToProject(pathProject, self)
         addToProject.exec_()
         if not addToProject.pathSelected:
             return
         main_container = IDE.get_service('main_container')
         if not main_container:
             return
         editorWidget = main_container.get_current_editor()
         if not editorWidget.file_path:
             name = QInputDialog.getText(None,
                                         translations.TR_ADD_FILE_TO_PROJECT,
                                         translations.TR_FILENAME + ": ")[0]
             if not name:
                 QMessageBox.information(
                     self,
                     translations.TR_INVALID_FILENAME,
                     translations.TR_INVALID_FILENAME_ENTER_A_FILENAME)
                 return
         else:
             name = file_manager.get_basename(editorWidget.file_path)
         new_path = file_manager.create_path(addToProject.pathSelected, name)
         ide_srv = IDE.get_service("ide")
         old_file = ide_srv.get_or_create_nfile(path)
         new_file = old_file.save(editorWidget.get_text(), new_path)
         #FIXME: Make this file replace the original in the open tab
     else:
         pass
开发者ID:LeoYao,项目名称:ninja-ide,代码行数:31,代码来源:tree_projects_widget.py


示例15: change_open_tab_id

 def change_open_tab_id(self, idname, newId):
     """Search for the Tab with idname, and set the newId to that Tab."""
     index = self.tabs.is_open(idname)
     if index != -1:
         widget = self.tabs.widget(index)
         tabName = file_manager.get_basename(newId)
         self.tabs.change_open_tab_name(index, tabName)
         widget.ID = newId
开发者ID:olemis,项目名称:ninja-ide,代码行数:8,代码来源:main_container.py


示例16: 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:jsargiot,项目名称:ninja-ide,代码行数:8,代码来源:locator.py


示例17: locate_file_code

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


示例18: _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:jsargiot,项目名称:ninja-ide,代码行数:8,代码来源:locator.py


示例19: _delete_folder

 def _delete_folder(self):
     # FIXME: We need nfilesystem support for this
     path = self.model().filePath(self.currentIndex())
     name = file_manager.get_basename(path)
     val = QMessageBox.question(
         self, translations.TR_REMOVE_FOLDER,
         translations.TR_DELETE_FOLLOWING_FOLDER.format(name),
         QMessageBox.Yes, QMessageBox.No)
     if val == QMessageBox.Yes:
         file_manager.delete_folder(path)
开发者ID:ninja-ide,项目名称:ninja-ide,代码行数:10,代码来源:tree_projects_widget.py


示例20: open_image

 def open_image(self, fileName):
     try:
         if not self.is_open(fileName):
             viewer = image_viewer.ImageViewer(fileName)
             self.add_tab(viewer, file_manager.get_basename(fileName))
             viewer.ID = fileName
         else:
             self.move_to_open(fileName)
     except Exception as reason:
         logger.error("open_image: %s", reason)
         QMessageBox.information(self, self.tr("Incorrect File"), self.tr("The image couldn't be open"))
开发者ID:perrito666,项目名称:ninja-ide,代码行数:11,代码来源:main_container.py



注:本文中的ninja_ide.core.file_handling.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