-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_editor.py
More file actions
67 lines (53 loc) · 2.04 KB
/
test_editor.py
File metadata and controls
67 lines (53 loc) · 2.04 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
import sys
from PyQt6.QtWidgets import (
QApplication, QMainWindow, QVBoxLayout, QWidget, QFileDialog, QMenu, QToolBar
)
from PyQt6.QtGui import QAction
from src.common.CodingWidgets import CodeEditor, CodeEditorMenu, CodeEditorToolbar
import re
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("RST Highlighter Debugger")
self.editor = CodeEditor()
#self.highlighter = RstHighlighter(self.editor.document(), self.rules)
menu_bar = self.menuBar()
toolbar = QToolBar(self)
file_menu = QMenu("File", self)
open_action = QAction("Open", self)
open_action.triggered.connect(self.load_file_dialog)
file_menu.addAction(open_action)
menu_bar.addMenu(file_menu)
CodeEditorMenu(self.editor, menu_bar)
CodeEditorToolbar(self.editor, toolbar)
container = QWidget()
layout = QVBoxLayout()
layout.addWidget(toolbar)
layout.addWidget(self.editor)
container.setLayout(layout)
self.setCentralWidget(container)
#preload_file = "docs/source/left_toolbox.rst" # Adjust path as needed
preload_file = "tests/test.rst" # Adjust path as needed
try:
with open(preload_file, 'r', encoding='utf-8') as f:
content = f.read()
self.editor.setPlainText(content)
except FileNotFoundError:
self.editor.setPlainText("test.rst not found.\nStart typing or open a file.")
def load_file_dialog(self):
file_name, _ = QFileDialog.getOpenFileName(
self,
"Open ReStructuredText File",
"",
"ReStructuredText Files (*.rst *.txt);;All Files (*)"
)
if file_name:
with open(file_name, 'r', encoding='utf-8') as f:
content = f.read()
self.editor.setPlainText(content)
if __name__ == "__main__":
app = QApplication(sys.argv)
win = MainWindow()
win.resize(800, 600)
win.show()
sys.exit(app.exec())