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


Python file_manager.read_file_content函数代码示例

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


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

示例1: _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

示例2: _replace_results

    def _replace_results(self):
        result = QMessageBox.question(self, self.tr("Replace Files Contents"),
            self.tr("Are you sure you want to replace the content in "
                    "this files?\n(The change is not reversible)"),
            buttons=QMessageBox.Yes | QMessageBox.No)
        if result == QMessageBox.Yes:
            for index in range(self._result_widget.topLevelItemCount()):
                parent = self._result_widget.topLevelItem(index)
                root_dir_name = parent.dir_name_root
                file_name = parent.text(0)
                file_path = file_manager.create_path(root_dir_name, file_name)
                try:
                    content = file_manager.read_file_content(file_path)
                    pattern = self._find_widget.pattern_line_edit.text()
                    flags = 0
                    if not self._find_widget.case_checkbox.isChecked():
                        flags |= re.IGNORECASE
                    if self._find_widget.type_checkbox.isChecked():
                        pattern = r'\b%s\b' % pattern

                    new_content = re.sub(pattern,
                        self._find_widget.replace_line.text(),
                        content, flags=flags)
                    file_manager.store_file_content(file_path,
                        new_content, False)
                except:
                    print('File: %s content, could not be replaced' %
                          file_path)
开发者ID:AlexaProjects,项目名称:Alexa2,代码行数:28,代码来源:find_in_files.py

示例3: __open_file

    def __open_file(self, fileName='', cursorPosition=0,\
                    tabIndex=None, positionIsLineNumber=False, notStart=True):
        try:
            if not self.is_open(fileName):
                self.actualTab.notOpening = False
                content = file_manager.read_file_content(fileName)
                editorWidget = self.add_editor(fileName, tabIndex=tabIndex,
                    content=content)
                editorWidget.ID = fileName
                encoding = file_manager._search_coding_line(content)
                editorWidget.encoding = encoding
                if not positionIsLineNumber:
                    editorWidget.set_cursor_position(cursorPosition)
                else:
                    editorWidget.go_to_line(cursorPosition)

                if not editorWidget.has_write_permission():
                    fileName += unicode(self.tr(" (Read-Only)"))
                    index = self.actualTab.currentIndex()
                    self.actualTab.setTabText(index, fileName)
            else:
                self.move_to_open(fileName)
                editorWidget = self.get_actual_editor()
                if editorWidget:
                    if positionIsLineNumber:
                        editorWidget.go_to_line(cursorPosition)
                    else:
                        editorWidget.set_cursor_position(cursorPosition)
            self.emit(SIGNAL("currentTabChanged(QString)"), fileName)
        except file_manager.NinjaIOException, reason:
            if not notStart:
                QMessageBox.information(self,
                    self.tr("The file couldn't be open"),
                    unicode(reason))
开发者ID:ntcong,项目名称:ninja-ide,代码行数:34,代码来源:main_container.py

