Skip to content

Commit

Permalink
Merge pull request #131 from Integration-Automation/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
JE-Chen45 authored Sep 19, 2023
2 parents 9eecc89 + 47705ce commit 6682d58
Show file tree
Hide file tree
Showing 18 changed files with 205 additions and 65 deletions.
3 changes: 3 additions & 0 deletions .idea/je_editor.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions exe/auto_py_to_exe.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@
{
"optionDest": "pathex",
"value": "C:/CodeWorkspace/je_editor/venv"
},
{
"optionDest": "datas",
"value": "C:/CodeWorkspace/je_editor/venv/Lib/site-packages/yapf_third_party;yapf_third_party/"
}
],
"nonPyinstallerOptions": {
Expand Down
3 changes: 3 additions & 0 deletions exe/user_setting.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"language": "Traditional_Chinese"
}
16 changes: 14 additions & 2 deletions je_editor/pyside_ui/code/code_process/code_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ def later_init(self) -> None:
else:
raise JEditorException(je_editor_init_error)

def exec_code(self, exec_file_name) -> None:
def exec_code(self, exec_file_name, exec_prefix: Union[str, list] = None) -> None:
"""
:param exec_file_name: string file will open to run
:param exec_prefix: user define exec prefix
:return: if error return result and True else return result and False
"""
try:
Expand All @@ -81,11 +82,22 @@ def exec_code(self, exec_file_name) -> None:
# detect file is exist
exec_file = reformat_os_file_path
# run program
execute_program_list = [self.compiler_path, exec_file]
if exec_prefix is None:
execute_program_list = [self.compiler_path, exec_file]
else:
if isinstance(exec_prefix, str):
execute_program_list = [self.compiler_path, exec_prefix, exec_file]
else:
execute_program_list = list()
execute_program_list.append(self.compiler_path)
for prefix in exec_prefix:
execute_program_list.append(prefix)
execute_program_list.append(exec_file)
self.process = subprocess.Popen(
execute_program_list,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=subprocess.PIPE,
shell=True
)
self.still_run_program = True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def __init__(self):
self.search_action.triggered.connect(
self.start_search_dialog
)
# Add actions
self.addAction(self.search_action)
# Complete
self.completer: Union[None, QCompleter] = None
Expand All @@ -68,7 +69,7 @@ def check_env(self):
if path.exists():
self.env = jedi.create_environment(str(path))
except Exception as error:
pass
error.with_traceback()

def set_complete(self, list_to_complete: list) -> None:
"""
Expand Down Expand Up @@ -121,7 +122,8 @@ def complete(self) -> None:
script = jedi.Script(code=self.toPlainText(), environment=self.env)
else:
script = jedi.Script(code=self.toPlainText())
jedi_complete_list: List[Completion] = script.complete()
jedi_complete_list: List[Completion] = script.complete(
self.textCursor().blockNumber() + 1, self.textCursor().positionInBlock())
if len(jedi_complete_list) > 0:
new_complete_list = list()
for complete_text in jedi_complete_list:
Expand Down Expand Up @@ -155,7 +157,7 @@ def find_next_text(self) -> None:
:return: None
"""
if self.search_box.isVisible():
text = self.search_box.search_input.text()
text = self.search_box.command_input.text()
self.find(text)

def find_back_text(self) -> None:
Expand All @@ -164,7 +166,7 @@ def find_back_text(self) -> None:
:return: None
"""
if self.search_box.isVisible():
text = self.search_box.search_input.text()
text = self.search_box.command_input.text()
self.find(text, QTextDocument.FindFlag.FindBackward)

def line_number_paint(self, event) -> None:
Expand Down Expand Up @@ -254,9 +256,7 @@ def keyPressEvent(self, event: QKeyEvent) -> None:
:param event: keypress event
:return: None
"""
if event.modifiers() and Qt.Modifier.CTRL:
super().keyPressEvent(event)
return
# Catch soft wrap shift + return (line nuber not working on soft warp)
if self.completer.popup().isVisible() and event.key() in self.skip_popup_behavior_list:
self.completer.popup().close()
event.ignore()
Expand All @@ -265,10 +265,8 @@ def keyPressEvent(self, event: QKeyEvent) -> None:
key = event.key()
if key == Qt.Key.Key_Enter or key == Qt.Key.Key_Return:
event.ignore()
else:
super().keyPressEvent(event)
else:
super().keyPressEvent(event)
return
super().keyPressEvent(event)
self.highlight_current_line()
if event.key() in self.need_complete_list and self.completer is not None:
if self.completer.popup().isVisible():
Expand Down
1 change: 1 addition & 0 deletions je_editor/pyside_ui/code/running_process_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def close_all_instance(self):
manager.process.terminate()
manager.main_window.exec_program = None
manager.main_window.exec_shell = None
manager.main_window.exec_python_debugger = None


