Skip to content

Commit

Permalink
Merge pull request #134 from Integration-Automation/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
JE-Chen authored Sep 22, 2023
2 parents c09a105 + e0e800c commit c5a0fd0
Show file tree
Hide file tree
Showing 20 changed files with 287 additions and 75 deletions.
48 changes: 46 additions & 2 deletions exe/auto_py_to_exe.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,52 @@
"value": "C:/CodeWorkspace/je_editor/venv"
},
{
"optionDest": "pathex",
"value": "C:/CodeWorkspace/je_editor/venv/Lib/site-packages"
"optionDest": "datas",
"value": "C:/CodeWorkspace/je_editor/exe/venv/Lib/site-packages/jupyter_client;jupyter_client/"
},
{
"optionDest": "datas",
"value": "C:/CodeWorkspace/je_editor/exe/venv/Lib/site-packages/jupyter_client-8.3.1.dist-info;jupyter_client-8.3.1.dist-info/"
},
{
"optionDest": "datas",
"value": "C:/CodeWorkspace/je_editor/exe/venv/Lib/site-packages/jupyter_core-5.3.1.dist-info;jupyter_core-5.3.1.dist-info/"
},
{
"optionDest": "datas",
"value": "C:/CodeWorkspace/je_editor/exe/venv/Lib/site-packages/jupyter_core;jupyter_core/"
},
{
"optionDest": "datas",
"value": "C:/CodeWorkspace/je_editor/exe/venv/Lib/site-packages/qtconsole-5.4.4.dist-info;qtconsole-5.4.4.dist-info/"
},
{
"optionDest": "datas",
"value": "C:/CodeWorkspace/je_editor/exe/venv/Lib/site-packages/qtconsole;qtconsole/"
},
{
"optionDest": "datas",
"value": "C:/CodeWorkspace/je_editor/exe/venv/Lib/site-packages/ipython-8.15.0.dist-info;ipython-8.15.0.dist-info/"
},
{
"optionDest": "datas",
"value": "C:/CodeWorkspace/je_editor/exe/venv/Lib/site-packages/IPython;IPython/"
},
{
"optionDest": "datas",
"value": "C:/CodeWorkspace/je_editor/exe/venv/Lib/site-packages/debugpy/_vendored/pydevd/pydev_ipython;pydev_ipython/"
},
{
"optionDest": "datas",
"value": "C:/CodeWorkspace/je_editor/exe/venv/Lib/site-packages/ipython_genutils-0.2.0.dist-info;ipython_genutils-0.2.0.dist-info/"
},
{
"optionDest": "datas",
"value": "C:/CodeWorkspace/je_editor/exe/venv/Lib/site-packages/ipython_genutils;ipython_genutils/"
},
{
"optionDest": "datas",
"value": "C:/CodeWorkspace/je_editor/exe/venv/Lib/site-packages/debugpy;debugpy/"
}
],
"nonPyinstallerOptions": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
from __future__ import annotations

from pathlib import Path
from typing import TYPE_CHECKING


if TYPE_CHECKING:
from je_editor.pyside_ui.main_ui.editor.editor_widget import EditorWidget
from je_editor.pyside_ui.main_ui.editor.editor_widget_dock import FullEditorWidget

from typing import Union, List

import jedi
Expand All @@ -24,10 +33,15 @@ class CodeEditor(QPlainTextEdit):
Add line, edit tab distance, add highlighter, add search text
"""

def __init__(self):
def __init__(self, main_window: Union[EditorWidget, FullEditorWidget]):
super().__init__()
# Jedi
self.env = None
self.check_env()
self.project = jedi.Project(str(Path.cwd()))
# Self main window (parent)
self.main_window = main_window

self.skip_popup_behavior_list = [
Qt.Key.Key_Enter, Qt.Key.Key_Return, Qt.Key.Key_Up, Qt.Key.Key_Down,
Qt.Key.Key_Tab, Qt.Key.Key_Backtab, Qt.Key.Key_Space, Qt.Key.Key_Backspace
Expand Down Expand Up @@ -68,6 +82,7 @@ def check_env(self):
try:
if path.exists():
self.env = jedi.create_environment(str(path))
self.project = jedi.Project(str(Path.cwd()))
except Exception as error:
error.with_traceback()

Expand Down Expand Up @@ -257,18 +272,34 @@ def keyPressEvent(self, event: QKeyEvent) -> None:
:return: None
"""
# 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:
key = event.key()
if event.modifiers() and Qt.Modifier.CTRL:
if key == Qt.Key.Key_B:
if self.env is not None:
script = jedi.Script(code=self.toPlainText(), environment=self.env)
else:
script = jedi.Script(code=self.toPlainText())
goto_list: List[jedi.api.classes.Name] = script.goto(
self.textCursor().blockNumber() + 1, self.textCursor().positionInBlock())
if len(goto_list) > 0:
path = goto_list[0].module_path
if path is not None and path.exists():
if self.main_window.current_file != str(path):
self.main_window.main_window.go_to_new_tab(path)
else:
self.textCursor().setPosition(goto_list[0].line - 1)
return
if self.completer.popup().isVisible() and key in self.skip_popup_behavior_list:
self.completer.popup().close()
event.ignore()
return
if event.modifiers() and Qt.Modifier.SHIFT:
key = event.key()
if key == Qt.Key.Key_Enter or key == Qt.Key.Key_Return:
event.ignore()
return
super().keyPressEvent(event)
self.highlight_current_line()
if event.key() in self.need_complete_list and self.completer is not None:
if key in self.need_complete_list and self.completer is not None:
if self.completer.popup().isVisible():
self.completer.popup().close()
self.complete()
Expand Down
19 changes: 12 additions & 7 deletions je_editor/pyside_ui/code/shell_process/shell_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import sys
from pathlib import Path
from threading import Thread
from typing import Union
from typing import Union, Callable

