This repository has been archived by the owner on Jan 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
48 lines (39 loc) · 1.5 KB
/
example.py
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
#!/usr/bin/python3
from PySide6.QtCore import *
from PySide6.QtGui import *
from PySide6.QtWidgets import *
import sys
from qt_material import apply_stylesheet
import TinyMCE_on_Pyqt as editor
class my_TinyMCE(editor.TinyMCE_on_PyQt_window):
def __init__(self):
super(my_TinyMCE, self).__init__()
# 添加保存按钮
self.save_button = QPushButton("保存文件",self)
self.save_button.clicked.connect(self.choose_file)
self.open_button = QPushButton("打开文件",self)
self.open_button.clicked.connect(self.open_file)
self.layout.addWidget(self.save_button)
self.layout.addWidget(self.open_button)
# 监听键盘
def keyPressEvent(self, event):
if QApplication.keyboardModifiers() == Qt.ControlModifier and event.key() == Qt.Key_S: #检测CtrlS保存按键
self.choose_file()
def choose_file(self):
file_url = QFileDialog.getSaveFileName(self,
"设置保存位置","./",
"All Files (*);;Text Files (*.html)")[0]
self.save_file(file_url)
def open_file(self):
file_url = QFileDialog.getOpenFileName(self,
"选择打开位置","./",
"All Files (*);;Text Files (*.html)")[0]
print(file_url)
with open(file_url, mode='r', encoding='utf-8') as file_obj:
self.set_html(file_obj.read())
app=QApplication(sys.argv)
apply_stylesheet(app, theme='dark_teal.xml')
win=my_TinyMCE()
win.init()
win.show()
app.exit(app.exec())