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


Python QTextStream.flush方法代码示例

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


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

示例1: save

# 需要导入模块: from PyQt4.QtCore import QTextStream [as 别名]
# 或者: from PyQt4.QtCore.QTextStream import flush [as 别名]
 def save(self):
     fileName = QFileDialog.getSaveFileName(self, caption='Save As...')
     try:
         file = QFile(fileName + '.txt')
         file.open(QIODevice.WriteOnly | QIODevice.Text)
         out = QTextStream(file)
         out << self.plainTextEdit.toPlainText()
         out.flush()
         file.close()
         self.close()
         return True
     except IOError:
         return False
开发者ID:solymosin,项目名称:maps2winbugs,代码行数:15,代码来源:exp2BUGS.py

示例2: exportDocument

# 需要导入模块: from PyQt4.QtCore import QTextStream [as 别名]
# 或者: from PyQt4.QtCore.QTextStream import flush [as 别名]
    def exportDocument(self, task, fileName, format):
        """

        :type task: QUrl
        :type fileName: str
        :type format: self.ExportFormat
        :return: bool
        """
        fileOut = QFile(fileName)

        if not fileOut.open(QIODevice.WriteOnly | QIODevice.Text):
            return False

        taskMap = self.__parseTask(task)
        text = self.__documentContent(taskMap, format)
        streamFileOut = QTextStream(fileOut)
        streamFileOut.setCodec("UTF-8")
        streamFileOut << text
        streamFileOut.flush()

        fileOut.close()

        return True
开发者ID:ctu-osgeorel,项目名称:qgis-vfk-plugin,代码行数:25,代码来源:vfkTextBrowser.py

示例3: LogsReadThread

# 需要导入模块: from PyQt4.QtCore import QTextStream [as 别名]
# 或者: from PyQt4.QtCore.QTextStream import flush [as 别名]
class LogsReadThread(QThread):
    MAX_INITIAL_SIZE = 2*1024*1024 # 2Mb

    def __init__(self, parent):
        QThread.__init__(self, parent)

        self.fCloseNow   = False
        self.fPurgeLogs  = False
        self.fRealParent = parent

        # -------------------------------------------------------------
        # Take some values from Logs Window

        self.LOG_FILE_JACK   = LogsW.LOG_FILE_JACK
        self.LOG_FILE_A2J    = LogsW.LOG_FILE_A2J
        self.LOG_FILE_LASH   = LogsW.LOG_FILE_LASH
        self.LOG_FILE_LADISH = LogsW.LOG_FILE_LADISH

        # -------------------------------------------------------------
        # Init logs

        if self.LOG_FILE_JACK is not None:
            self.fLogFileJACK = QFile(self.LOG_FILE_JACK)
            self.fLogFileJACK.open(QIODevice.ReadOnly)
            self.fLogStreamJACK = QTextStream(self.fLogFileJACK)
            self.fLogStreamJACK.setCodec("UTF-8")

            if self.fLogFileJACK.size() > self.MAX_INITIAL_SIZE:
                self.fLogStreamJACK.seek(self.fLogFileJACK.size() - self.MAX_INITIAL_SIZE)

        if self.LOG_FILE_A2J is not None:
            self.fLogFileA2J = QFile(self.LOG_FILE_A2J)
            self.fLogFileA2J.open(QIODevice.ReadOnly)
            self.fLogStreamA2J = QTextStream(self.fLogFileA2J)
            self.fLogStreamA2J.setCodec("UTF-8")

            if self.fLogFileA2J.size() > self.MAX_INITIAL_SIZE:
                self.fLogStreamA2J.seek(self.fLogFileA2J.size() - self.MAX_INITIAL_SIZE)

        if self.LOG_FILE_LASH is not None:
            self.fLogFileLASH = QFile(self.LOG_FILE_LASH)
            self.fLogFileLASH.open(QIODevice.ReadOnly)
            self.fLogStreamLASH = QTextStream(self.fLogFileLASH)
            self.fLogStreamLASH.setCodec("UTF-8")

            if self.fLogFileLASH.size() > self.MAX_INITIAL_SIZE:
                self.fLogStreamLASH.seek(self.fLogFileLASH.size() - self.MAX_INITIAL_SIZE)

        if self.LOG_FILE_LADISH is not None:
            self.fLogFileLADISH = QFile(self.LOG_FILE_LADISH)
            self.fLogFileLADISH.open(QIODevice.ReadOnly)
            self.fLogStreamLADISH = QTextStream(self.fLogFileLADISH)
            self.fLogStreamLADISH.setCodec("UTF-8")

            if self.fLogFileLADISH.size() > self.MAX_INITIAL_SIZE:
                self.fLogStreamLADISH.seek(self.fLogFileLADISH.size() - self.MAX_INITIAL_SIZE)

    def closeNow(self):
        self.fCloseNow = True

    def purgeLogs(self):
        self.fPurgeLogs = True

    def run(self):
        # -------------------------------------------------------------
        # Read logs and set text in main thread

        while not self.fCloseNow:
            if self.fPurgeLogs:
                if self.LOG_FILE_JACK:
                    self.fLogStreamJACK.flush()
                    self.fLogFileJACK.close()
                    self.fLogFileJACK.open(QIODevice.WriteOnly)
                    self.fLogFileJACK.close()
                    self.fLogFileJACK.open(QIODevice.ReadOnly)

                if self.LOG_FILE_A2J:
                    self.fLogStreamA2J.flush()
                    self.fLogFileA2J.close()
                    self.fLogFileA2J.open(QIODevice.WriteOnly)
                    self.fLogFileA2J.close()
                    self.fLogFileA2J.open(QIODevice.ReadOnly)

                if self.LOG_FILE_LASH:
                    self.fLogStreamLASH.flush()
                    self.fLogFileLASH.close()
                    self.fLogFileLASH.open(QIODevice.WriteOnly)
                    self.fLogFileLASH.close()
                    self.fLogFileLASH.open(QIODevice.ReadOnly)

                if self.LOG_FILE_LADISH:
                    self.fLogStreamLADISH.flush()
                    self.fLogFileLADISH.close()
                    self.fLogFileLADISH.open(QIODevice.WriteOnly)
                    self.fLogFileLADISH.close()
                    self.fLogFileLADISH.open(QIODevice.ReadOnly)

                self.fPurgeLogs = False

            else:
#.........这里部分代码省略.........
开发者ID:ViktorNova,项目名称:Cadence,代码行数:103,代码来源:logs.py

示例4: accept

# 需要导入模块: from PyQt4.QtCore import QTextStream [as 别名]
# 或者: from PyQt4.QtCore.QTextStream import flush [as 别名]
 def accept(self):
     self.buttonOk.setEnabled(False)
     if self.inShape.currentText() == "":
         QMessageBox.information(self, self.tr("Define current projection"), self.tr("No input shapefile specified"))
     elif self.txtProjection.text() == "" and self.rdoProjection.isChecked():
         QMessageBox.information(self, self.tr("Define current projection"), self.tr("Please specify spatial reference system"))
     elif self.cmbLayer.currentText() == "" and self.rdoLayer.isChecked():
         QMessageBox.information(self, self.tr("Define current projection"), self.tr("Please specify spatial reference system"))
     else:
         self.progressBar.setValue(5)
         inName = self.inShape.currentText()
         self.progressBar.setValue(10)
         vLayer = ftools_utils.getVectorLayerByName(inName)
         self.progressBar.setValue(30)
         if vLayer == "Error":
             QMessageBox.information(self, self.tr("Define current projection"), self.tr("Cannot define projection for PostGIS data...yet!"))
         else:
             srsDefine = None
             if self.rdoProjection.isChecked():
                 srsDefine = self.crs
             else:
                 destLayer = ftools_utils.getVectorLayerByName(self.cmbLayer.currentText())
                 srsDefine = destLayer.crs()
             if srsDefine == vLayer.crs():
                 responce = QMessageBox.question(self, self.tr("Define current projection"),
                                                 self.tr("Identical output spatial reference system chosen\n\nAre you sure you want to proceed?"),
                                                 QMessageBox.Yes, QMessageBox.No, QMessageBox.NoButton)
                 if responce == QMessageBox.No:
                     self.progressBar.setValue(0)
                     self.buttonOk.setEnabled(True)
                     return
             provider = vLayer.dataProvider()
             self.progressBar.setValue(35)
             inPath = provider.dataSourceUri()
             p = re.compile("\|.*")
             inPath = p.sub("", inPath)
             self.progressBar.setValue(40)
             if inPath.endswith(".shp"):
                 inPath = inPath[:-4]
             self.progressBar.setValue(55)
             if not srsDefine.isValid():
                 QMessageBox.information(self, self.tr("Define current projection"), self.tr("Output spatial reference system is not valid"))
             else:
                 self.progressBar.setValue(60)
                 outputWkt = srsDefine.toWkt()
                 self.progressBar.setValue(65)
                 outputFile = QFile(inPath + ".prj")
                 outputFile.open(QIODevice.WriteOnly | QIODevice.Text)
                 outputPrj = QTextStream(outputFile)
                 outputPrj << outputWkt
                 outputPrj.flush()
                 outputFile.close()
                 self.progressBar.setValue(70)
                 checkFile = QFile(inPath + ".qpj")
                 if checkFile.exists():
                     checkFile.open(QIODevice.WriteOnly | QIODevice.Text)
                     outputPrj = QTextStream(checkFile)
                     outputPrj << outputWkt
                     outputPrj.flush()
                     checkFile.close()
                 self.progressBar.setValue(95)
                 vLayer.setCrs(srsDefine)
                 self.progressBar.setValue(100)
                 QMessageBox.information(self, self.tr("Define current projection"),
                                         self.tr("Defined Projection For:\n%s.shp") % (inPath))
     self.progressBar.setValue(0)
     self.buttonOk.setEnabled(True)
开发者ID:Geoneer,项目名称:QGIS,代码行数:69,代码来源:doDefineProj.py

示例5: QLocalSocket

# 需要导入模块: from PyQt4.QtCore import QTextStream [as 别名]
# 或者: from PyQt4.QtCore.QTextStream import flush [as 别名]
#coding=utf-8

from time import sleep
from PyQt4.QtCore import QTextStream,QString
from PyQt4.QtNetwork import QLocalSocket
import random
import os

if __name__ == "__main__":

    pid = os.getpid()
    ls = QLocalSocket()
    ls.connectToServer("localserver-test")
    if ls.waitForConnected():
        print "连接成功"
        while True:
            try:
                ts = QTextStream(ls)
                ts << QString.number(random.randrange(1000)) + "\nTTTTTTTTTT" + "\n PID = " + QString.number(pid) + "\n"
                ts.flush()
                print "werite :", ls.waitForBytesWritten()
                print pid
                sleep(1)
            except Exception as e:
                print e.message

开发者ID:github-jxm,项目名称:QtCrearor_fast_learn,代码行数:27,代码来源:main.py

示例6: QtSingleApplication

# 需要导入模块: from PyQt4.QtCore import QTextStream [as 别名]
# 或者: from PyQt4.QtCore.QTextStream import flush [as 别名]
class QtSingleApplication(QApplication):

    messageReceived = pyqtSignal(unicode)

    def __init__(self, id, *argv):

        super(QtSingleApplication, self).__init__(*argv)
        self._id = id
        self._activationWindow = None
        self._activateOnMessage = False

        # Is there another instance running?
        self._outSocket = QLocalSocket()
        self._outSocket.connectToServer(self._id)
        self._isRunning = self._outSocket.waitForConnected()

        if self._isRunning:
            # Yes, there is.
            self._outStream = QTextStream(self._outSocket)
            self._outStream.setCodec('UTF-8')
        else:
            # No, there isn't.
            self._outSocket = None
            self._outStream = None
            self._inSocket = None
            self._inStream = None
            self._server = QLocalServer()
            self._server.listen(self._id)
            self._server.newConnection.connect(self._onNewConnection)

    def isRunning(self):
        return self._isRunning

    def id(self):
        return self._id

    def activationWindow(self):
        return self._activationWindow

    def setActivationWindow(self, activationWindow, activateOnMessage = True):
        self._activationWindow = activationWindow
        self._activateOnMessage = activateOnMessage

    def activateWindow(self):
        if not self._activationWindow:
            return
        self._activationWindow.setWindowState(
            self._activationWindow.windowState() & ~Qt.WindowMinimized)
        self._activationWindow.raise_()
        self._activationWindow.activateWindow()

    def sendMessage(self, msg):
        if not self._outStream:
            return False
        self._outStream << msg << '\n'
        self._outStream.flush()
        return self._outSocket.waitForBytesWritten()

    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._inStream.setCodec('UTF-8')
        self._inSocket.readyRead.connect(self._onReadyRead)
        if self._activateOnMessage:
            self.activateWindow()

    def _onReadyRead(self):
        while True:
            msg = self._inStream.readLine()
            if not msg: break
            self.messageReceived.emit(msg)
开发者ID:vioelsdm,项目名称:pyPlanner,代码行数:77,代码来源:qtsingleapplication.py


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