Skip to content

Instantly share code, notes, and snippets.

@JerzySpendel
Created January 11, 2013 15:51
Show Gist options
  • Save JerzySpendel/4511702 to your computer and use it in GitHub Desktop.
Save JerzySpendel/4511702 to your computer and use it in GitHub Desktop.
import sys
import subprocess
import threading
import time
import io
from PyQt4 import QtCore,QtGui
import gui
import re
class MyForm(QtGui.QMainWindow):
def __init__(self,parent=None):
QtGui.QWidget.__init__(self,parent)
self.ui = gui.Ui_MainWindow()
self.ui.setupUi(self)
QtCore.QObject.connect(self.ui.pushButton,QtCore.SIGNAL('clicked()'),self.download)
def test(self):
print(self.ui.lineEdit.text())
def download(self):
f = open('output','w')
p = subprocess.Popen(['python','./__main__.py',self.ui.lineEdit.text()],shell=False,stdin=subprocess.PIPE,stderr=f, stdout=f,bufsize=-1)
t = Reader(self)
t.start()
class Reader(threading.Thread):
def __init__(self,MyForm):
threading.Thread.__init__(self)
self.fil = open('output','r')
self.var = 2
self.form = MyForm
self.percent =
def get_last_line(self):
a = self.fil.readlines()
return a[len(a)-1]
def run(self):
while True:
try:
time.sleep(0.2)
self.var = self.get_last_line()
print(self.var)
self.form.ui.label_3.setText(self.var)
except IndexError:
print("No new informations, waiting 0.1 sec. more")
time.sleep(0.1)
app = QtGui.QApplication(sys.argv)
g = MyForm()
g.show()
sys.exit(app.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment