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


Python QtCore.QTextStream类代码示例

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


在下文中一共展示了QTextStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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:Salmista-94,项目名称:Ninja_3.0_PyQt5,代码行数:32,代码来源:locator.py

示例2: findFiles

    def findFiles(self, files, text):
        progressDialog = QProgressDialog(self)

        progressDialog.setCancelButtonText("&Cancel")
        progressDialog.setRange(0, files.count())
        progressDialog.setWindowTitle("Find Files")

        foundFiles = []

        for i in range(files.count()):
            progressDialog.setValue(i)
            progressDialog.setLabelText("Searching file number %d of %d..." % (i, files.count()))
            QApplication.processEvents()

            if progressDialog.wasCanceled():
                break

            inFile = QFile(self.currentDir.absoluteFilePath(files[i]))

            if inFile.open(QIODevice.ReadOnly):
                stream = QTextStream(inFile)
                while not stream.atEnd():
                    if progressDialog.wasCanceled():
                        break
                    line = stream.readLine()
                    if text in line:
                        foundFiles.append(files[i])
                        break

        progressDialog.close()

        return foundFiles
开发者ID:death-finger,项目名称:Scripts,代码行数:32,代码来源:findfiles.py

示例3: __init__

    def __init__(self, ui_file, bus, devices=[], parent=None):
        QtWidgets.QMainWindow.__init__(self, parent=parent)

        self.bus = bus

        # TODO: CAMPid 980567566238416124867857834291346779
        ico_file = os.path.join(QFileInfo.absolutePath(QFileInfo(__file__)), "icon.ico")
        ico = QtGui.QIcon(ico_file)
        self.setWindowIcon(ico)

        ui = ui_file
        # TODO: CAMPid 9549757292917394095482739548437597676742
        if not QFileInfo(ui).isAbsolute():
            ui_file = os.path.join(QFileInfo.absolutePath(QFileInfo(__file__)), ui)
        else:
            ui_file = ui
        ui_file = QFile(ui_file)
        ui_file.open(QFile.ReadOnly | QFile.Text)
        ts = QTextStream(ui_file)
        sio = io.StringIO(ts.readAll())
        self.ui = uic.loadUi(sio, self)

        self.ui.action_About.triggered.connect(self.about)

        device_tree = epyqlib.devicetree.Tree()
        device_tree_model = epyqlib.devicetree.Model(root=device_tree)
        device_tree_model.device_removed.connect(self._remove_device)
        self.ui.device_tree.setModel(device_tree_model)

        self.ui.device_tree.device_selected.connect(self.set_current_device)
开发者ID:altendky,项目名称:st,代码行数:30,代码来源:__main__.py

示例4: openFile

 def openFile(self):
     if settings.get("file_dialog_dir"):
         self.curDir = '~/'
     else:
         self.curDir = settings.get("file_dialog_dir")
     fn = QFileDialog.getOpenFileName(self,
             self.tr("Open File..."), self.curDir,
             self.tr("HTML-Files (*.htm *.html);;All Files (*)"))
     QApplication.setOverrideCursor(Qt.WaitCursor)
     if fn:
         self.lastFolder = os.path.dirname(fn)
         if os.path.exists(fn):
             if os.path.isfile(fn):
                 f = QFile(fn)
                 if not f.open(QIODevice.ReadOnly |
                               QIODevice.Text):
                     QtGui.QMessageBox.information(self.parent(),
                     self.tr("Error - Lector"),
                     self.tr("Can't open '%s.'" % fn))
                 else:
                     stream = QTextStream(f)
                     text = stream.readAll()
                     self.setText(text)
             else:
                 QMessageBox.information(self.parent(),
                 self.tr("Error - Lector"),
                 self.tr("'%s' is not a file." % fn))
     QApplication.restoreOverrideCursor()
开发者ID:correosdelbosque,项目名称:lector,代码行数:28,代码来源:textwidget.py

示例5: _grep_file

    def _grep_file(self, file_path, file_name):
        """Search for each line inside the file."""
        if not self.by_phrase:
            with open(file_path, 'r') as f:
                content = f.read()
            words = [word for word in
                self.search_pattern.pattern().split('|')]
            words.insert(0, True)

            def check_whole_words(result, word):
                return result and content.find(word) != -1
            if not reduce(check_whole_words, words):
                return
        file_object = QFile(file_path)
        if not file_object.open(QFile.ReadOnly):
            return

        stream = QTextStream(file_object)
        lines = []
        line_index = 0
        line = stream.readLine()
        while not self._cancel and not (stream.atEnd() and not line):
            column = self.search_pattern.indexIn(line)
            if column != -1:
                lines.append((line_index, line))
            #take the next line!
            line = stream.readLine()
            line_index += 1
        #emit a signal!
        relative_file_name = file_manager.convert_to_relative(
            self.root_dir, file_path)
        self.found_pattern.emit((relative_file_name, lines))
开发者ID:Salmista-94,项目名称:Ninja_3.0_PyQt5,代码行数:32,代码来源:find_in_files.py

示例6: save

 def save(self):
     if "Unnamed" in self.filename:
         filename = QFileDialog.getSaveFileName(self,
                                                "G.R.O.M. Editor -- Save File As", self.filename,
                                                "MD files (*.mdp *.itp *.top *.*)")
         print('filename is ', filename)
         if len(filename[0]) == 0:
             return
         self.filename = filename[0]
     self.setWindowTitle(QFileInfo(self.filename).fileName())
     exception = None
     fh = None
     try:
         fh = QFile(self.filename)
         if not fh.open(QIODevice.WriteOnly):
             raise IOError(str(fh.errorString()))
         stream = QTextStream(fh)
         stream.setCodec("UTF-8")
         stream << self.toPlainText()
         self.document().setModified(False)
     except EnvironmentError as e:
         exception = e
     finally:
         if fh is not None:
             fh.close()
         if exception is not None:
             raise exception
开发者ID:hovo1990,项目名称:GROM,代码行数:27,代码来源:textedit.py

示例7: readTextFromFile

    def readTextFromFile(self, fileName=None, encoding=None):
        previousFileName = self._fileName
        if fileName:
            self._fileName = fileName

            # Only try to detect encoding if it is not specified
        if encoding is None and globalSettings.detectEncoding:
            encoding = self.detectFileEncoding(self._fileName)

            # TODO: why do we open the file twice: for detecting encoding
            # and for actual read? Can we open it just once?
        openfile = QFile(self._fileName)
        openfile.open(QFile.ReadOnly)
        stream = QTextStream(openfile)
        encoding = encoding or globalSettings.defaultCodec
        if encoding:
            stream.setCodec(encoding)
            # If encoding is specified or detected, we should save the file with
            # the same encoding
            self.editBox.document().setProperty("encoding", encoding)

        text = stream.readAll()
        openfile.close()

        self.editBox.setPlainText(text)
        self.editBox.document().setModified(False)

        if previousFileName != self._fileName:
            self.updateActiveMarkupClass()
            self.fileNameChanged.emit()
开发者ID:retext-project,项目名称:retext,代码行数:30,代码来源:tab.py

示例8: set_window_style

def set_window_style(window):
    """
    :return the stylesheet string
    """
    # Smart import of the rc file

    f = QFile(":dark_style.qss")
    if not f.exists():
        print('Custom stylesheet not present')
        Lumberjack.error("Unable to load stylesheet, file not found in "
                         "resources")
        return ""
    else:
        f.open(QFile.ReadOnly | QFile.Text)
        ts = QTextStream(f)
        stylesheet = ts.readAll()
        if platform.system().lower() == 'darwin':  # see issue #12 on github
            mac_fix = '''
            QDockWidget::title
            {
                background-color: #31363b;
                text-align: center;
                height: 12px;
            }
            '''
            stylesheet += mac_fix
        window.setWindowIcon(QIcon(':/app_icons/rc/PAT_icon.png'))
        window.setStyleSheet(stylesheet)
开发者ID:MazeFX,项目名称:pat,代码行数:28,代码来源:__init__.py

示例9: openFile

    def openFile(self, path=None):
        if not path:
            path, _ = QFileDialog.getOpenFileName(self, "Choose a data file",
                    '', '*.cht')

        if path:
            f = QFile(path)

            if f.open(QFile.ReadOnly | QFile.Text):
                stream = QTextStream(f)

                self.model.removeRows(0, self.model.rowCount(QModelIndex()),
                        QModelIndex())

                row = 0
                line = stream.readLine()
                while line:
                    self.model.insertRows(row, 1, QModelIndex())

                    pieces = line.split(',')
                    self.model.setData(self.model.index(row, 0, QModelIndex()),
                                pieces[0])
                    self.model.setData(self.model.index(row, 1, QModelIndex()),
                                float(pieces[1]))
                    self.model.setData(self.model.index(row, 0, QModelIndex()),
                                QColor(pieces[2]), Qt.DecorationRole)

                    row += 1
                    line = stream.readLine()

                f.close()
                self.statusBar().showMessage("Loaded %s" % path, 2000)
开发者ID:PWilsonUofC,项目名称:VGenes,代码行数:32,代码来源:chart.py

