Last active
July 19, 2017 10:45
-
-
Save ntoll/ef285cfaa4e1ff56e450f00009a46622 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
print('start') | |
for i in range(10): | |
print(i) | |
time.sleep(1) | |
print('stop') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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