Python PyQt5.QtCore 模块,QTextStream() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用PyQt5.QtCore.QTextStream()

项目:pisi-player    作者:mthnzbk    | 项目源码 | 文件源码
def __init__(self, subtitle, encoding="UTF-8"):
        super().__init__()

        subtitlefile = QFile(subtitle)

        if not subtitlefile.open(QIODevice.ReadOnly | QIODevice.Text):
            return

        text = QTextStream(subtitlefile)
        text.setCodec(encoding)

        subtitletext = text.readAll()

        # ('s?ra', 'saat', 'dakika', 'saniye', 'milisaniye', 'saat', 'dakika', 'saniye', 'milisaniye', 'birincisat?r', 'ikincisat?r')
        compile = re.compile(r"(\d.*)\n(\d{2}):(\d{2}):(\d{2}),(\d{3}) --> (\d{2}):(\d{2}):(\d{2}),(\d{3})\n(\W.*|\w.*)\n(\w*|\W*|\w.*|\W.*)\n")
        self.sublist = compile.findall(subtitletext)
项目:Mac-Python-3.X    作者:L1nwatch    | 项目源码 | 文件源码
def save(self):
        filename, _ = QFileDialog.getSaveFileName(self,
                "Choose a file name", '.', "HTML (*.html *.htm)")
        if not filename:
            return

        file = QFile(filename)
        if not file.open(QFile.WriteOnly | QFile.Text):
            QMessageBox.warning(self, "Dock Widgets",
                    "Cannot write file %s:\n%s." % (filename, file.errorString()))
            return

        out = QTextStream(file)
        QApplication.setOverrideCursor(Qt.WaitCursor)
        out << self.textEdit.toHtml()
        QApplication.restoreOverrideCursor()

        self.statusBar().showMessage("Saved '%s'" % filename, 2000)
项目:Mac-Python-3.X    作者:L1nwatch    | 项目源码 | 文件源码
def __init__(self, parent=None):
        super(DragWidget, self).__init__(parent)

        dictionaryFile = QFile(':/dictionary/words.txt')
        dictionaryFile.open(QIODevice.ReadOnly)

        x = 5
        y = 5

        for word in QTextStream(dictionaryFile).readAll().split():
            wordLabel = DragLabel(word, self)
            wordLabel.move(x, y)
            wordLabel.show()
            x += wordLabel.width() + 2
            if x >= 195:
                x = 5
                y += wordLabel.height() + 2

        newPalette = self.palette()
        newPalette.setColor(QPalette.Window, Qt.white)
        self.setPalette(newPalette)

        self.setAcceptDrops(True)
        self.setMinimumSize(400, max(200, y))
        self.setWindowTitle("Draggable Text")
项目:examples    作者:pyqt    | 项目源码 | 文件源码
def save(self):
        filename, _ = QFileDialog.getSaveFileName(self,
                "Choose a file name", '.', "HTML (*.html *.htm)")
        if not filename:
            return

        file = QFile(filename)
        if not file.open(QFile.WriteOnly | QFile.Text):
            QMessageBox.warning(self, "Dock Widgets",
                    "Cannot write file %s:\n%s." % (filename, file.errorString()))
            return

        out = QTextStream(file)
        QApplication.setOverrideCursor(Qt.WaitCursor)
        out << self.textEdit.toHtml()
        QApplication.restoreOverrideCursor()

        self.statusBar().showMessage("Saved '%s'" % filename, 2000)
项目:examples    作者:pyqt    | 项目源码 | 文件源码
def __init__(self, parent=None):
        super(DragWidget, self).__init__(parent)

        dictionaryFile = QFile(':/dictionary/words.txt')
        dictionaryFile.open(QIODevice.ReadOnly)

        x = 5
        y = 5

        for word in QTextStream(dictionaryFile).readAll().split():
            wordLabel = DragLabel(word, self)
            wordLabel.move(x, y)
            wordLabel.show()
            x += wordLabel.width() + 2
            if x >= 195:
                x = 5
                y += wordLabel.height() + 2

        newPalette = self.palette()
        newPalette.setColor(QPalette.Window, Qt.white)
        self.setPalette(newPalette)

        self.setAcceptDrops(True)
        self.setMinimumSize(400, max(200, y))
        self.setWindowTitle("Draggable Text")
