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


Python QTextStream.readAll方法代码示例

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


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

示例1: readTextFromFile

# 需要导入模块: from PyQt5.QtCore import QTextStream [as 别名]
# 或者: from PyQt5.QtCore.QTextStream import readAll [as 别名]
    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,代码行数:32,代码来源:tab.py

示例2: openFile

# 需要导入模块: from PyQt5.QtCore import QTextStream [as 别名]
# 或者: from PyQt5.QtCore.QTextStream import readAll [as 别名]
 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,代码行数:30,代码来源:textwidget.py

示例3: __init__

# 需要导入模块: from PyQt5.QtCore import QTextStream [as 别名]
# 或者: from PyQt5.QtCore.QTextStream import readAll [as 别名]
    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,代码行数:32,代码来源:__main__.py

示例4: load_stylesheet_pyqt5

# 需要导入模块: from PyQt5.QtCore import QTextStream [as 别名]
# 或者: from PyQt5.QtCore.QTextStream import readAll [as 别名]
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,代码行数:36,代码来源:__init__.py

示例5: set_window_style

# 需要导入模块: from PyQt5.QtCore import QTextStream [as 别名]
# 或者: from PyQt5.QtCore.QTextStream import readAll [as 别名]
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,代码行数:30,代码来源:__init__.py

示例6: loadStyle

# 需要导入模块: from PyQt5.QtCore import QTextStream [as 别名]
# 或者: from PyQt5.QtCore.QTextStream import readAll [as 别名]
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,代码行数:11,代码来源:__init__.py

示例7: ReadTextFile

# 需要导入模块: from PyQt5.QtCore import QTextStream [as 别名]
# 或者: from PyQt5.QtCore.QTextStream import readAll [as 别名]
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,代码行数:11,代码来源:myutils.py

示例8: readFile

# 需要导入模块: from PyQt5.QtCore import QTextStream [as 别名]
# 或者: from PyQt5.QtCore.QTextStream import readAll [as 别名]
 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,代码行数:11,代码来源:apis.py

示例9: updateTextEdit

# 需要导入模块: from PyQt5.QtCore import QTextStream [as 别名]
# 或者: from PyQt5.QtCore.QTextStream import readAll [as 别名]
    def updateTextEdit(self):
        mib = self.encodingComboBox.itemData(self.encodingComboBox.currentIndex())
        codec = QTextCodec.codecForMib(mib)

        data = QTextStream(self.encodedData)
        data.setAutoDetectUnicode(False)
        data.setCodec(codec)

        self.decodedStr = data.readAll()
        self.textEdit.setPlainText(self.decodedStr)
开发者ID:Axel-Erfurt,项目名称:pyqt5,代码行数:12,代码来源:codecs.py

示例10: ReadResourceTextFile

# 需要导入模块: from PyQt5.QtCore import QTextStream [as 别名]
# 或者: from PyQt5.QtCore.QTextStream import readAll [as 别名]
def ReadResourceTextFile(resFile):

    res = QResource(resFile)
    file = QFile(res.absoluteFilePath())
    file.open(QFile.ReadOnly | QFile.Text)
    textStream = QTextStream(file)
    data = textStream.readAll()
    file.close()

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

示例11: ouvrirtexte

# 需要导入模块: from PyQt5.QtCore import QTextStream [as 别名]
# 或者: from PyQt5.QtCore.QTextStream import readAll [as 别名]
 def ouvrirtexte(self):
     filename, _ = QFileDialog.getOpenFileName(self)
     if filename:
         file = QFile(filename)
         if not file.open(QFile.ReadOnly | QFile.Text):
             QMessageBox.critical(self, appname + version + "Open File",
                                  "Reading Error %s:\n%s." % (filename, file.errorString()))
             return
         instr = QTextStream(file)
         self.ui.plainTextEdit.setPlainText(instr.readAll())
开发者ID:Antidote1911,项目名称:Cryptoshop-GUI,代码行数:12,代码来源:Cryptoshop.py

示例12: loadFile

# 需要导入模块: from PyQt5.QtCore import QTextStream [as 别名]
# 或者: from PyQt5.QtCore.QTextStream import readAll [as 别名]
 def loadFile(self):
     fh = QFile(self.filename)
     print("fh is ", fh)
     if not fh.open(QIODevice.ReadOnly):
         raise IOError(str(fh.errorString()))
     stream = QTextStream(fh)
     stream.setCodec("UTF-8")
     # self.setPlainText("Hello World")
     self.preParse = (stream.readAll())  # Here lies the problem how to fix it? PyQt 3.4.2 Works Fine
     print(self.preParse)
     self.parseOutputData(self.preParse)
开发者ID:hovo1990,项目名称:GROM,代码行数:13,代码来源:exportMWave.py

示例13: read

# 需要导入模块: from PyQt5.QtCore import QTextStream [as 别名]
# 或者: from PyQt5.QtCore.QTextStream import readAll [as 别名]
    def read(self):
        """ Reads the file and returns the content """

        _file = QFile(self.filename)
        if not _file.open(QIODevice.ReadOnly | QIODevice.Text):
            raise Exception(_file.errorString())

        # Codec
        codec = QTextCodec.codecForLocale()
        stream = QTextStream(_file)
        stream.setCodec(codec)
        return stream.readAll()
开发者ID:centaurialpha,项目名称:pireal,代码行数:14,代码来源:pfile.py

示例14: setPersepolisColorScheme

# 需要导入模块: from PyQt5.QtCore import QTextStream [as 别名]
# 或者: from PyQt5.QtCore.QTextStream import readAll [as 别名]
    def setPersepolisColorScheme(self, color_scheme):
        self.persepolis_color_scheme = color_scheme
        if color_scheme == 'Persepolis Old Dark Red':
            persepolis_dark_red = DarkRedPallete()
            self.setPalette(persepolis_dark_red)
            self.setStyleSheet("QMenu::item:selected {background-color : #d64937 ;color : white} QToolTip { color: #ffffff; background-color: #353535; border: 1px solid white; }")
        elif color_scheme == 'Persepolis  Old Dark Blue':
            persepolis_dark_blue = DarkBluePallete()
            self.setPalette(persepolis_dark_blue)
            self.setStyleSheet("QMenu::item:selected { background-color : #2a82da ;color : white } QToolTip { color: #ffffff; background-color: #353535; border: 1px solid white; }")
        elif color_scheme == 'Persepolis ArcDark Red':
            persepolis_arcdark_red = ArcDarkRedPallete()
            self.setPalette(persepolis_arcdark_red)
            self.setStyleSheet("QMenu::item:selected {background-color : #bf474d ; color : white} QToolTip { color: #ffffff; background-color: #353945; border: 1px solid white; } QPushButton {background-color: #353945  } QTabWidget {background-color : #353945;} QMenu {background-color: #353945 }")

        elif color_scheme == 'Persepolis ArcDark Blue':
            persepolis_arcdark_blue = ArcDarkBluePallete()
            self.setPalette(persepolis_arcdark_blue)
            self.setStyleSheet("QMenu::item:selected {background-color : #5294e2 ; color : white } QToolTip { color: #ffffff; background-color: #353945; border: 1px solid white; } QPushButton {background-color: #353945  } QTabWidget {background-color : #353945;} QMenu {background-color: #353945 }")
        elif color_scheme == 'Persepolis Old Light Red':
            persepolis_light_red = LightRedPallete()
            self.setPalette(persepolis_light_red)
            self.setStyleSheet("QMenu::item:selected {background-color : #d64937 ;color : white} QToolTip { color: #ffffff; background-color: #353535; border: 1px solid white; }")

        elif color_scheme == 'Persepolis Old Light Blue':
            persepolis_light_blue = LightBluePallete()
            self.setPalette(persepolis_light_blue)
            self.setStyleSheet("QMenu::item:selected { background-color : #2a82da ;color : white } QToolTip { color: #ffffff; background-color: #353535; border: 1px solid white; }")

        elif color_scheme == 'Persepolis Dark Blue':
            file = QFile(":/dark_style.qss")
            file.open(QFile.ReadOnly | QFile.Text)
            stream = QTextStream(file)
            self.setStyleSheet(stream.readAll())

        elif color_scheme == 'Persepolis Light Blue':
            file = QFile(":/light_style.qss")
            file.open(QFile.ReadOnly | QFile.Text)
            stream = QTextStream(file)
            self.setStyleSheet(stream.readAll())
开发者ID:kazemihabib,项目名称:persepolis,代码行数:42,代码来源:persepolis.py

示例15: loadFile

# 需要导入模块: from PyQt5.QtCore import QTextStream [as 别名]
# 或者: from PyQt5.QtCore.QTextStream import readAll [as 别名]
    def loadFile(self, fileName):
        file = QFile(fileName)
        if not file.open(QFile.ReadOnly | QFile.Text):
            QMessageBox.warning(self, "Application",
                    "Cannot read file %s:\n%s." % (fileName, file.errorString()))
            return

        inf = QTextStream(file)
        QApplication.setOverrideCursor(Qt.WaitCursor)
        self.textEdit.setPlainText(inf.readAll())
        QApplication.restoreOverrideCursor()

        self.setCurrentFile(fileName)
        self.statusBar().showMessage("File loaded", 2000)
开发者ID:Axel-Erfurt,项目名称:pyqt5,代码行数:16,代码来源:application.py


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