Skip to content

Commit

Permalink
Merge pull request #151 from Integration-Automation/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
JE-Chen authored Feb 3, 2025
2 parents 1686bc0 + 1cd1d44 commit d2944b4
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 38 deletions.
4 changes: 2 additions & 2 deletions dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ build-backend = "setuptools.build_meta"

[project]
name = "je_editor_dev"
version = "0.0.203"
version = "0.0.212"
authors = [
{ name = "JE-Chen", email = "jechenmailman@gmail.com" },
]
description = "JEditor is basic but powerful editor include GPT"
requires-python = ">=3.9"
license = { text = "MIT" }
dependencies = [
"PySide6==6.8.1", "qt-material", "yapf", "frontengine", "pycodestyle", "jedi", "qtconsole", "re-edge-gpt[gui]"
"PySide6==6.7.3", "qt-material", "yapf", "frontengine", "pycodestyle", "jedi", "qtconsole", "re-edge-gpt[gui]"
]
classifiers = [
"Programming Language :: Python :: 3.9",
Expand Down
2 changes: 1 addition & 1 deletion dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
frontengine
PySide6==6.8.1
PySide6==6.7.3
sphinx
twine
build
Expand Down
4 changes: 2 additions & 2 deletions je_editor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from je_editor.pyside_ui.code.code_process.code_exec import ExecManager
from je_editor.pyside_ui.code.shell_process.shell_exec import ShellManager
from je_editor.pyside_ui.code.syntax.python_syntax import PythonHighlighter
from je_editor.pyside_ui.code.syntax.syntax_setting import syntax_word_setting_dict, syntax_rule_setting_dict
from je_editor.pyside_ui.code.syntax.syntax_setting import syntax_extend_setting_dict, syntax_rule_setting_dict
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 je_editor.pyside_ui.main_ui.main_editor import EDITOR_EXTEND_TAB
Expand All @@ -26,7 +26,7 @@
"start_editor", "EditorMain", "EDITOR_EXTEND_TAB",
"JEditorException", "JEditorExecException", "FullEditorWidget",
"JEditorRunOnShellException", "JEditorSaveFileException", "syntax_rule_setting_dict",
"JEditorOpenFileException", "JEditorContentFileException", "syntax_word_setting_dict",
"JEditorOpenFileException", "JEditorContentFileException", "syntax_extend_setting_dict",
"JEditorCantFindLanguageException", "JEditorJsonException", "PythonHighlighter",
"user_setting_dict", "user_setting_color_dict", "EditorWidget", "BrowserWidget",
"ExecManager", "ShellManager", "traditional_chinese_word_dict", "english_word_dict",
Expand Down
2 changes: 1 addition & 1 deletion je_editor/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# argparse
import argparse

from je_editor.tkinter_ui.editor_main_ui.tkinter_editor import start_editor
from je_editor.start_editor import start_editor

argparse_event_dict = {
"start": start_editor,
Expand Down
2 changes: 1 addition & 1 deletion je_editor/pyside_ui/code/code_process/code_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def exec_code(self, exec_file_name, exec_prefix: Union[str, list] = None) -> Non
# start tkinter_ui update
# start timer
self.timer = QTimer(self.main_window)
self.timer.setInterval(1)
self.timer.setInterval(100)
self.timer.timeout.connect(self.pull_text)
self.timer.start()
except Exception as error:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
import jedi
from PySide6 import QtGui
from PySide6.QtCore import Qt, QRect
from PySide6.QtGui import QPainter, QTextCharFormat, QTextFormat, QKeyEvent, QAction, QTextDocument, QTextCursor
from PySide6.QtGui import QPainter, QTextCharFormat, QTextFormat, QKeyEvent, QAction, QTextDocument, QTextCursor, \
QTextOption
from PySide6.QtWidgets import QPlainTextEdit, QWidget, QTextEdit, QCompleter
from jedi.api.classes import Completion

Expand Down Expand Up @@ -43,6 +44,7 @@ def __init__(self, main_window: Union[EditorWidget, FullEditorWidget]):
self.check_env()
# Self main window (parent)
self.main_window = main_window
self.current_file = main_window.current_file

self.skip_popup_behavior_list = [
Qt.Key.Key_Enter, Qt.Key.Key_Return, Qt.Key.Key_Up, Qt.Key.Key_Down,
Expand All @@ -64,9 +66,10 @@ def __init__(self, main_window: Union[EditorWidget, FullEditorWidget]):
self.setTabStopDistance(
QtGui.QFontMetricsF(self.font()).horizontalAdvance(" ")
)
self.highlighter = PythonHighlighter(self.document())
self.highlighter = PythonHighlighter(self.document(), main_window=self)
self.highlight_current_line()
self.setLineWrapMode(self.LineWrapMode.NoWrap)
self.setWordWrapMode(QTextOption.WrapMode.WrapAnywhere)
# Search Text
self.search_action = QAction("Search")
self.search_action.setShortcut("Ctrl+f")
Expand All @@ -79,6 +82,11 @@ def __init__(self, main_window: Union[EditorWidget, FullEditorWidget]):
self.completer: Union[None, QCompleter] = None
self.set_complete([])

def reset_highlighter(self):
jeditor_logger.info("CodeEditor reset_highlighter")
self.highlighter = PythonHighlighter(self.document(), main_window=self)
self.highlight_current_line()

def check_env(self):
jeditor_logger.info("CodeEditor check_env")
path = venv_check()
Expand Down
2 changes: 1 addition & 1 deletion je_editor/pyside_ui/code/shell_process/shell_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def exec_shell(self, shell_command: [str, list]) -> None:
self.read_program_error_output_from_thread.start()
# start timer
self.timer = QTimer(self.main_window)
self.timer.setInterval(1)
self.timer.setInterval(100)
self.timer.timeout.connect(self.pull_text)
self.timer.start()
except Exception as error:
Expand Down
61 changes: 42 additions & 19 deletions je_editor/pyside_ui/code/syntax/python_syntax.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,57 @@
from __future__ import annotations

from pathlib import Path
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from je_editor.pyside_ui.code.plaintext_code_edit.code_edit_plaintext import CodeEditor

from PySide6.QtCore import QRegularExpression
from PySide6.QtGui import QSyntaxHighlighter
from PySide6.QtGui import QTextCharFormat

from je_editor.pyside_ui.code.syntax.syntax_setting import syntax_word_setting_dict, syntax_rule_setting_dict
from je_editor.pyside_ui.code.syntax.syntax_setting import syntax_word_setting_dict, syntax_rule_setting_dict, \
syntax_extend_setting_dict
from je_editor.utils.logging.loggin_instance import jeditor_logger


class PythonHighlighter(QSyntaxHighlighter):
def __init__(self, parent=None):
def __init__(self, parent=None, main_window: CodeEditor = None):
jeditor_logger.info(f"Init PythonHighlighter parent: {parent}")
super().__init__(parent)

self.highlight_rules = []

# Highlight
for rule_variable_dict in syntax_word_setting_dict.values():
color = rule_variable_dict.get("color")
text_char_format = QTextCharFormat()
text_char_format.setForeground(color)
for word in rule_variable_dict.get("words"):
pattern = QRegularExpression(rf"\b{word}\b")
self.highlight_rules.append((pattern, text_char_format))

for rule_variable_dict in syntax_rule_setting_dict.values():
color = rule_variable_dict.get("color")
text_char_format = QTextCharFormat()
text_char_format.setForeground(color)
for rule in rule_variable_dict.get("rules"):
pattern = QRegularExpression(rule)
self.highlight_rules.append((pattern, text_char_format))
if main_window.current_file is not None:
current_file_suffix = Path(main_window.current_file).suffix
else:
current_file_suffix = ".py"
if current_file_suffix == ".py":
# Highlight
for rule_variable_dict in syntax_word_setting_dict.values():
color = rule_variable_dict.get("color")
text_char_format = QTextCharFormat()
text_char_format.setForeground(color)
for word in rule_variable_dict.get("words"):
pattern = QRegularExpression(rf"\b{word}\b")
self.highlight_rules.append((pattern, text_char_format))
for rule_variable_dict in syntax_rule_setting_dict.values():
color = rule_variable_dict.get("color")
text_char_format = QTextCharFormat()
text_char_format.setForeground(color)
for rule in rule_variable_dict.get("rules"):
pattern = QRegularExpression(rule)
self.highlight_rules.append((pattern, text_char_format))
else:
if syntax_extend_setting_dict.get(current_file_suffix):
for rule_variable_dict in syntax_extend_setting_dict.get(current_file_suffix).values():
color = rule_variable_dict.get("color")
text_char_format = QTextCharFormat()
text_char_format.setForeground(color)
for word in rule_variable_dict.get("words"):
pattern = QRegularExpression(rf"\b{word}\b")
self.highlight_rules.append((pattern, text_char_format))
else:
pass

def highlightBlock(self, text) -> None:
jeditor_logger.info(f"PythonHighlighter highlightBlock text: {text}")
Expand Down
2 changes: 2 additions & 0 deletions je_editor/pyside_ui/code/syntax/syntax_setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,7 @@
"words": ("self",),
"color": QColor(204, 0, 204)
}
}

syntax_extend_setting_dict: dict = {
}
2 changes: 1 addition & 1 deletion je_editor/pyside_ui/main_ui/editor/editor_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def __init__(self, main_window: EditorMain):
self.grid_layout.addWidget(self.full_splitter)
# Check format time
self.check_format_timer = QTimer()
self.check_format_timer.setInterval(10)
self.check_format_timer.setInterval(100)
self.check_format_timer.timeout.connect(self.check_file_format)
self.check_format_timer.start()

Expand Down
9 changes: 5 additions & 4 deletions je_editor/pyside_ui/main_ui/main_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
from PySide6.QtGui import QFontDatabase, QIcon, Qt
from PySide6.QtWidgets import QMainWindow, QWidget, QTabWidget
from frontengine import FrontEngineMainUI
from frontengine import RedirectManager
from qt_material import QtStyleTools

from je_editor.utils.logging.loggin_instance import jeditor_logger
from je_editor.pyside_ui.browser.browser_widget import BrowserWidget
from je_editor.pyside_ui.code.auto_save.auto_save_manager import init_new_auto_save_thread, file_is_open_manager_dict
from je_editor.pyside_ui.main_ui.editor.editor_widget import EditorWidget
Expand All @@ -23,6 +21,7 @@
write_user_setting
from je_editor.pyside_ui.main_ui.system_tray.extend_system_tray import ExtendSystemTray
from je_editor.utils.file.open.open_file import read_file
from je_editor.utils.logging.loggin_instance import jeditor_logger
from je_editor.utils.multi_language.multi_language_wrapper import language_wrapper
from je_editor.utils.redirect_manager.redirect_manager_class import redirect_manager_instance

Expand Down Expand Up @@ -80,7 +79,7 @@ def __init__(self, debug_mode: bool = False, show_system_tray_ray: bool = False)
self.tab_widget.tabCloseRequested.connect(self.close_tab)
# Timer to redirect error or message
self.redirect_timer = QTimer(self)
self.redirect_timer.setInterval(1)
self.redirect_timer.setInterval(100)
self.redirect_timer.start()
self.setWindowTitle(language_wrapper.language_word_dict.get("application_name"))
self.setToolTip(language_wrapper.language_word_dict.get("application_name"))
Expand All @@ -101,7 +100,7 @@ def __init__(self, debug_mode: bool = False, show_system_tray_ray: bool = False)
redirect_manager_instance.set_redirect()
# Timer to redirect error or message
self.redirect_timer = QTimer(self)
self.redirect_timer.setInterval(1)
self.redirect_timer.setInterval(100)
self.redirect_timer.timeout.connect(self.redirect)
self.redirect_timer.start()
# TAB Add
Expand Down Expand Up @@ -181,6 +180,8 @@ def startup_setting(self) -> None:
if last_file_path.is_file() and last_file_path.exists() and widget.code_save_thread is None:
init_new_auto_save_thread(str(last_file_path), widget)
widget.code_edit.setPlainText(read_file(widget.current_file)[1])
widget.code_edit.current_file = widget.current_file
widget.code_edit.reset_highlighter()
file_is_open_manager_dict.update({str(last_file_path): str(last_file_path.name)})
widget.rename_self_tab()

Expand Down
3 changes: 2 additions & 1 deletion je_editor/utils/redirect_manager/redirect_manager_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ def set_redirect() -> None:
sys.stderr = redirect_err
default_logger = logging.getLogger("RedirectManager")
default_logger.addHandler(redirect_err)
skip_logger_list = ["JEditor", "FrontEngine", "AutomationIDE"]
for name in logging.root.manager.loggerDict.keys():
if name == "JEditor":
if name in skip_logger_list:
continue
else:
logging.getLogger(name).addHandler(redirect_err)
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ build-backend = "setuptools.build_meta"

[project]
name = "je_editor"
version = "0.0.186"
version = "0.0.192"
authors = [
{ name = "JE-Chen", email = "jechenmailman@gmail.com" },
]
description = "JEditor is basic but powerful editor include GPT"
requires-python = ">=3.9"
license = { text = "MIT" }
dependencies = [
"PySide6==6.8.1", "qt-material", "yapf", "frontengine", "pycodestyle", "jedi", "qtconsole", "re-edge-gpt[gui]"
"PySide6==6.7.3", "qt-material", "yapf", "frontengine", "pycodestyle", "jedi", "qtconsole", "re-edge-gpt[gui]"
]
classifiers = [
"Programming Language :: Python :: 3.9",
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
frontengine
PySide6==6.8.1
PySide6==6.7.3
sphinx
auto-py-to-exe
twine
Expand Down

0 comments on commit d2944b4

Please sign in to comment.