run_instance_manager = RunInstanceManager()
21 changes: 11 additions & 10 deletions je_editor/pyside_ui/dialog/file_dialog/open_file_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@ def choose_file_get_open_file_path(parent_qt_instance: EditorMain) -> None:

def choose_dir_get_dir_path(parent_qt_instance: EditorMain) -> None:
dir_path = QFileDialog().getExistingDirectory(parent=parent_qt_instance,)
check_path = Path(dir_path)
if check_path.exists() and check_path.is_dir():
parent_qt_instance.working_dir = dir_path
for code_editor in range(parent_qt_instance.tab_widget.count()):
widget = parent_qt_instance.tab_widget.widget(code_editor)
if isinstance(widget, EditorWidget):
widget.project_treeview.setRootIndex(widget.project_treeview_model.index(dir_path))
widget.code_edit.check_env()
os.chdir(dir_path)
parent_qt_instance.startup_setting()
if dir_path != "":
check_path = Path(dir_path)
if check_path.exists() and check_path.is_dir():
parent_qt_instance.working_dir = dir_path
for code_editor in range(parent_qt_instance.tab_widget.count()):
widget = parent_qt_instance.tab_widget.widget(code_editor)
if isinstance(widget, EditorWidget):
widget.project_treeview.setRootIndex(widget.project_treeview_model.index(dir_path))
widget.code_edit.check_env()
os.chdir(dir_path)
parent_qt_instance.startup_setting()

37 changes: 37 additions & 0 deletions je_editor/pyside_ui/main_ui/editor/debugger_input.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from __future__ import annotations

from typing import TYPE_CHECKING

from PySide6.QtWidgets import QWidget, QLineEdit, QBoxLayout, QPushButton, QHBoxLayout

if TYPE_CHECKING:
from je_editor.pyside_ui.main_ui.main_editor import EditorWidget

from je_editor.utils.multi_language.multi_language_wrapper import language_wrapper


class DebuggerInput(QWidget):

def __init__(self, main_window: EditorWidget):
super().__init__()
self.main_window = main_window
self.main_window.code_difference_result.setCurrentWidget(self.main_window.debugger_result)
self.box_layout = QBoxLayout(QBoxLayout.Direction.TopToBottom)
self.command_input = QLineEdit()
self.send_command_button = QPushButton()
self.send_command_button.setText(language_wrapper.language_word_dict.get("debugger_input_send_command"))
self.send_command_button.clicked.connect(self.send_command)
self.box_h_layout = QHBoxLayout()
self.box_h_layout.addWidget(self.send_command_button)
self.box_layout.addWidget(self.command_input)
self.box_layout.addLayout(self.box_h_layout)
self.setWindowTitle(language_wrapper.language_word_dict.get("editor_debugger"))
self.setLayout(self.box_layout)

def send_command(self):
if self.main_window.exec_python_debugger is not None:
process_stdin = self.main_window.exec_python_debugger.process.stdin
if process_stdin is not None:
process_stdin.write(self.command_input.text().encode() + b"\n")
process_stdin.flush()

