|
3 | 3 |
|
4 | 4 | """ Module for the base OCB Code Block. """ |
5 | 5 |
|
6 | | - |
7 | | -from PyQt5.QtCore import QCoreApplication, QByteArray |
| 6 | +from PyQt5.QtCore import QByteArray |
8 | 7 | from PyQt5.QtGui import QPixmap |
9 | 8 | from PyQt5.QtWidgets import QPushButton, QTextEdit |
10 | 9 |
|
11 | 10 | from ansi2html import Ansi2HTMLConverter |
12 | 11 |
|
13 | 12 | from opencodeblocks.graphics.blocks.block import OCBBlock |
14 | 13 | from opencodeblocks.graphics.pyeditor import PythonEditor |
| 14 | +from opencodeblocks.graphics.worker import Worker |
15 | 15 |
|
16 | 16 | conv = Ansi2HTMLConverter() |
17 | 17 |
|
@@ -144,19 +144,17 @@ def init_run_button(self): |
144 | 144 | def run_code(self): |
145 | 145 | """Run the code in the block""" |
146 | 146 | code = self.source_editor.text() |
147 | | - kernel = self.source_editor.kernel |
148 | 147 | self.source = code |
149 | | - # Execute the code |
150 | | - kernel.client.execute(code) |
151 | | - done = False |
152 | | - # While the kernel sends messages |
153 | | - while done is False: |
154 | | - # Keep the GUI alive |
155 | | - QCoreApplication.processEvents() |
156 | | - # Save kernel message and display it |
157 | | - output, output_type, done = kernel.update_output() |
158 | | - if done is False: |
159 | | - if output_type == 'text': |
160 | | - self.stdout = output |
161 | | - elif output_type == 'image': |
162 | | - self.image = output |
| 148 | + # Create a worker to handle execution |
| 149 | + worker = Worker(self.source_editor.kernel, self.source) |
| 150 | + worker.signals.stdout.connect(self.handle_stdout) |
| 151 | + worker.signals.image.connect(self.handle_image) |
| 152 | + self.source_editor.threadpool.start(worker) |
| 153 | + |
| 154 | + def handle_stdout(self, stdout): |
| 155 | + """ Handle the stdout signal """ |
| 156 | + self.stdout = stdout |
| 157 | + |
| 158 | + def handle_image(self, image): |
| 159 | + """ Handle the image signal """ |
| 160 | + self.image = image |
0 commit comments