PyQT Read And Update TextEdit From .txt File
Here is what I am trying to do: 1) I am storing 10 posts at a time using the Twitter API to stream posts. They are being stored into a text file called lrgDict.txt import tweepy,da
Solution 1:
You basically need to implement signals and slots and I made a example to show this, but example is based on your logic but not with twiter api
from PyQt4 import QtGui, QtCore
import sys
class FetchData(QtCore.QObject):
fetchFinished = QtCore.pyqtSignal(str)
def __init__(self, *args):
super(FetchData, self).__init__(*args)
@QtCore.pyqtSlot()
def run(self, searchStr):
rtString = "Some data from no where : %s" % searchStr
self.fetchFinished.emit(str(rtString))
class BASEGUICLS(QtGui.QDialog):
def __init__(self,parent=None):
super(BASEGUICLS, self).__init__(parent)
self.verticalLayout = QtGui.QVBoxLayout()
self.searchString = QtGui.QLineEdit()
self.resultsText = QtGui.QPlainTextEdit()
self.fetchButton = QtGui.QPushButton("Fetch")
self.stopButton = QtGui.QPushButton("Stop")
self.verticalLayout.addWidget(self.searchString)
self.verticalLayout.addWidget(self.resultsText)
self.verticalLayout.addWidget(self.fetchButton)
self.verticalLayout.addWidget(self.stopButton)
self.setLayout(self.verticalLayout)
self.fetchData = FetchData()
self.fetchData.fetchFinished.connect(self.updateResult)
self.fetchButton.clicked.connect(self.getData)
self.stopButton.clicked.connect(self.stopFetch)
self.timer = QtCore.QTimer(self)
self.timer.timeout.connect(self.refreshResult)
def getData(self):
self.timer.start(500)
def refreshResult(self):
searchStr = str(self.searchString.text())
if not searchStr:
self.stopFetch()
raise RuntimeError("Missing Search String")
self.fetchData.run(searchStr)
def stopFetch(self):
self.timer.stop()
def updateResult(self, value):
self.resultsText.appendPlainText(value)
def main():
app = QtGui.QApplication(sys.argv)
ex = BASEGUICLS(None)
ex.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main()
Post a Comment for "PyQT Read And Update TextEdit From .txt File"