项目:headcache    作者:s9w    | 项目源码 | 文件源码
def load_file(self, filename):
        file = QFile("{}/{}".format(os.getcwd(), filename))
        if not file.open(QtCore.QIODevice.ReadOnly):
            print("couldn't open file")
        stream = QtCore.QTextStream(file)
        stream.setCodec("UTF-8")
        content = stream.readAll()

        # built structure tree
        self.ast_generator.clear_ast()
        self.ast_generator.parse(mistune.preprocessing(content), filename=filename)
        entry = self.ast_generator.ast
        entry["time"] = QFileInfo(file).lastModified().toMSecsSinceEpoch()

        # add html code to tree nodes
        for i, lvl2 in enumerate(list(entry["content"])):
            content_markdown = "##{}\n{}".format(lvl2["title"], lvl2["content"])
            content_html = self.markdowner_simple(content_markdown)
            entry["content"][i]["html"] = self.preview_css_str + content_html
        return entry
项目:Osdag    作者:osdag-admin    | 项目源码 | 文件源码
def displaylog_totextedit(self, commLogicObj):
        """
        This method displaying Design messages(log messages)to textedit widget.
        """
        fname = str(commLogicObj.call_saveMessages())
        afile = QFile(fname)

        if not afile.open(QIODevice.ReadOnly):  # ReadOnly
            QMessageBox.information(None, 'info', afile.errorString())

        stream = QTextStream(afile)
        self.ui.textEdit.clear()
        self.ui.textEdit.setHtml(stream.readAll())
        vscrollBar = self.ui.textEdit.verticalScrollBar()
        vscrollBar.setValue(vscrollBar.maximum())
        afile.close()
项目:Osdag    作者:osdag-admin    | 项目源码 | 文件源码
def displaylog_totextedit(self, commLogicObj):

        '''
        This method displaying Design messages(log messages)to textedit widget.
        '''
        fname = str(commLogicObj.call_saveMessages())
        afile = QFile(fname)

        if not afile.open(QIODevice.ReadOnly):  # ReadOnly
            QMessageBox.information(None, 'info', afile.errorString())

        stream = QTextStream(afile)
        self.ui.textEdit.clear()
        self.ui.textEdit.setHtml(stream.readAll())
        vscrollBar = self.ui.textEdit.verticalScrollBar()
        vscrollBar.setValue(vscrollBar.maximum())
        afile.close()

    # QtViewer
项目:Osdag    作者:osdag-admin    | 项目源码 | 文件源码
def displaylog_totextedit(self,commLogicObj):
        '''
        This method displaying Design messages(log messages)to textedit widget.
        '''
        fname = str(commLogicObj.call_saveMessages())
        afile = QFile(fname)

        if not afile.open(QIODevice.ReadOnly):  # ReadOnly
            QMessageBox.information(None, 'info', afile.errorString())

        stream = QTextStream(afile)
        self.ui.textEdit.clear()
        self.ui.textEdit.setHtml(stream.readAll())
        vscroll_bar = self.ui.textEdit.verticalScrollBar()
        vscroll_bar.setValue(vscroll_bar.maximum())
        afile.close()

    # QtViewer
项目:pyqt5-example    作者:guinslym    | 项目源码 | 文件源码
def save(self):
        filename, _ = QFileDialog.getSaveFileName(self,
                "Choose a file name", '.', "HTML (*.html *.htm)")
        if not filename:
            return

        file = QFile(filename)
        if not file.open(QFile.WriteOnly | QFile.Text):
            QMessageBox.warning(self, "Dock Widgets",
                    "Cannot write file %s:\n%s." % (filename, file.errorString()))
            return

        out = QTextStream(file)
        QApplication.setOverrideCursor(Qt.WaitCursor)
        out << self.textEdit.toHtml()
        QApplication.restoreOverrideCursor()

        self.statusBar().showMessage("Saved '%s'" % filename, 2000)
项目:pyqt5-example    作者:guinslym    | 项目源码 | 文件源码
def __init__(self, parent=None):
        super(DragWidget, self).__init__(parent)

        dictionaryFile = QFile(':/dictionary/words.txt')
        dictionaryFile.open(QIODevice.ReadOnly)

        x = 5
        y = 5

        for word in QTextStream(dictionaryFile).readAll().split():
            wordLabel = DragLabel(word, self)
            wordLabel.move(x, y)
            wordLabel.show()
            x += wordLabel.width() + 2
            if x >= 195:
                x = 5
                y += wordLabel.height() + 2

        newPalette = self.palette()
        newPalette.setColor(QPalette.Window, Qt.white)
        self.setPalette(newPalette)

        self.setAcceptDrops(True)
        self.setMinimumSize(400, max(200, y))
        self.setWindowTitle("Draggable Text")
