I have 3 classes
One is the Console
class:
class Console(QWidget):
def __init__(self):
super().__init__()
self.editor = QPlainTextEdit(self)
self.editor.setReadOnly(True)
self.font = QFont()
self.font.setFamily(editor["editorFont"])
self.font.setPointSize(12)
self.layout = QVBoxLayout()
self.layout.addWidget(self.editor, 1)
self.setLayout(self.layout)
self.output = None
self.error = None
self.editor.setFont(self.font)
def run(self, command):
"""Executes a system command."""
out, err = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
self.output = out
self.error = err
self.editor.setPlainText((self.output + self.error).decode())
return self.output + self.error
The other one is a Tabs
class which assigns Console()
to the variable self.console
.
And then I have the Main
class which has a function called Terminal
which can be called by a keyboard shortcut Shift+F10
That will take the current filename of the file opened (this is handled with the Tabs
class) and run it using subprocess
.
Now we get to the problem: when running some programs that aren't instant, the whole GUI freezes and I can't figure out how to make the GUI responsive when the Console
class has executed the run
function.
The whole code can be found here: https://github.com/Fuchsiaff/PyPad