Add caching logging packaging and annotation management

This commit is contained in:
2026-06-29 15:26:55 +08:00
parent d34529c7bf
commit 736f9249b9
11 changed files with 303 additions and 25 deletions
+65
View File
@@ -422,6 +422,68 @@ class MainWindow(QMainWindow):
else:
QMessageBox.warning(self, "填写失败", "没有找到对应的表单字段。")
def show_annotations(self) -> None:
if not self._ensure_document():
return
annotations = self.document.annotations()
if not annotations:
QMessageBox.information(self, "注释列表", "当前 PDF 没有注释。")
return
dialog = QDialog(self)
dialog.setWindowTitle("注释列表")
layout = QVBoxLayout(dialog)
annotation_list = QListWidget()
for annotation in annotations:
content = annotation.content or annotation.annotation_type
item = QListWidgetItem(
f"第 {annotation.page_index + 1} 页 {annotation.annotation_type} {content}"
)
item.setData(Qt.ItemDataRole.UserRole, annotation)
annotation_list.addItem(item)
layout.addWidget(annotation_list)
buttons = QDialogButtonBox(
QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Close
)
buttons.button(QDialogButtonBox.StandardButton.Ok).setText("跳转")
delete_button = buttons.addButton("删除", QDialogButtonBox.ButtonRole.ActionRole)
buttons.accepted.connect(dialog.accept)
buttons.rejected.connect(dialog.reject)
layout.addWidget(buttons)
deleted = {"value": False}
def delete_selected_annotation() -> None:
item = annotation_list.currentItem()
if not item:
return
annotation = item.data(Qt.ItemDataRole.UserRole)
reply = QMessageBox.question(
self,
"删除注释",
"确定删除选中的注释吗?",
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
)
if reply == QMessageBox.StandardButton.Yes:
self.document.delete_annotation(annotation.page_index, annotation.xref)
self.viewer.render()
self.statusBar().showMessage("注释已删除,记得保存", 3000)
deleted["value"] = True
dialog.accept()
delete_button.clicked.connect(delete_selected_annotation)
result = dialog.exec()
if deleted["value"]:
return
item = annotation_list.currentItem()
if not item:
return
annotation = item.data(Qt.ItemDataRole.UserRole)
if result == QDialog.DialogCode.Accepted:
self.viewer.go_to_page(annotation.page_index)
def go_to_page_dialog(self) -> None:
if not self._ensure_document():
return
@@ -519,6 +581,7 @@ class MainWindow(QMainWindow):
self.metadata_action = QAction("文档信息", self)
self.metadata_action.setShortcut(QKeySequence("Ctrl+I"))
self.form_fill_action = QAction("填写表单", self)
self.annotation_list_action = QAction("注释列表", self)
self.highlight_action = QAction("高亮", self)
self.highlight_action.setShortcut(QKeySequence("Ctrl+H"))
self.underline_action = QAction("下划线", self)
@@ -571,6 +634,7 @@ class MainWindow(QMainWindow):
tools_menu.addAction(self.images_to_pdf_action)
tools_menu.addAction(self.metadata_action)
tools_menu.addAction(self.form_fill_action)
tools_menu.addAction(self.annotation_list_action)
edit_menu = self.menuBar().addMenu("编辑")
edit_menu.addAction(self.highlight_action)
@@ -647,6 +711,7 @@ class MainWindow(QMainWindow):
self.images_to_pdf_action.triggered.connect(self.images_to_pdf)
self.metadata_action.triggered.connect(self.edit_metadata)
self.form_fill_action.triggered.connect(self.fill_form_field)
self.annotation_list_action.triggered.connect(self.show_annotations)
self.highlight_action.triggered.connect(self.highlight_current_page)
self.underline_action.triggered.connect(self.underline_current_page)
self.strikeout_action.triggered.connect(self.strikeout_current_page)