项目:a-cadmci    作者:florez87    | 项目源码 | 文件源码
def load_stylesheet(pyside=True):
    """
    Loads the stylesheet. Takes care of importing the rc module.

    :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
    if pyside:
        import qdarkstyle.pyside_style_rc
    else:
        import qdarkstyle.pyqt_style_rc

    # Load the stylesheet content from resources
    if not pyside:
        from PyQt4.QtCore import QFile, QTextStream
    else:
        from PySide.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: #31363b;
                text-align: center;
                height: 12px;
            }
            '''
            stylesheet += mac_fix
        return stylesheet
项目:a-cadmci    作者:florez87    | 项目源码 | 文件源码
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 qdarkstyle.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: #31363b;
                text-align: center;
                height: 12px;
            }
            '''
            stylesheet += mac_fix
        return stylesheet
项目:zoocore    作者:dsparrow27    | 项目源码 | 文件源码
def load_stylesheet(pyside=True):
    """
    Loads the stylesheet. Takes care of importing the rc module.

    :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
    if pyside:
        pass
    else:
        pass

    # Load the stylesheet content from resources
    from qt.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: #31363b;
                text-align: center;
                height: 12px;
            }
            '''
            stylesheet += mac_fix
        return stylesheet
项目:zoocore    作者:dsparrow27    | 项目源码 | 文件源码
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

    # 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: #31363b;
                text-align: center;
                height: 12px;
            }
            '''
            stylesheet += mac_fix
        return stylesheet
项目:vidcutter    作者:ozmartian    | 项目源码 | 文件源码
def loadQSS(theme, devmode: bool = False) -> str:
        if devmode:
            filename = os.path.join(QFileInfo(__file__).absolutePath(), 'vidcutter/styles/{}.qss'.format(theme))
        else:
            filename = ':/styles/{}.qss'.format(theme)
        if QFileInfo(filename).exists():
            qssfile = QFile(filename)
            qssfile.open(QFile.ReadOnly | QFile.Text)
            content = QTextStream(qssfile).readAll()
            qApp.setStyleSheet(content)
            return content
项目:vidcutter    作者:ozmartian    | 项目源码 | 文件源码
def __init__(self, appid, *argv):
        super(SingleApplication, self).__init__(*argv)
        self._appid = appid
        self._activationWindow = None
        self._activateOnMessage = False
        self._outSocket = QLocalSocket()
        self._outSocket.connectToServer(self._appid)
        self._isRunning = self._outSocket.waitForConnected()
        self._outStream = None
        self._inSocket = None
        self._inStream = None
        self._server = None
        self.settings = QSettings(SingleApplication.getSettingsPath(), QSettings.IniFormat)
        self.singleInstance = self.settings.value('singleInstance', 'on', type=str) in {'on', 'true'}
        if self._isRunning and self.singleInstance:
            self._outStream = QTextStream(self._outSocket)
            for a in argv[0][1:]:
                a = os.path.join(os.getcwd(), a)
                if os.path.isfile(a):
                    self.sendMessage(a)
                    break
            sys.exit(0)
        else:
            error = self._outSocket.error()
            if error == QLocalSocket.ConnectionRefusedError:
                self.close()
                QLocalServer.removeServer(self._appid)
            self._outSocket = None
            self._server = QLocalServer()
            self._server.listen(self._appid)
            self._server.newConnection.connect(self._onNewConnection)
项目:vidcutter    作者:ozmartian    | 项目源码 | 文件源码
def _onNewConnection(self):
        if self._inSocket:
            self._inSocket.readyRead.disconnect(self._onReadyRead)
        self._inSocket = self._server.nextPendingConnection()
        if not self._inSocket:
            return
        self._inStream = QTextStream(self._inSocket)
        self._inSocket.readyRead.connect(self._onReadyRead)
        if self._activateOnMessage:
            self.activateWindow()
项目:MyoSEMG    作者:LuffyDai    | 项目源码 | 文件源码
def __init__(self,parent=None):
        myo.Ui_MainWindow.__init__(self,parent)
        self.setWindowFlags(Qt.FramelessWindowHint)
        f = QFile("D:\MyoSEMG\BorderlessWindow.css")
        if not f.exists():
            self.statusBar().showMessage("Unable to load stylesheet, file not found in resources")
        else:
            f.open(QFile.ReadOnly | QFile.Text)
            ts = QTextStream(f)
            stylesheet = ts.readAll()
        self.setStyleSheet(stylesheet)
        title_bar = QtWidgets.QWidget()
        title_bar.pushButtonMinimize =  QtWidgets.QToolButton()
        title_bar.pushButtonMinimize.setIcon(QtGui.QIcon('Icons/Minimize.png'))
        title_bar.pushButtonMaxmize = QtWidgets.QToolButton()
        title_bar.pushButtonMaxmize.setIcon(QtGui.QIcon('Icons/Maxmize.png'))
        title_bar.pushButtonClose = QtWidgets.QToolButton()
        title_bar.pushButtonClose.setIcon(QtGui.QIcon('Icons/Close.png'))
        title_bar.pushButtonMinimize.setMinimumHeight(10)
        title_bar.pushButtonClose.setMinimumHeight(10)
        title_bar.pushButtonMaxmize.setMinimumHeight(10)
        label = QtWidgets.QLabel(self)
        label.setText("MyoSEMG")
        title_bar.setWindowTitle("MyoSEMG")
        hbox = QtWidgets.QHBoxLayout()
        hbox.addWidget(label)
        hbox.addWidget(title_bar.pushButtonMinimize)
        hbox.addWidget(title_bar.pushButtonMaxmize)
        hbox.addWidget(title_bar.pushButtonClose)
        hbox.insertStretch(1,500)
        hbox.setSpacing(0)
        self.setSizePolicy(QtWidgets.QSizePolicy.Expanding,QtWidgets.QSizePolicy.Fixed)
        self.maxNormal = False
        title_bar.pushButtonClose.clicked().connect(self.close)
        title_bar.pushButtonMinimize.clicked.connect(self.showSmall)
        title_bar.pushButtonMaxmize.clicked.connect(self.showMaxRestore)
项目:MyoSEMG    作者:LuffyDai    | 项目源码 | 文件源码
def load_darkstyle():
    f = QFile("darkstyle\style.qss")
    if not f.exists():
        _logger().error("Unable to load stylesheet, file not  in resources")
        return ""
    else:
        f.open(QFile.ReadOnly|QFile.Text)
        ts = QTextStream(f)
        stylesheet = ts.readAll()
        return stylesheet
项目:MyoSEMG    作者:LuffyDai    | 项目源码 | 文件源码
def load_windowstyle():
    f = QFile("D:\MyoSEMG\BorderlessWindow.css")
    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()
        return stylesheet
