|
|
|
|
@ -74,12 +74,18 @@ class WordStyleMainWindow(QMainWindow):
|
|
|
|
|
|
|
|
|
|
def set_window_icon(self):
|
|
|
|
|
"""设置窗口图标"""
|
|
|
|
|
# 创建简单的Word风格图标
|
|
|
|
|
icon = QIcon()
|
|
|
|
|
pixmap = QPixmap(32, 32)
|
|
|
|
|
pixmap.fill(QColor("#2B579A"))
|
|
|
|
|
icon.addPixmap(pixmap)
|
|
|
|
|
self.setWindowIcon(icon)
|
|
|
|
|
# 使用我们创建的Word风格图标
|
|
|
|
|
project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
|
icon_path = os.path.join(project_root, 'resources', 'icons', 'app_icon.png')
|
|
|
|
|
if os.path.exists(icon_path):
|
|
|
|
|
self.setWindowIcon(QIcon(icon_path))
|
|
|
|
|
else:
|
|
|
|
|
# 如果图标文件不存在,创建简单的Word风格图标
|
|
|
|
|
icon = QIcon()
|
|
|
|
|
pixmap = QPixmap(32, 32)
|
|
|
|
|
pixmap.fill(QColor("#2B579A"))
|
|
|
|
|
icon.addPixmap(pixmap)
|
|
|
|
|
self.setWindowIcon(icon)
|
|
|
|
|
|
|
|
|
|
def setup_ui(self):
|
|
|
|
|
"""设置Word风格的UI界面"""
|
|
|
|
|
@ -513,8 +519,16 @@ class WordStyleMainWindow(QMainWindow):
|
|
|
|
|
"""保存文件"""
|
|
|
|
|
if self.current_file_path:
|
|
|
|
|
try:
|
|
|
|
|
with open(self.current_file_path, 'w', encoding='utf-8') as f:
|
|
|
|
|
f.write(self.text_edit.toPlainText())
|
|
|
|
|
# 如果是.docx文件,创建一个基本的Word文档
|
|
|
|
|
if self.current_file_path.endswith('.docx'):
|
|
|
|
|
from docx import Document
|
|
|
|
|
doc = Document()
|
|
|
|
|
doc.add_paragraph(self.text_edit.toPlainText())
|
|
|
|
|
doc.save(self.current_file_path)
|
|
|
|
|
else:
|
|
|
|
|
# 对于其他格式,保持原有逻辑
|
|
|
|
|
with open(self.current_file_path, 'w', encoding='utf-8') as f:
|
|
|
|
|
f.write(self.text_edit.toPlainText())
|
|
|
|
|
|
|
|
|
|
self.is_modified = False
|
|
|
|
|
self.update_window_title()
|
|
|
|
|
@ -528,13 +542,25 @@ class WordStyleMainWindow(QMainWindow):
|
|
|
|
|
def save_as_file(self):
|
|
|
|
|
"""另存为"""
|
|
|
|
|
file_path, _ = QFileDialog.getSaveFileName(
|
|
|
|
|
self, "另存为", "", "文本文档 (*.txt);;所有文件 (*.*)"
|
|
|
|
|
self, "另存为", "", "Word文档 (*.docx);;文本文档 (*.txt);;所有文件 (*.*)"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if file_path:
|
|
|
|
|
# 如果用户没有指定扩展名,自动添加.docx扩展名
|
|
|
|
|
if not os.path.splitext(file_path)[1]:
|
|
|
|
|
file_path += ".docx"
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
with open(file_path, 'w', encoding='utf-8') as f:
|
|
|
|
|
f.write(self.text_edit.toPlainText())
|
|
|
|
|
# 如果是.docx文件,创建一个基本的Word文档
|
|
|
|
|
if file_path.endswith('.docx'):
|
|
|
|
|
from docx import Document
|
|
|
|
|
doc = Document()
|
|
|
|
|
doc.add_paragraph(self.text_edit.toPlainText())
|
|
|
|
|
doc.save(file_path)
|
|
|
|
|
else:
|
|
|
|
|
# 对于其他格式,保持原有逻辑
|
|
|
|
|
with open(file_path, 'w', encoding='utf-8') as f:
|
|
|
|
|
f.write(self.text_edit.toPlainText())
|
|
|
|
|
|
|
|
|
|
self.current_file_path = file_path
|
|
|
|
|
self.is_modified = False
|
|
|
|
|
|