示例10: write

 def write(self, tileset, fileName):
     file = QSaveFile(fileName)
     if (not file.open(QIODevice.WriteOnly | QIODevice.Text)):
         self.mError = self.tr("Could not open file for writing.")
         return False
     
     converter = MapToVariantConverter()
     variant = converter.toVariant(tileset, QFileInfo(fileName).dir())
     writer = json
     try:
         result = writer.dumps(variant, indent=4)
     except:
         # This can only happen due to coding error
         self.mError = self.tr('Unknow error.')
         return False
     
     out = QTextStream(file)
     out << result
     out.flush()
     if (file.error() != QFile.NoError):
         self.mError = self.tr("Error while writing file:\n%1").arg(file.errorString())
         return False
     
     if (not file.commit()):
         self.mError = file.errorString()
         return False
     
     return True
开发者ID:theall,项目名称:Python-Tiled,代码行数:28,代码来源:jsonplugin.py

示例11: load_stylesheet_pyqt5

def load_stylesheet_pyqt5():
    """
    Loads the stylesheet for use in a pyqt5 application.

    :param pyside: True to load the pyside rc file, False to load the PyQt rc file

    :return the stylesheet string
    """
    # Smart import of the rc file
    import theme.pyqt5_style_rc

    # Load the stylesheet content from resources
    from PyQt5.QtCore import QFile, QTextStream

    f = QFile(":qdarkstyle/style.qss")
    if not f.exists():
        _logger().error("Unable to load stylesheet, file not found in "
                        "resources")
        return ""
    else:
        f.open(QFile.ReadOnly | QFile.Text)
        ts = QTextStream(f)
        stylesheet = ts.readAll()
        if platform.system().lower() == 'darwin':  # see issue #12 on github
            mac_fix = '''
            QDockWidget::title
            {
                background-color: #353434;
                text-align: center;
                height: 12px;
            }
            '''
            stylesheet += mac_fix
        return stylesheet
开发者ID:DrHaze,项目名称:PyQt5-FormPreview,代码行数:34,代码来源:__init__.py

示例12: save

    def save(self, content, path=None):
        """
        Write a temporary file with .tnj extension and copy it over the
        original one.
        .nsf = Ninja Swap File
        # FIXME: Where to locate addExtension, does not fit here
        """
        new_path = False
        if path:
            self.attach_to_path(path)
            new_path = True

        save_path = self._file_path

        if not save_path:
            raise NinjaNoFileNameException("I am asked to write a "
                                           "file but no one told me where")
        swap_save_path = "%s.nsp" % save_path

        # If we have a file system watcher, remove the file path
        # from its watch list until we are done making changes.
        if self.__watcher is not None:
            self.__watcher.removePath(save_path)

        flags = QIODevice.WriteOnly | QIODevice.Truncate
        f = QFile(swap_save_path)
        if settings.use_platform_specific_eol():
            flags |= QIODevice.Text

        if not f.open(flags):
            raise NinjaIOException(f.errorString())

        stream = QTextStream(f)
        encoding = get_file_encoding(content)
        if encoding:
            stream.setCodec(encoding)

        encoded_stream = stream.codec().fromUnicode(content)
        f.write(encoded_stream)
        f.flush()
        f.close()
        # SIGNAL: Will save (temp, definitive) to warn folder to do something
        self.willSave.emit(swap_save_path, save_path)
        self.__mtime = os.path.getmtime(swap_save_path)
        shutil.move(swap_save_path, save_path)
        self.reset_state()

        # If we have a file system watcher, add the saved path back
        # to its watch list, otherwise create a watcher and start
        # watching
        if self.__watcher is not None:
            if new_path:
                # self.__watcher.removePath(self.__watcher.files()[0])
                self.__watcher.addPath(self._file_path)
            else:
                self.__watcher.addPath(save_path)
        else:
            self.start_watching()
        return self
开发者ID:ninja-ide,项目名称:ninja-ide,代码行数:59,代码来源:nfile.py

示例13: readFile

 def readFile(self, path, coding = "UTF-8"):
     """读取文件"""
     file = QFile(path)
     file.open(QIODevice.ReadOnly | QIODevice.Text)
     fin = QTextStream(file)
     fin.setCodec(coding)
     data = fin.readAll()
     file.close()
     return data
开发者ID:892768447,项目名称:BlogClient,代码行数:9,代码来源:apis.py

示例14: loadStyle

def loadStyle(stylesheet):

    if stylesheet not in StyleSheets.keys():
        raise RuntimeError('Invalid stylesheet (%s)' %stylesheet)

    f = QFile(StyleSheets[stylesheet])
    f.open(QFile.ReadOnly | QFile.Text)
    ts = QTextStream(f)
    return  ts.readAll()
开发者ID:jni,项目名称:cecog,代码行数:9,代码来源:__init__.py

示例15: ReadTextFile

def ReadTextFile(filePath):

    file = QFile(filePath)
    file.open(QFile.ReadOnly | QFile.Text)
    textStream = QTextStream(file)
    data = textStream.readAll()
    file.close()

    return data
开发者ID:dkleinbe,项目名称:Graph42,代码行数:9,代码来源:myutils.py


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