5 changes: 5 additions & 0 deletions je_editor/pyside_ui/main_ui/editor/editor_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def __init__(self, main_window: EditorMain):
# Current execute instance if none not running
self.exec_program: Union[None, ExecManager] = None
self.exec_shell: Union[None, ShellManager] = None
self.exec_python_debugger: Union[None, ExecManager] = None
# Autosave
self.code_save_thread: Union[CodeEditSaveThread, None] = None
# UI
Expand Down Expand Up @@ -70,12 +71,16 @@ def __init__(self, main_window: EditorMain):
# Code format checker
self.format_check_result = CodeRecord()
self.format_check_result.setTextColor(actually_color_dict.get("warning_output_color"))
# Debugger
self.debugger_result = CodeRecord()
# Code result tab
self.code_difference_result = QTabWidget()
self.code_difference_result.addTab(
self.code_result_scroll_area, language_wrapper.language_word_dict.get("editor_code_result"))
self.code_difference_result.addTab(
self.format_check_result, language_wrapper.language_word_dict.get("editor_format_check"))
self.code_difference_result.addTab(
self.debugger_result, language_wrapper.language_word_dict.get("editor_debugger"))
# Edit splitter
self.edit_splitter.addWidget(self.code_edit_scroll_area)
self.edit_splitter.addWidget(self.code_difference_result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from typing import TYPE_CHECKING

import black

from je_editor.pyside_ui.main_ui.editor.editor_widget import EditorWidget
from je_editor.utils.multi_language.multi_language_wrapper import language_wrapper

Expand All @@ -17,16 +19,27 @@ def set_check_menu(ui_we_want_to_set: EditorMain) -> None:
ui_we_want_to_set.check_menu = ui_we_want_to_set.menu.addMenu(
language_wrapper.language_word_dict.get("check_code_style_menu_label"))
# Yapf code check
ui_we_want_to_set.check_menu.check_python_action = QAction(
ui_we_want_to_set.check_menu.yapf_check_python_action = QAction(
language_wrapper.language_word_dict.get("yapf_reformat_label"))
ui_we_want_to_set.check_menu.check_python_action.setShortcut(
ui_we_want_to_set.check_menu.yapf_check_python_action.setShortcut(
QKeySequence("Ctrl+Shift+Y"))
ui_we_want_to_set.check_menu.check_python_action.triggered.connect(
lambda: check_python_code(
ui_we_want_to_set.check_menu.yapf_check_python_action.triggered.connect(
lambda: yapf_check_python_code(
ui_we_want_to_set
)
)
ui_we_want_to_set.check_menu.addAction(ui_we_want_to_set.check_menu.check_python_action)
ui_we_want_to_set.check_menu.addAction(ui_we_want_to_set.check_menu.yapf_check_python_action)
# Black code check
ui_we_want_to_set.check_menu.black_check_python_action = QAction(
language_wrapper.language_word_dict.get("black_reformat_label"))
ui_we_want_to_set.check_menu.black_check_python_action.setShortcut(
QKeySequence("Ctrl+Shift+L"))
ui_we_want_to_set.check_menu.black_check_python_action.triggered.connect(
lambda: black_check_python_code(
ui_we_want_to_set
)
)
ui_we_want_to_set.check_menu.addAction(ui_we_want_to_set.check_menu.black_check_python_action)
# Reformat JSON
ui_we_want_to_set.check_menu.reformat_json_action = QAction(
language_wrapper.language_word_dict.get("reformat_json_label"))
Expand All @@ -39,7 +52,7 @@ def set_check_menu(ui_we_want_to_set: EditorMain) -> None:
ui_we_want_to_set.check_menu.addAction(ui_we_want_to_set.check_menu.reformat_json_action)


def check_python_code(ui_we_want_to_set: EditorMain) -> None:
def yapf_check_python_code(ui_we_want_to_set: EditorMain) -> None:
widget = ui_we_want_to_set.tab_widget.currentWidget()
if isinstance(widget, EditorWidget):
code_text = widget.code_edit.toPlainText()
Expand All @@ -53,6 +66,13 @@ def check_python_code(ui_we_want_to_set: EditorMain) -> None:
widget.code_edit.setPlainText(format_code[0])


def black_check_python_code(ui_we_want_to_set: EditorMain) -> None:
widget = ui_we_want_to_set.tab_widget.currentWidget()
if isinstance(widget, EditorWidget):
code_text = widget.code_edit.toPlainText()
widget.code_edit.setPlainText(black.format_str(code_text, mode=black.Mode()))


def reformat_json_text(ui_we_want_to_set: EditorMain) -> None:
widget = ui_we_want_to_set.tab_widget.currentWidget()
if isinstance(widget, EditorWidget):
Expand Down
8 changes: 5 additions & 3 deletions je_editor/pyside_ui/main_ui/menu/help_menu/build_help_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@ def set_help_menu(ui_we_want_to_set: EditorMain) -> None:
ui_we_want_to_set.help_menu.help_github_action.triggered.connect(
lambda: open_web_browser(
ui_we_want_to_set,
"https://github.com/Integrated-Testing-Environment/je_editor", "GitHub")
"https://github.com/Integrated-Testing-Environment/je_editor",
language_wrapper.language_word_dict.get("help_menu_open_github_label"))
)
ui_we_want_to_set.help_menu.addAction(ui_we_want_to_set.help_menu.help_github_action)

ui_we_want_to_set.help_menu.help_doc_action = QAction(
language_wrapper.language_word_dict.get("help_menu_open_about_label"))
language_wrapper.language_word_dict.get("help_menu_open_doc_label"))
ui_we_want_to_set.help_menu.help_doc_action.triggered.connect(
lambda: open_web_browser(
ui_we_want_to_set,
"https://je-editor.readthedocs.io/en/latest/", "Doc")
"https://je-editor.readthedocs.io/en/latest/",
language_wrapper.language_word_dict.get("help_menu_open_doc_label"))
)
ui_we_want_to_set.help_menu.addAction(ui_we_want_to_set.help_menu.help_doc_action)

Expand Down
Loading

0 comments on commit 6682d58

Please sign in to comment.