Skip to content

Instantly share code, notes, and snippets.

@ntoll
Last active July 19, 2017 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ntoll/ef285cfaa4e1ff56e450f00009a46622 to your computer and use it in GitHub Desktop.
Save ntoll/ef285cfaa4e1ff56e450f00009a46622 to your computer and use it in GitHub Desktop.
import time
print('start')
for i in range(10):
print(i)
time.sleep(1)
print('stop')
class PythonProcessPane(QTextEdit):
"""
Captures, displays and works with the stdin, stdout and stderr of a Python
process.
Used for running standard Python3 scripts.
"""
def start_process(self, script):
self.script = script
logger.info('Running script: {}'.format(script))
self.process = QProcess(self)
self.process.readyRead.connect(self.read)
self.process.start('python3', [script])
def append(self, byte_stream):
"""
Append text to the text area.
"""
cursor = self.textCursor()
cursor.movePosition(cursor.End)
cursor.insertText(byte_stream.data().decode('utf-8'))
def read(self):
"""
From the process's stdout.
"""
self.append(self.process.readAll())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment