|
6 | 6 | import threading |
7 | 7 | from pathlib import Path |
8 | 8 | from queue import Queue |
9 | | -from typing import TYPE_CHECKING |
| 9 | +from typing import TYPE_CHECKING, Union |
10 | 10 |
|
11 | 11 | from PySide6.QtCore import QTimer |
| 12 | +from PySide6.QtGui import QTextCharFormat |
12 | 13 | from PySide6.QtWidgets import QWidget |
13 | 14 | from je_editor.pyside_ui.main_ui.save_settings.user_color_setting_file import actually_color_dict |
14 | 15 | from je_editor.utils.venv_check.check_venv import check_and_choose_venv |
@@ -38,8 +39,8 @@ def __init__( |
38 | 39 | self._program_buffer_size = program_buffer |
39 | 40 | self._run_output_queue: Queue = Queue() |
40 | 41 | self._run_error_queue: Queue = Queue() |
41 | | - self._read_program_error_output_from_thread: [threading.Thread, None] = None |
42 | | - self._read_program_output_from_thread: [threading.Thread, None] = None |
| 42 | + self._read_program_error_output_from_thread: Union[threading.Thread, None] = None |
| 43 | + self._read_program_output_from_thread: Union[threading.Thread, None] = None |
43 | 44 | self._timer: QTimer = QTimer(self._code_window) |
44 | 45 | if self._main_window.python_compiler is None: |
45 | 46 | # Renew compiler path |
@@ -74,19 +75,24 @@ def __init__( |
74 | 75 | # Pyside UI update method |
75 | 76 | def pull_text(self): |
76 | 77 | try: |
77 | | - self._code_window.code_result.setTextColor(actually_color_dict.get("normal_output_color")) |
78 | 78 | if not self._run_output_queue.empty(): |
79 | 79 | output_message = self._run_output_queue.get_nowait() |
80 | 80 | output_message = str(output_message).strip() |
81 | 81 | if output_message: |
82 | | - self._code_window.code_result.append(output_message) |
83 | | - self._code_window.code_result.setTextColor(actually_color_dict.get("error_output_color")) |
| 82 | + text_cursor = self._code_window.code_result.textCursor() |
| 83 | + text_format = QTextCharFormat() |
| 84 | + text_format.setForeground(actually_color_dict.get("normal_output_color")) |
| 85 | + text_cursor.insertText(output_message, text_format) |
| 86 | + text_cursor.insertBlock() |
84 | 87 | if not self._run_error_queue.empty(): |
85 | 88 | error_message = self._run_error_queue.get_nowait() |
86 | 89 | error_message = str(error_message).strip() |
87 | 90 | if error_message: |
88 | | - self._code_window.code_result.append(error_message) |
89 | | - self._code_window.code_result.setTextColor(actually_color_dict.get("normal_output_color")) |
| 91 | + text_cursor = self._code_window.code_result.textCursor() |
| 92 | + text_format = QTextCharFormat() |
| 93 | + text_format.setForeground(actually_color_dict.get("error_output_color")) |
| 94 | + text_cursor.insertText(error_message, text_format) |
| 95 | + text_cursor.insertBlock() |
90 | 96 | except queue.Empty: |
91 | 97 | pass |
92 | 98 | if self._process is not None: |
@@ -115,7 +121,11 @@ def exit_program(self): |
115 | 121 | self.print_and_clear_queue() |
116 | 122 | if self._process is not None: |
117 | 123 | self._process.terminate() |
118 | | - self._code_window.code_result.append(f"Task exit with code {self._process.returncode}") |
| 124 | + text_cursor = self._code_window.code_result.textCursor() |
| 125 | + text_format = QTextCharFormat() |
| 126 | + text_format.setForeground(actually_color_dict.get("normal_output_color")) |
| 127 | + text_cursor.insertText(f"Task exit with code {self._process.returncode}", text_format) |
| 128 | + text_cursor.insertBlock() |
119 | 129 | self._process = None |
120 | 130 |
|
121 | 131 | def print_and_clear_queue(self): |
|
0 commit comments