项目:PyQt5_stylesheets    作者:RedFalsh    | 项目源码 | 文件源码
def load_stylesheet(pyside=True):
    """
    Loads the stylesheet. Takes care of importing the rc module.

    :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
    if pyside:
        import qdarkstyle.pyside_style_rc
    else:
        import qdarkstyle.pyqt_style_rc

    # Load the stylesheet content from resources
    if not pyside:
        from PyQt4.QtCore import QFile, QTextStream
    else:
        from PySide.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: #31363b;
                text-align: center;
                height: 12px;
            }
            '''
            stylesheet += mac_fix
        return stylesheet
项目:Mac-Python-3.X    作者:L1nwatch    | 项目源码 | 文件源码
def open(self):
        fileName, _ = QFileDialog.getOpenFileName(self)
        if fileName:
            fd = QFile(fileName)
            if not fd.open(QIODevice.ReadOnly):
                QMessageBox.information(self, "Unable to open file",
                        fd.errorString())
                return

            output = QTextStream(fd).readAll()

            # Display contents.
            self.centralWidget.plainTextEdit.setPlainText(output)
            self.centralWidget.setBaseUrl(QUrl.fromLocalFile(fileName))
项目:Mac-Python-3.X    作者:L1nwatch    | 项目源码 | 文件源码
def save(self):
        content = self.centralWidget.plainTextEdit.toPlainText()
        fileName, _ = QFileDialog.getSaveFileName(self)
        if fileName:
            fd = QFile(fileName)
            if not fd.open(QIODevice.WriteOnly):
                QMessageBox.information(self, "Unable to open file",
                        fd.errorString())
                return

            QTextStream(fd) << content
项目:Mac-Python-3.X    作者:L1nwatch    | 项目源码 | 文件源码
def slotSourceDownloaded(self):
        reply = self.sender()
        self.textEdit = QTextEdit()
        self.textEdit.setAttribute(Qt.WA_DeleteOnClose)
        self.textEdit.show()
        self.textEdit.setPlainText(QTextStream(reply).readAll())
        self.textEdit.resize(600, 400)
        reply.deleteLater()
项目:Mac-Python-3.X    作者:L1nwatch    | 项目源码 | 文件源码
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)
项目:Mac-Python-3.X    作者:L1nwatch    | 项目源码 | 文件源码
def loadFile(self, fileName):
        file = QFile(fileName)
        if not file.open( QFile.ReadOnly | QFile.Text):
            QMessageBox.warning(self, "Recent Files",
                    "Cannot read file %s:\n%s." % (fileName, file.errorString()))
            return

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

        self.setCurrentFile(fileName)
        self.statusBar().showMessage("File loaded", 2000)
项目:Mac-Python-3.X    作者:L1nwatch    | 项目源码 | 文件源码
def saveFile(self, fileName):
        file = QFile(fileName)
        if not file.open( QFile.WriteOnly | QFile.Text):
            QMessageBox.warning(self, "Recent Files",
                    "Cannot write file %s:\n%s." % (fileName, file.errorString()))
            return

        outstr = QTextStream(file)
        QApplication.setOverrideCursor(Qt.WaitCursor)
        outstr << self.textEdit.toPlainText()
        QApplication.restoreOverrideCursor()

        self.setCurrentFile(fileName)
        self.statusBar().showMessage("File saved", 2000)
项目:examples    作者:pyqt    | 项目源码 | 文件源码
def open(self):
        fileName, _ = QFileDialog.getOpenFileName(self)
        if fileName:
            fd = QFile(fileName)
            if not fd.open(QIODevice.ReadOnly):
                QMessageBox.information(self, "Unable to open file",
                        fd.errorString())
                return

            output = QTextStream(fd).readAll()

            # Display contents.
            self.centralWidget.plainTextEdit.setPlainText(output)
            self.centralWidget.setBaseUrl(QUrl.fromLocalFile(fileName))
项目:examples    作者:pyqt    | 项目源码 | 文件源码
def save(self):
        content = self.centralWidget.plainTextEdit.toPlainText()
        fileName, _ = QFileDialog.getSaveFileName(self)
        if fileName:
            fd = QFile(fileName)
            if not fd.open(QIODevice.WriteOnly):
                QMessageBox.information(self, "Unable to open file",
                        fd.errorString())
                return

            QTextStream(fd) << content
项目:examples    作者:pyqt    | 项目源码 | 文件源码
def slotSourceDownloaded(self):
        reply = self.sender()
        self.textEdit = QTextEdit()
        self.textEdit.setAttribute(Qt.WA_DeleteOnClose)
        self.textEdit.show()
        self.textEdit.setPlainText(QTextStream(reply).readAll())
        self.textEdit.resize(600, 400)
        reply.deleteLater()
项目:examples    作者:pyqt    | 项目源码 | 文件源码
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)
项目:examples    作者:pyqt    | 项目源码 | 文件源码
def loadFile(self, fileName):
        file = QFile(fileName)
        if not file.open( QFile.ReadOnly | QFile.Text):
            QMessageBox.warning(self, "Recent Files",
                    "Cannot read file %s:\n%s." % (fileName, file.errorString()))
            return

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

        self.setCurrentFile(fileName)
        self.statusBar().showMessage("File loaded", 2000)
项目:examples    作者:pyqt    | 项目源码 | 文件源码
def saveFile(self, fileName):
        file = QFile(fileName)
        if not file.open( QFile.WriteOnly | QFile.Text):
            QMessageBox.warning(self, "Recent Files",
                    "Cannot write file %s:\n%s." % (fileName, file.errorString()))
            return

        outstr = QTextStream(file)
        QApplication.setOverrideCursor(Qt.WaitCursor)
        outstr << self.textEdit.toPlainText()
        QApplication.restoreOverrideCursor()

        self.setCurrentFile(fileName)
        self.statusBar().showMessage("File saved", 2000)
项目:ConcretePy    作者:MarioRaul    | 项目源码 | 文件源码
def load_stylesheet(pyside=True):
    """
    Loads the stylesheet. Takes care of importing the images module.

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

    :return the stylesheet string
    """
    # Smart import of the images file
    if pyside:
        import qdarkstyle.pyside_style_rc
    else:
        import qdarkstyle.pyqt_style_rc

    # Load the stylesheet content from resources
    if not pyside:
        from PyQt4.QtCore import QFile, QTextStream
    else:
        from PySide.QtCore import QFile, QTextStream

    f = QFile(":darkBlue/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: #31363b;
                text-align: center;
                height: 12px;
            }
            '''
            stylesheet += mac_fix
        return stylesheet
项目:ConcretePy    作者:MarioRaul    | 项目源码 | 文件源码
def load_stylesheet_pyqt5():
    """
    Loads the stylesheet for use in a pyqt5 application.

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

    :return the stylesheet string
    """
    # Smart import of the images file
    import qdarkstyle.pyqt5_style_rc

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

    f = QFile(":darkBlue/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: #31363b;
                text-align: center;
                height: 12px;
            }
            '''
            stylesheet += mac_fix
        return stylesheet
项目:QQ_ucics    作者:hustdebug    | 项目源码 | 文件源码
def initSkin(self):
        skin = QFile("resources/themes/default.qss")
        if not skin.exists() or not skin.open(QFile.ReadOnly | QFile.Text):
            del skin
        else:
            qts = QTextStream(skin)
            qts.setCodec("UTF-8")
            data = qts.readAll()
            skin.close()
            del skin
            self.setStyleSheet(data)
项目:GazeboWorldDesigner    作者:barulicm    | 项目源码 | 文件源码
def load_stylesheet(pyside=True):
    """
    Loads the stylesheet. Takes care of importing the rc module.

    :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
    if pyside:
        import qdarkstyle.pyside_style_rc
    else:
        import qdarkstyle.pyqt_style_rc

    # Load the stylesheet content from resources
    if not pyside:
        from PyQt4.QtCore import QFile, QTextStream
    else:
        from PySide.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: #31363b;
                text-align: center;
                height: 12px;
            }
            '''
            stylesheet += mac_fix
        return stylesheet
项目:GazeboWorldDesigner    作者:barulicm    | 项目源码 | 文件源码
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 qdarkstyle.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: #31363b;
                text-align: center;
                height: 12px;
            }
            '''
            stylesheet += mac_fix
        return stylesheet
项目:Osdag    作者:osdag-admin    | 项目源码 | 文件源码
def save_file(self, fileName):
        """(file open for writing)-> boolean
        """
        fname = QFile(fileName)

        if not fname.open(QFile.WriteOnly | QFile.Text):
            QMessageBox.warning(self, "Application",
                                "Cannot write file %s:\n%s." % (fileName, fname.errorString()))
            return False

        outf = QTextStream(fname)
        QApplication.setOverrideCursor(Qt.WaitCursor)
        outf << self.ui.textEdit.toPlainText()
        QApplication.restoreOverrideCursor()
项目:Osdag    作者:osdag-admin    | 项目源码 | 文件源码
def save_file(self, fileName):
        '''(file open for writing)-> boolean
        '''
        fname = QFile(fileName)

        if not fname.open(QFile.WriteOnly | QFile.Text):
            QMessageBox.warning(self, "Application",
                                "Cannot write file %s:\n%s." % (fileName, fname.errorString()))
            return False

        outf = QTextStream(fname)
        QApplication.setOverrideCursor(Qt.WaitCursor)
        outf << self.ui.textEdit.toPlainText()
        QApplication.restoreOverrideCursor()
项目:Osdag    作者:osdag-admin    | 项目源码 | 文件源码
def save_file(self, filename):
        '''(file open for writing)-> boolean
        '''
        file_name = QFile(filename)

        if not file_name.open(QFile.WriteOnly | QFile.Text):
            return False

        outf = QTextStream(file_name)
        QApplication.setOverrideCursor(Qt.WaitCursor)
        outf << self.ui.textEdit.toPlainText()
        QApplication.restoreOverrideCursor()
项目:Osdag    作者:osdag-admin    | 项目源码 | 文件源码
def save_file(self, filename):
        '''(file open for writing)-> boolean
        '''
        fname = QFile(filename)

        if not fname.open(QFile.WriteOnly | QFile.Text):
            QMessageBox.warning(self, "Application",
                                      "Cannot write file %s:\n%s." % (filename, fname.errorString()))
            return False

        outf = QTextStream(fname)
        QApplication.setOverrideCursor(Qt.WaitCursor)
        outf << self.ui.textEdit.toPlainText()
        QApplication.restoreOverrideCursor()
项目:pyqt5-example    作者:guinslym    | 项目源码 | 文件源码
def open(self):
        fileName, _ = QFileDialog.getOpenFileName(self)
        if fileName:
            fd = QFile(fileName)
            if not fd.open(QIODevice.ReadOnly):
                QMessageBox.information(self, "Unable to open file",
                        fd.errorString())
                return

            output = QTextStream(fd).readAll()

            # Display contents.
            self.centralWidget.plainTextEdit.setPlainText(output)
            self.centralWidget.setBaseUrl(QUrl.fromLocalFile(fileName))
项目:pyqt5-example    作者:guinslym    | 项目源码 | 文件源码
def save(self):
        content = self.centralWidget.plainTextEdit.toPlainText()
        fileName, _ = QFileDialog.getSaveFileName(self)
        if fileName:
            fd = QFile(fileName)
            if not fd.open(QIODevice.WriteOnly):
                QMessageBox.information(self, "Unable to open file",
                        fd.errorString())
                return

            QTextStream(fd) << content
项目:pyqt5-example    作者:guinslym    | 项目源码 | 文件源码
def slotSourceDownloaded(self):
        reply = self.sender()
        self.textEdit = QTextEdit()
        self.textEdit.setAttribute(Qt.WA_DeleteOnClose)
        self.textEdit.show()
        self.textEdit.setPlainText(QTextStream(reply).readAll())
        self.textEdit.resize(600, 400)
        reply.deleteLater()
项目:pyqt5-example    作者:guinslym    | 项目源码 | 文件源码
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)
项目:pyqt5-example    作者:guinslym    | 项目源码 | 文件源码
def loadFile(self, fileName):
        file = QFile(fileName)
        if not file.open( QFile.ReadOnly | QFile.Text):
            QMessageBox.warning(self, "Recent Files",
                    "Cannot read file %s:\n%s." % (fileName, file.errorString()))
            return

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

        self.setCurrentFile(fileName)
        self.statusBar().showMessage("File loaded", 2000)
项目:pyqt5-example    作者:guinslym    | 项目源码 | 文件源码
def saveFile(self, fileName):
        file = QFile(fileName)
        if not file.open( QFile.WriteOnly | QFile.Text):
            QMessageBox.warning(self, "Recent Files",
                    "Cannot write file %s:\n%s." % (fileName, file.errorString()))
            return

        outstr = QTextStream(file)
        QApplication.setOverrideCursor(Qt.WaitCursor)
        outstr << self.textEdit.toPlainText()
        QApplication.restoreOverrideCursor()

        self.setCurrentFile(fileName)
        self.statusBar().showMessage("File saved", 2000)
项目:PyQt5_stylesheets    作者:RedFalsh    | 项目源码 | 文件源码
def load_stylesheet_pyqt5(**kwargs):
    """
    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

    if kwargs["style"] == "style_Dark":
        import PyQt5_stylesheets.pyqt5_style_Dark_rc
    if kwargs["style"] == "style_DarkOrange":
        import PyQt5_stylesheets.pyqt5_style_DarkOrange_rc
    if kwargs["style"] == "style_Classic":
        import PyQt5_stylesheets.pyqt5_style_Classic_rc

    if kwargs["style"] == "style_navy":
        import PyQt5_stylesheets.pyqt5_style_navy_rc

    if kwargs["style"] == "style_gray":
        import PyQt5_stylesheets.pyqt5_style_gray_rc

    if kwargs["style"] == "style_blue":
        import PyQt5_stylesheets.pyqt5_style_blue_rc

    if kwargs["style"] == "style_black":
        import PyQt5_stylesheets.pyqt5_style_black_rc
    # Load the stylesheet content from resources
    from PyQt5.QtCore import QFile, QTextStream

    f = QFile(":PyQt5_stylesheets/%s.qss"%kwargs["style"])
    if not f.exists():
        f = QFile(":PyQt5_stylesheets/%s.css"%kwargs["style"])
    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: #31363b;
                text-align: center;
                height: 12px;
            }
            '''
            stylesheet += mac_fix
        return stylesheet