Skip to content

Commit

Permalink
Merge pull request #68 from Integration-Automation/dev
Browse files Browse the repository at this point in the history
Fix color and encoding issue
  • Loading branch information
JE-Chen committed Sep 26, 2023
2 parents 0ab99b1 + f40bb36 commit 33490f3
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class CodeWindow(QWidget):
def __init__(self):
# UI used to show run code or shell command result.
super().__init__()
self.python_compiler = None
self.grid_layout = QGridLayout()
self.code_result = QTextEdit()
self.code_result.setLineWrapMode(self.code_result.LineWrapMode.NoWrap)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ def start_process(
if send_mail:
process = TaskProcessManager(
main_window=code_window,
program_buffer_size=program_buffer
program_buffer_size=program_buffer,
program_encoding=main_window.encoding
)
else:
process = TaskProcessManager(
code_window,
task_done_trigger_function=send_after_test,
program_buffer_size=program_buffer
program_buffer_size=program_buffer,
program_encoding=main_window.encoding
)
process.start_test_process(
package,
Expand Down
53 changes: 21 additions & 32 deletions automation_editor/extend/process_executor/task_process_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
from threading import Thread

from PySide6.QtCore import QTimer
from je_editor import user_setting_color_dict
from je_editor.pyside_ui.main_ui.save_settings.user_color_setting_file import actually_color_dict
from je_editor.utils.venv_check.check_venv import check_and_choose_venv

from automation_editor.automation_editor_ui.show_code_window.code_window import CodeWindow
from automation_editor.utils.exception.exception_tags import compiler_not_found_error
Expand All @@ -23,16 +24,18 @@ def __init__(
main_window: CodeWindow,
task_done_trigger_function: typing.Callable = None,
error_trigger_function: typing.Callable = None,
program_buffer_size: int = 1024000
program_buffer_size: int = 1024000,
program_encoding: str = "utf-8"
):
super().__init__()
self.compiler_path = None
# ite_instance param
self.read_program_error_output_from_thread: [threading.Thread, None] = None
self.read_program_output_from_thread: [threading.Thread, None] = None
self.main_window: CodeWindow = main_window
self.timer: QTimer = QTimer(self.main_window)
self.still_run_program: bool = True
self.program_encoding: str = "utf-8"
self.program_encoding: str = program_encoding
self.run_output_queue: Queue = Queue()
self.run_error_queue: Queue = Queue()
self.process: [subprocess.Popen, None] = None
Expand All @@ -41,36 +44,22 @@ def __init__(
self.error_trigger_function: typing.Callable = error_trigger_function
self.program_buffer_size = program_buffer_size

def start_test_process(self, package: str, exec_str: str):
# try to find file and compiler
if sys.platform in ["win32", "cygwin", "msys"]:
venv_path = Path(os.getcwd() + "/venv/Scripts")
else:
venv_path = Path(os.getcwd() + "/venv/bin")
if venv_path.is_dir() and venv_path.exists():
compiler_path = shutil.which(
cmd="python3",
path=str(venv_path)
)
else:
compiler_path = shutil.which(cmd="python3")
if compiler_path is None:
def renew_path(self) -> None:
if self.main_window.python_compiler is None:
# Renew compiler path
if sys.platform in ["win32", "cygwin", "msys"]:
venv_path = Path(os.getcwd() + "/venv/Scripts")
else:
venv_path = Path(os.getcwd() + "/venv/bin")
if venv_path.is_dir() and venv_path.exists():
compiler_path = shutil.which(
cmd="python",
path=str(venv_path)
)
venv_path = Path(str(Path.cwd()) + "/venv/Scripts")
else:
compiler_path = shutil.which(cmd="python")
if compiler_path is None:
raise ITEExecException(compiler_not_found_error)
venv_path = Path(str(Path.cwd()) + "/venv/bin")
self.compiler_path = check_and_choose_venv(venv_path)
else:
self.compiler_path = self.main_window.python_compiler

def start_test_process(self, package: str, exec_str: str):
self.renew_path()
self.process = subprocess.Popen(
[
compiler_path,
self.compiler_path,
"-m",
package,
"--execute_str",
Expand Down Expand Up @@ -105,19 +94,19 @@ def start_test_process(self, package: str, exec_str: str):
# Pyside UI update method
def pull_text(self):
try:
self.main_window.code_result.setTextColor(user_setting_color_dict.get("normal_output_color"))
self.main_window.code_result.setTextColor(actually_color_dict.get("normal_output_color"))
if not self.run_output_queue.empty():
output_message = self.run_output_queue.get_nowait()
output_message = str(output_message).strip()
if output_message:
self.main_window.code_result.append(output_message)
self.main_window.code_result.setTextColor(user_setting_color_dict.get("error_output_color"))
self.main_window.code_result.setTextColor(actually_color_dict.get("error_output_color"))
if not self.run_error_queue.empty():
error_message = self.run_error_queue.get_nowait()
error_message = str(error_message).strip()
if error_message:
self.main_window.code_result.append(error_message)
self.main_window.code_result.setTextColor(user_setting_color_dict.get("normal_output_color"))
self.main_window.code_result.setTextColor(actually_color_dict.get("normal_output_color"))
except queue.Empty:
pass
if self.process is not None:
Expand Down
Loading

0 comments on commit 33490f3

Please sign in to comment.