This commit is contained in:
douboer
2025-09-07 12:39:28 +08:00
parent 1ba01e3c64
commit 4d033257fe
5714 changed files with 15866 additions and 1032 deletions

View File

@@ -18,7 +18,6 @@ from cover_mixin import CoverMixin
from finished_books_mixin import FinishedBooksMixin
class ConfigDialog(QDialog):
def __init__(self, parent=None):
super().__init__(parent)
@@ -111,6 +110,12 @@ class IBookExportApp(CoverMixin, FinishedBooksMixin, QWidget):
# ====== 信号 ======
self.export_btn.clicked.connect(self.export_notes)
self.config_btn.clicked.connect(self.show_config)
# iPad 数据包导出按钮
if hasattr(self, 'ipad_export_btn'):
try:
self.ipad_export_btn.clicked.connect(self.export_ipad_bundle)
except Exception:
pass
self.listwidget.currentRowChanged.connect(self.update_book_info)
self.listwidget.installEventFilter(self)
# ====== 封面标签 ======
@@ -159,6 +164,11 @@ class IBookExportApp(CoverMixin, FinishedBooksMixin, QWidget):
lab.setAlignment(_QtAlign.AlignmentFlag.AlignHCenter | _QtAlign.AlignmentFlag.AlignTop)
except Exception:
pass
# 应用全局字体(含苹方支持)
try:
self._apply_global_font()
except Exception:
pass
# 初始封面 + 首本书信息 (及 AI 简评触发)
self._load_initial()
# 已读书籍网格
@@ -399,11 +409,28 @@ class IBookExportApp(CoverMixin, FinishedBooksMixin, QWidget):
self.exporter.export_booksnote_to_md(selected_booksnote, selected_booksinfo, out_path)
QMessageBox.information(self, "导出成功", f"已导出到:{out_path}")
def export_ipad_bundle(self):
"""导出 iPad 数据包 ZIP。"""
try:
from ipad_bundle_export import export_ipad_bundle
ts = datetime.datetime.now().strftime('%Y%m%d_%H%M%S')
out_dir = getattr(config, 'EXPORT_NOTES_DIR', os.getcwd())
os.makedirs(out_dir, exist_ok=True)
out_path = os.path.join(out_dir, f'ipad_bundle_{ts}.zip')
export_ipad_bundle(out_path, self.manager, self.exporter)
QMessageBox.information(self, '完成', f'iPad 数据包已生成:\n{out_path}')
except Exception as e:
QMessageBox.critical(self, '错误', f'导出 iPad 数据包失败: {e}')
def show_config(self):
dlg = ConfigDialog(self)
if dlg.exec():
dlg.get_config()
QMessageBox.information(self, "提示", "配置已更新(仅本次运行有效)")
try:
self._apply_global_font()
except Exception as e:
print('字体刷新失败:', e)
def update_book_info(self, row):
if row < 0:
@@ -521,7 +548,43 @@ class IBookExportApp(CoverMixin, FinishedBooksMixin, QWidget):
self._relayout_finished_grid()
except Exception:
pass
super().resizeEvent(event)
# ---------------- 全局字体应用(含苹方别名) ----------------
def _apply_global_font(self):
try:
from PyQt6.QtGui import QFontDatabase, QFont
from PyQt6.QtWidgets import QApplication
fam_cfg = getattr(config, 'FONT_FAMILY', None)
size = int(getattr(config, 'FONT_SIZE', 14))
candidates_cfg = list(getattr(config, 'FONT_CANDIDATES', []))
# 如果用户直接输入 'PingFang' 统一展开具体系列供匹配
extra_pingfang = ['PingFang SC','PingFang TC','PingFang HK']
expanded = []
if fam_cfg and fam_cfg.lower().startswith('pingfang'):
expanded.extend(extra_pingfang)
# 去重保持顺序
seen = set()
def add_seq(seq):
for f in seq:
if f and f not in seen:
seen.add(f); expanded.append(f)
add_seq([fam_cfg])
add_seq(expanded)
add_seq(candidates_cfg)
available = set(QFontDatabase.families())
chosen = None
for f in expanded:
if f in available:
chosen = f; break
if not chosen:
print('[字体] 无可用字体,放弃')
return
font = QFont(chosen, size)
QApplication.instance().setFont(font)
self.setFont(font)
print(f'[字体] 应用 {chosen} {size}px')
except Exception as e:
print('全局字体应用失败:', e)
def _build_book_html(self, review_text: str) -> str:
"""构建包含加粗紫红色标题的 HTML 内容AI书评分段显示。"""