示例4: _copy_file

 def _copy_file(self):
     #get the selected QTreeWidgetItem
     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 = QInputDialog.getText(self, self.tr("Copy File"),
         self.tr("File Name:"), text=item.text(0))[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(pathForFile)
         path = file_manager.store_file_content(path, content, newFile=True)
         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,代码行数:28,代码来源:tree_projects_widget.py

示例5: _copy_file

 def _copy_file(self):
     item = self.currentItem()
     if item.parent() is None:
         pathForFile = item.path
     else:
         pathForFile = os.path.join(item.path, unicode(item.text(0)))
     pathProject = self.get_selected_project_path()
     addToProject = ui_tools.AddToProject(pathProject, self)
     addToProject.setWindowTitle(self.tr("Copy File to"))
     addToProject.exec_()
     if not addToProject.pathSelected:
         return
     name = unicode(QInputDialog.getText(None,
         self.tr("Copy File"),
         self.tr("File Name:"))[0])
     if not name:
         QMessageBox.information(self, self.tr("Indalid Name"),
             self.tr("The file name is empty, please enter a name"))
         return
     path = file_manager.create_path(
         unicode(addToProject.pathSelected), name)
     try:
         content = file_manager.read_file_content(pathForFile)
         path = file_manager.store_file_content(path, content, newFile=True)
         self.add_existing_file(path)
     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: _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

示例7: __open_file

    def __open_file(self, fileName='', cursorPosition=-1,
                    tabIndex=None, positionIsLineNumber=False, notStart=True):
        try:
            if not self.is_open(fileName):
                print("can not opened!")
                self.actualTab.notOpening = False
                content = file_manager.read_file_content(fileName)
                editorWidget = self.add_editor(fileName, tabIndex=tabIndex,
                    use_open_highlight=True)

                #Add content
                #we HAVE to add the editor's content before set the ID
                #because of the minimap logic
                editorWidget.setPlainText(content)
                editorWidget.ID = fileName
                editorWidget.async_highlight()
                encoding = file_manager.get_file_encoding(content)
                editorWidget.encoding = encoding
                if cursorPosition == -1:
                    cursorPosition = 0
                if not positionIsLineNumber:
                    editorWidget.set_cursor_position(cursorPosition)
                else:
                    editorWidget.go_to_line(cursorPosition)
                self.add_standalone_watcher(editorWidget.ID, notStart)

                #New file then try to add a coding line
                if not content:
                    helpers.insert_coding_line(editorWidget)
                    self.save_file(editorWidget=editorWidget)

                if not editorWidget.has_write_permission():
                    fileName += _translate("_s_MainContainer", " (Read-Only)")
                    index = self.actualTab.currentIndex()
                    self.actualTab.setTabText(index, fileName)

            else:
                print("has opened")
                self.move_to_open(fileName)
                editorWidget = self.get_actual_editor()
                if editorWidget and notStart and cursorPosition != -1:
                    if positionIsLineNumber:
                        editorWidget.go_to_line(cursorPosition)
                    else:
                        editorWidget.set_cursor_position(cursorPosition)
            print("file.FileName::", fileName)
            self.currentTabChanged.emit(fileName)
        except file_manager.NinjaIOException as reason:
            if notStart:
                QMessageBox.information(self,
                    _translate("_s_MainContainer", "The file couldn't be open"), str(reason))
        except Exception as reason:
            logger.error('open_file: %s', reason)
        self.actualTab.notOpening = True
开发者ID:Salmista-94,项目名称:Ninja_PyQt5,代码行数:54,代码来源:main_container.py

示例8: __open_file

    def __open_file(self, fileName='', cursorPosition=-1,
                    tabIndex=None, positionIsLineNumber=False, notStart=True):
        try:
            if not self.is_open(fileName):
                self.actualTab.notOpening = False
                content = file_manager.read_file_content(fileName)
                editorWidget = self.add_editor(fileName, tabIndex=tabIndex,
                    use_open_highlight=True)
                editorWidget.highlighter.set_open_visible_area(
                    positionIsLineNumber, cursorPosition)

                #Add content
                editorWidget.ID = fileName
                editorWidget.setPlainText(content)
                editorWidget.async_highlight()
                encoding = file_manager.get_file_encoding(content)
                editorWidget.encoding = encoding
                if cursorPosition == -1:
                    cursorPosition = 0
                if not positionIsLineNumber:
                    editorWidget.set_cursor_position(cursorPosition)
                else:
                    editorWidget.go_to_line(cursorPosition)
                self.add_standalone_watcher(editorWidget.ID, notStart)

                #New file then try to add a coding line
                if not content:
                    helpers.insert_coding_line(editorWidget)
                    self.save_file(editorWidget=editorWidget)

                if not editorWidget.has_write_permission():
                    fileName += self.tr(" (Read-Only)")
                    index = self.actualTab.currentIndex()
                    self.actualTab.setTabText(index, fileName)

            else:
                self.move_to_open(fileName)
                editorWidget = self.get_actual_editor()
                if editorWidget and notStart and cursorPosition != -1:
                    if positionIsLineNumber:
                        editorWidget.go_to_line(cursorPosition)
                    else:
                        editorWidget.set_cursor_position(cursorPosition)
            self.emit(SIGNAL("currentTabChanged(QString)"), fileName)
        except file_manager.NinjaIOException as reason:
            if not notStart:
                QMessageBox.information(self,
                    self.tr("The file couldn't be open"), reason)
        except Exception as reason:
            logger.error('open_file: %s', reason)
        self.actualTab.notOpening = True
开发者ID:beuno,项目名称:ninja-ide,代码行数:51,代码来源:main_container.py

示例9: __init__

    def __init__(self, url, process=None, parent=None):
        QWidget.__init__(self, parent)
        itab_item.ITabItem.__init__(self)
        self._id = url
        self._process = process
        vbox = QVBoxLayout(self)
        #Web Frame
        QWebSettings.globalSettings().setAttribute(
            QWebSettings.PluginsEnabled, True)
        self.webFrame = QWebView(self)
        self.webFrame.setAcceptDrops(False)
        factory = WebPluginFactory(self)

        self.webFrame.page().setPluginFactory(factory)
        self.webFrame.load(QUrl(url))

        vbox.addWidget(self.webFrame)

        if process is not None:
            time.sleep(0.5)
            self.webFrame.load(QUrl(url))

        if url == resources.START_PAGE_URL:
            self.webFrame.page().setLinkDelegationPolicy(
                QWebPage.DelegateAllLinks)
            self.connect(self.webFrame, SIGNAL("linkClicked(QUrl)"),
                self.start_page_operations)
            if sys.platform == "win32":
                content = file_manager.read_file_content(self.ID)
                pathCss = os.path.join(
                    resources.PRJ_PATH, 'doc', 'css', 'style.css')
                pathJs = os.path.join(resources.PRJ_PATH, 'doc', 'js', 'libs')
                pathImg = os.path.join(resources.PRJ_PATH, 'doc', 'img')
                content = content.replace('css/style.css',
                    pathCss).replace(
                    'src="js/libs/', 'src="%s\\' % pathJs).replace(
                    'src="img/', 'src="%s\\' % pathImg)
                self.webFrame.setHtml(content)
            self._id = 'Start Page'
            policy = Qt.ScrollBarAlwaysOff
        else:
            policy = Qt.ScrollBarAsNeeded
        self.webFrame.page().currentFrame().setScrollBarPolicy(
            Qt.Vertical, policy)
        self.webFrame.page().currentFrame().setScrollBarPolicy(
            Qt.Horizontal, policy)
开发者ID:akatrevorjay,项目名称:ninja-ide,代码行数:46,代码来源:browser_widget.py

示例10: create_class

 def create_class(self, path):
     content = file_manager.read_file_content(path)
     items = introspection.obtain_symbols(content)
     mYPadding = 10
     mXPadding = 10
     for classname, classdetail in list(items["classes"].items()):
         cl = ClassModel(self.graphicView, self.scene)
         cl.set_class_name(classname)
         self.fill_clases(cl, classdetail[1])
         self.scene.addItem(cl)
         cl.setPos(self.mX, self.mY)
         self.mX += cl._get_width() + mXPadding
         if self.hightestY < self.mY + cl.get_height():
             self.hightestY = self.mY + cl.get_height()
         if self.mX > 2000:
             self.mX = -400
             self.mY += self.hightestY + mYPadding
开发者ID:AlexaProjects,项目名称:Alexa2,代码行数:17,代码来源:class_diagram.py

示例11: test_read_file_content

 def test_read_file_content(self):
     filename = os.path.join(self.examples_dir, 'file_for_tests.py')
     content = file_manager.read_file_content(filename)
     expected = ("# -*- coding: utf-8 -*-\n\nprint 'testing'\n"
                 "print 'ñandú testing'\n").encode('utf-8')
     self.assertEqual(content, expected)
开发者ID:AlexaProjects,项目名称:Alexa2,代码行数:6,代码来源:test_file_manager.py


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