-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditor.py
More file actions
87 lines (69 loc) · 2.72 KB
/
editor.py
File metadata and controls
87 lines (69 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from msilib.schema import SelfReg
from multiprocessing import parent_process
from random import paretovariate
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.Qsci import *
from PyQt5.QtGui import *
import keyword
import pkgutil
from lexer import HTMLCustomLexer
from typing import TYPE_CHECKING
class Editor(QsciScintilla):
def __init__(self, main_window, parent=None):
super(Editor, self).__init__(parent)
self.main_window = main_window
self._current_file_changed = False
# Encoding
self.setUtf8(True)
# Font
self.window_font = QFont("Fire Code")
self.window_font.setPointSize(12)
self.setFont(self.window_font)
# Brace matching
self.setBraceMatching(QsciScintilla.SloppyBraceMatch)
# Indentation
self.setIndentationGuides(True)
self.setTabWidth(4)
self.setIndentationsUseTabs(False)
self.setAutoIndent(True)
# Autocomplete
self.setAutoCompletionSource(QsciScintilla.AcsAll)
self.setAutoCompletionThreshold(1)
self.setAutoCompletionCaseSensitivity(False)
self.setAutoCompletionUseSingle(QsciScintilla.AcusNever)
# Caret
self.setCaretForegroundColor(QColor("#0A4435")) # Green color
self.setCaretLineVisible(True)
self.setCaretWidth(2)
self.setCaretLineBackgroundColor(QColor("#0A4435")) # Dark green color
# EOL
self.setEolMode(QsciScintilla.EolWindows)
self.setEolVisibility(False)
# Lexer for syntax highlighting
self.pylexer = HTMLCustomLexer(self)
self.pylexer.setDefaultFont(self.window_font)
# API
self.api = QsciAPIs(self.pylexer)
for key in keyword.kwlist+dir(__builtins__):
self.api.add(key)
for _, name, _ in pkgutil.iter_modules():
self.api.add(name)
# For test purpose, you can add custom function with its parameters
self.api.add("addition(a: int, b: int)")
self.api.prepare()
self.setLexer(self.pylexer)
# Line numbers
self.setMarginType(0, QsciScintilla.NumberMargin)
self.setMarginWidth(0, "000")
self.setMarginsForegroundColor(QColor("#c2d3b2")) # Light green color
self.setMarginsBackgroundColor(QColor("#173725")) # Dark green color
self.setMarginsFont(self.window_font)
@property
def current_file_changed(self, value: bool):
curr_index = self.main_window
def keyPressEvent(self, e: QKeyEvent) -> None:
if e.modifiers() == Qt.ControlModifier and e.key() == Qt.Key_Space:
self.autoCompleteFromAll()
else:
return super().keyPressEvent(e)