Skip to content

Commit d2944b4

Browse files
authored
Merge pull request #151 from Integration-Automation/dev
Dev
2 parents 1686bc0 + 1cd1d44 commit d2944b4

File tree

14 files changed

+73
-38
lines changed

14 files changed

+73
-38
lines changed

dev.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ build-backend = "setuptools.build_meta"
66

77
[project]
88
name = "je_editor_dev"
9-
version = "0.0.203"
9+
version = "0.0.212"
1010
authors = [
1111
{ name = "JE-Chen", email = "[email protected]" },
1212
]
1313
description = "JEditor is basic but powerful editor include GPT"
1414
requires-python = ">=3.9"
1515
license = { text = "MIT" }
1616
dependencies = [
17-
"PySide6==6.8.1", "qt-material", "yapf", "frontengine", "pycodestyle", "jedi", "qtconsole", "re-edge-gpt[gui]"
17+
"PySide6==6.7.3", "qt-material", "yapf", "frontengine", "pycodestyle", "jedi", "qtconsole", "re-edge-gpt[gui]"
1818
]
1919
classifiers = [
2020
"Programming Language :: Python :: 3.9",

dev_requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
frontengine
2-
PySide6==6.8.1
2+
PySide6==6.7.3
33
sphinx
44
twine
55
build

je_editor/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from je_editor.pyside_ui.code.code_process.code_exec import ExecManager
33
from je_editor.pyside_ui.code.shell_process.shell_exec import ShellManager
44
from je_editor.pyside_ui.code.syntax.python_syntax import PythonHighlighter
5-
from je_editor.pyside_ui.code.syntax.syntax_setting import syntax_word_setting_dict, syntax_rule_setting_dict
5+
from je_editor.pyside_ui.code.syntax.syntax_setting import syntax_extend_setting_dict, syntax_rule_setting_dict
66
from je_editor.pyside_ui.main_ui.editor.editor_widget import EditorWidget
77
from je_editor.pyside_ui.main_ui.editor.editor_widget_dock import FullEditorWidget
88
from je_editor.pyside_ui.main_ui.main_editor import EDITOR_EXTEND_TAB
@@ -26,7 +26,7 @@
2626
"start_editor", "EditorMain", "EDITOR_EXTEND_TAB",
2727
"JEditorException", "JEditorExecException", "FullEditorWidget",
2828
"JEditorRunOnShellException", "JEditorSaveFileException", "syntax_rule_setting_dict",
29-
"JEditorOpenFileException", "JEditorContentFileException", "syntax_word_setting_dict",
29+
"JEditorOpenFileException", "JEditorContentFileException", "syntax_extend_setting_dict",
3030
"JEditorCantFindLanguageException", "JEditorJsonException", "PythonHighlighter",
3131
"user_setting_dict", "user_setting_color_dict", "EditorWidget", "BrowserWidget",
3232
"ExecManager", "ShellManager", "traditional_chinese_word_dict", "english_word_dict",

je_editor/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# argparse
33
import argparse
44

5-
from je_editor.tkinter_ui.editor_main_ui.tkinter_editor import start_editor
5+
from je_editor.start_editor import start_editor
66

77
argparse_event_dict = {
88
"start": start_editor,

je_editor/pyside_ui/code/code_process/code_exec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def exec_code(self, exec_file_name, exec_prefix: Union[str, list] = None) -> Non
131131
# start tkinter_ui update
132132
# start timer
133133
self.timer = QTimer(self.main_window)
134-
self.timer.setInterval(1)
134+
self.timer.setInterval(100)
135135
self.timer.timeout.connect(self.pull_text)
136136
self.timer.start()
137137
except Exception as error:

je_editor/pyside_ui/code/plaintext_code_edit/code_edit_plaintext.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
import jedi
1515
from PySide6 import QtGui
1616
from PySide6.QtCore import Qt, QRect
17-
from PySide6.QtGui import QPainter, QTextCharFormat, QTextFormat, QKeyEvent, QAction, QTextDocument, QTextCursor
17+
from PySide6.QtGui import QPainter, QTextCharFormat, QTextFormat, QKeyEvent, QAction, QTextDocument, QTextCursor, \
18+
QTextOption
1819
from PySide6.QtWidgets import QPlainTextEdit, QWidget, QTextEdit, QCompleter
1920
from jedi.api.classes import Completion
2021

@@ -43,6 +44,7 @@ def __init__(self, main_window: Union[EditorWidget, FullEditorWidget]):
4344
self.check_env()
4445
# Self main window (parent)
4546
self.main_window = main_window
47+
self.current_file = main_window.current_file
4648

4749
self.skip_popup_behavior_list = [
4850
Qt.Key.Key_Enter, Qt.Key.Key_Return, Qt.Key.Key_Up, Qt.Key.Key_Down,
@@ -64,9 +66,10 @@ def __init__(self, main_window: Union[EditorWidget, FullEditorWidget]):
6466
self.setTabStopDistance(
6567
QtGui.QFontMetricsF(self.font()).horizontalAdvance(" ")
6668
)
67-
self.highlighter = PythonHighlighter(self.document())
69+
self.highlighter = PythonHighlighter(self.document(), main_window=self)
6870
self.highlight_current_line()
6971
self.setLineWrapMode(self.LineWrapMode.NoWrap)
72+
self.setWordWrapMode(QTextOption.WrapMode.WrapAnywhere)
7073
# Search Text
7174
self.search_action = QAction("Search")
7275
self.search_action.setShortcut("Ctrl+f")
@@ -79,6 +82,11 @@ def __init__(self, main_window: Union[EditorWidget, FullEditorWidget]):
7982
self.completer: Union[None, QCompleter] = None
8083
self.set_complete([])
8184

85+
def reset_highlighter(self):
86+
jeditor_logger.info("CodeEditor reset_highlighter")
87+
self.highlighter = PythonHighlighter(self.document(), main_window=self)
88+
self.highlight_current_line()
89+
8290
def check_env(self):
8391
jeditor_logger.info("CodeEditor check_env")
8492
path = venv_check()

je_editor/pyside_ui/code/shell_process/shell_exec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def exec_shell(self, shell_command: [str, list]) -> None:
112112
self.read_program_error_output_from_thread.start()
113113
# start timer
114114
self.timer = QTimer(self.main_window)
115-
self.timer.setInterval(1)
115+
self.timer.setInterval(100)
116116
self.timer.timeout.connect(self.pull_text)
117117
self.timer.start()
118118
except Exception as error:

je_editor/pyside_ui/code/syntax/python_syntax.py

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,57 @@
1+
from __future__ import annotations
2+
3+
from pathlib import Path
4+
from typing import TYPE_CHECKING
5+
6+
if TYPE_CHECKING:
7+
from je_editor.pyside_ui.code.plaintext_code_edit.code_edit_plaintext import CodeEditor
8+
19
from PySide6.QtCore import QRegularExpression
210
from PySide6.QtGui import QSyntaxHighlighter
311
from PySide6.QtGui import QTextCharFormat
412

5-
from je_editor.pyside_ui.code.syntax.syntax_setting import syntax_word_setting_dict, syntax_rule_setting_dict
13+
from je_editor.pyside_ui.code.syntax.syntax_setting import syntax_word_setting_dict, syntax_rule_setting_dict, \
14+
syntax_extend_setting_dict
615
from je_editor.utils.logging.loggin_instance import jeditor_logger
716

817

918
class PythonHighlighter(QSyntaxHighlighter):
10-
def __init__(self, parent=None):
19+
def __init__(self, parent=None, main_window: CodeEditor = None):
1120
jeditor_logger.info(f"Init PythonHighlighter parent: {parent}")
1221
super().__init__(parent)
1322

1423
self.highlight_rules = []
15-
16-
# Highlight
17-
for rule_variable_dict in syntax_word_setting_dict.values():
18-
color = rule_variable_dict.get("color")
19-
text_char_format = QTextCharFormat()
20-
text_char_format.setForeground(color)
21-
for word in rule_variable_dict.get("words"):
22-
pattern = QRegularExpression(rf"\b{word}\b")
23-
self.highlight_rules.append((pattern, text_char_format))
24-
25-
for rule_variable_dict in syntax_rule_setting_dict.values():
26-
color = rule_variable_dict.get("color")
27-
text_char_format = QTextCharFormat()
28-
text_char_format.setForeground(color)
29-
for rule in rule_variable_dict.get("rules"):
30-
pattern = QRegularExpression(rule)
31-
self.highlight_rules.append((pattern, text_char_format))
24+
if main_window.current_file is not None:
25+
current_file_suffix = Path(main_window.current_file).suffix
26+
else:
27+
current_file_suffix = ".py"
28+
if current_file_suffix == ".py":
29+
# Highlight
30+
for rule_variable_dict in syntax_word_setting_dict.values():
31+
color = rule_variable_dict.get("color")
32+
text_char_format = QTextCharFormat()
33+
text_char_format.setForeground(color)
34+
for word in rule_variable_dict.get("words"):
35+
pattern = QRegularExpression(rf"\b{word}\b")
36+
self.highlight_rules.append((pattern, text_char_format))
37+
for rule_variable_dict in syntax_rule_setting_dict.values():
38+
color = rule_variable_dict.get("color")
39+
text_char_format = QTextCharFormat()
40+
text_char_format.setForeground(color)
41+
for rule in rule_variable_dict.get("rules"):
42+
pattern = QRegularExpression(rule)
43+
self.highlight_rules.append((pattern, text_char_format))
44+
else:
45+
if syntax_extend_setting_dict.get(current_file_suffix):
46+
for rule_variable_dict in syntax_extend_setting_dict.get(current_file_suffix).values():
47+
color = rule_variable_dict.get("color")
48+
text_char_format = QTextCharFormat()
49+
text_char_format.setForeground(color)
50+
for word in rule_variable_dict.get("words"):
51+
pattern = QRegularExpression(rf"\b{word}\b")
52+
self.highlight_rules.append((pattern, text_char_format))
53+
else:
54+
pass
3255

3356
def highlightBlock(self, text) -> None:
3457
jeditor_logger.info(f"PythonHighlighter highlightBlock text: {text}")

je_editor/pyside_ui/code/syntax/syntax_setting.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,7 @@
6161
"words": ("self",),
6262
"color": QColor(204, 0, 204)
6363
}
64+
}
6465

66+
syntax_extend_setting_dict: dict = {
6567
}

je_editor/pyside_ui/main_ui/editor/editor_widget.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def __init__(self, main_window: EditorMain):
108108
self.grid_layout.addWidget(self.full_splitter)
109109
# Check format time
110110
self.check_format_timer = QTimer()
111-
self.check_format_timer.setInterval(10)
111+
self.check_format_timer.setInterval(100)
112112
self.check_format_timer.timeout.connect(self.check_file_format)
113113
self.check_format_timer.start()
114114

0 commit comments

Comments
 (0)