from PySide6.QtCore import QTimer
from PySide6.QtWidgets import QTextEdit
Expand All @@ -27,6 +27,7 @@ def __init__(
main_window: Union[EditorWidget, None] = None,
shell_encoding: str = "utf-8",
program_buffer: int = 8192000,
after_done_function: Union[None, Callable] = None
):
"""
:param main_window: Pyside main window
Expand All @@ -45,6 +46,7 @@ def __init__(
self.run_error_queue: queue = queue.Queue()
self.program_encoding: str = shell_encoding
self.program_buffer: int = program_buffer
self.after_done_function = after_done_function
self.renew_path()
run_instance_manager.instance_list.append(self)

Expand Down Expand Up @@ -130,17 +132,20 @@ def pull_text(self) -> None:
except queue.Empty:
pass
if self.process.returncode == 0:
self.timer.stop()
self.exit_program()
self.main_window.exec_shell = None
self.process_run_over()
elif self.process.returncode is not None:
self.timer.stop()
self.exit_program()
self.main_window.exec_shell = None
self.process_run_over()
if self.still_run_shell:
# poll return code
self.process.poll()

def process_run_over(self):
self.timer.stop()
self.exit_program()
self.main_window.exec_shell = None
if self.after_done_function is not None:
self.after_done_function()

# exit program change run flag to false and clean read thread and queue and process
def exit_program(self) -> None:
self.still_run_shell = False
Expand Down
20 changes: 11 additions & 9 deletions je_editor/pyside_ui/dialog/file_dialog/open_file_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@ def choose_dir_get_dir_path(parent_qt_instance: EditorMain) -> None:
dir_path = QFileDialog().getExistingDirectory(parent=parent_qt_instance,)
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()
else:
return
if check_path.exists() and check_path.is_dir():
parent_qt_instance.working_dir = dir_path
os.chdir(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()
parent_qt_instance.startup_setting()

5 changes: 3 additions & 2 deletions je_editor/pyside_ui/main_ui/dock/destroy_dock.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ class DestroyDock(QDockWidget):
def __init__(self):
super().__init__()
self.setAllowedAreas(Qt.DockWidgetArea.AllDockWidgetAreas)
# Attr
self.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose)

def closeEvent(self, event) -> None:
self.widget().closeEvent(event)
super().closeEvent(event)
self.widget().close()
super().close()
66 changes: 40 additions & 26 deletions je_editor/pyside_ui/main_ui/editor/editor_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self, main_window: EditorMain):
self.python_compiler = None
self.main_window = main_window
self.tab_manager = self.main_window.tab_widget
self.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose)
# Attr
# Current execute instance if none not running
self.exec_program: Union[None, ExecManager] = None
self.exec_shell: Union[None, ShellManager] = None
Expand All @@ -58,7 +58,7 @@ def __init__(self, main_window: EditorMain):
self.edit_splitter = QSplitter(self.full_splitter)
self.edit_splitter.setOrientation(Qt.Orientation.Vertical)
# code edit and code result plaintext
self.code_edit = CodeEditor()
self.code_edit = CodeEditor(self)
self.code_result = CodeRecord()
self.code_edit_scroll_area = QScrollArea()
self.code_edit_scroll_area.setWidgetResizable(True)
Expand Down Expand Up @@ -129,37 +129,50 @@ def set_project_treeview(self) -> None:
self.grid_layout.addWidget(self.tree_view_scroll_area, 0, 0, 0, 1)
self.project_treeview.clicked.connect(self.treeview_click)

def check_is_open(self, path: Path):
if file_is_open_manager_dict.get(str(path), None) is not None:
widget: QWidget = self.tab_manager.findChild(EditorWidget, str(path))
if widget is None:
file_is_open_manager_dict.pop(str(path), None)
else:
self.tab_manager.setCurrentWidget(widget)
return False
else:
file_is_open_manager_dict.update({str(path): str(path)})
return True

def open_an_file(self, path: Path) -> bool:
"""
:param path: open file path
:return: return False if file tab exists
"""
if not self.check_is_open(path):
return False
file, file_content = read_file(str(path))
self.code_edit.setPlainText(
file_content
)
self.current_file = file
user_setting_dict.update({"last_file": str(self.current_file)})
if self.current_file is not None and self.code_save_thread is None:
init_new_auto_save_thread(self.current_file, self)
else:
self.code_save_thread.file = self.current_file
self.rename_self_tab()
return True

def treeview_click(self) -> None:
clicked_item: QFileSystemModel = self.project_treeview.selectedIndexes()[0]
file_info: QFileInfo = self.project_treeview.model().fileInfo(clicked_item)
path = pathlib.Path(file_info.absoluteFilePath())
if path.is_file():
if file_is_open_manager_dict.get(str(path), None) is not None:
widget: QWidget = self.tab_manager.findChild(EditorWidget, str(path.name))
if widget is None:
file_is_open_manager_dict.pop(str(path), None)
else:
self.tab_manager.setCurrentWidget(widget)
return
else:
file_is_open_manager_dict.update({str(path): str(path.name)})
file, file_content = read_file(str(path))
self.code_edit.setPlainText(
file_content
)
self.current_file = file
user_setting_dict.update({"last_file": str(self.current_file)})
if self.current_file is not None and self.code_save_thread is None:
init_new_auto_save_thread(self.current_file, self)
else:
self.code_save_thread.file = self.current_file
self.rename_self_tab()
self.open_an_file(path)

def rename_self_tab(self):
if self.tab_manager.currentWidget() is self:
self.tab_manager.setTabText(
self.tab_manager.currentIndex(), str(Path(self.current_file).name))
self.setObjectName(str(Path(self.current_file).name))
self.tab_manager.currentIndex(), str(Path(self.current_file)))
self.setObjectName(str(Path(self.current_file)))

def check_file_format(self):
if self.current_file:
Expand All @@ -171,8 +184,9 @@ def check_file_format(self):

def close(self) -> bool:
self.check_format_timer.stop()
self.code_save_thread.still_run = False
self.code_save_thread = None
if self.code_save_thread is not None:
self.code_save_thread.still_run = False
self.code_save_thread = None
file_is_open_manager_dict.pop(self.current_file, None)
auto_save_manager_dict.pop(self.current_file, None)
return super().close()
2 changes: 1 addition & 1 deletion je_editor/pyside_ui/main_ui/editor/editor_widget_dock.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self, current_file: str):
self.grid_layout = QGridLayout(self)
self.setWindowTitle(language_wrapper.language_word_dict.get("application_name"))
# code edit and code result plaintext
self.code_edit = CodeEditor()
self.code_edit = CodeEditor(self)
self.code_edit_scroll_area = QScrollArea()
self.code_edit_scroll_area.setWidgetResizable(True)
self.code_edit_scroll_area.setViewportMargins(0, 0, 0, 0)
Expand Down
2 changes: 2 additions & 0 deletions je_editor/pyside_ui/main_ui/editor/process_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ class ProcessInput(QWidget):

def __init__(self, main_window: EditorWidget, process_type: str = "debugger"):
super().__init__()
# Attr
self.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose)
# UI setting
self.main_window = main_window
self.box_layout = QBoxLayout(QBoxLayout.Direction.TopToBottom)
self.command_input = QLineEdit()
Expand Down
Empty file.
51 changes: 51 additions & 0 deletions je_editor/pyside_ui/main_ui/ipython_widget/rich_jupyter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from __future__ import annotations

from typing import TYPE_CHECKING

import IPython
from IPython.lib import guisupport
from PySide6.QtWidgets import QWidget, QGridLayout, QLabel

from je_editor.utils.multi_language.multi_language_wrapper import language_wrapper

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


class IpythonWidget(QWidget):
def __init__(self, main_window: EditorMain):
super().__init__()
self.grid_layout = QGridLayout()
self.ipython_enable = False
try:
from qtconsole.inprocess import QtInProcessKernelManager
from qtconsole.rich_jupyter_widget import RichJupyterWidget
app = guisupport.get_app_qt4()
kernel_manager = QtInProcessKernelManager()
kernel_manager.start_kernel()
kernel = kernel_manager.kernel
kernel.gui = "qt"
kernel_client = kernel_manager.client()
kernel_client.start_channels()
control = RichJupyterWidget()
control.kernel_manager = kernel_manager
control.kernel_client = kernel_client

def stop():
kernel_client.stop_channels()
kernel_manager.shutdown_kernel()
self.close()

control.exit_requested.connect(stop)
self.show_widget = control
self.grid_layout.addWidget(self.show_widget, 0, 0, -1, -1)
guisupport.start_event_loop_qt4(app)
except ImportError:
self.ipython_enable = False
self.show_widget = QLabel(language_wrapper.language_word_dict.get("please_install_qtcontsole_label"))
self.grid_layout.addWidget(self.show_widget)

self.setLayout(self.grid_layout)

def close(self):
super().close()
Loading

0 comments on commit c5a0fd0

Please sign in to comment.