81 lines
2.0 KiB
Python
81 lines
2.0 KiB
Python
|
|
"""
|
||
|
|
浏览视图演示脚本
|
||
|
|
|
||
|
|
展示分类浏览功能的使用方法
|
||
|
|
"""
|
||
|
|
|
||
|
|
import sys
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
# 添加项目路径
|
||
|
|
sys.path.insert(0, str(Path(__file__).parent.parent))
|
||
|
|
|
||
|
|
from PyQt6.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QWidget
|
||
|
|
from PyQt6.QtCore import Qt
|
||
|
|
|
||
|
|
from src.models.database import init_database, get_db
|
||
|
|
from src.gui.widgets.browse_view import BrowseView
|
||
|
|
|
||
|
|
|
||
|
|
class BrowseDemoWindow(QMainWindow):
|
||
|
|
"""浏览视图演示窗口"""
|
||
|
|
|
||
|
|
def __init__(self):
|
||
|
|
super().__init__()
|
||
|
|
|
||
|
|
# 初始化数据库
|
||
|
|
db_path = "sqlite:////home/congsh/CodeSpace/ClaudeSpace/CutThenThink/data/cutnthink.db"
|
||
|
|
init_database(db_path)
|
||
|
|
|
||
|
|
self.setup_ui()
|
||
|
|
|
||
|
|
def setup_ui(self):
|
||
|
|
"""设置UI"""
|
||
|
|
self.setWindowTitle("CutThenThink - 分类浏览演示")
|
||
|
|
self.setMinimumSize(1000, 700)
|
||
|
|
self.resize(1200, 800)
|
||
|
|
|
||
|
|
# 创建中央组件
|
||
|
|
central_widget = QWidget()
|
||
|
|
self.setCentralWidget(central_widget)
|
||
|
|
|
||
|
|
# 布局
|
||
|
|
layout = QVBoxLayout(central_widget)
|
||
|
|
layout.setContentsMargins(0, 0, 0, 0)
|
||
|
|
layout.setSpacing(0)
|
||
|
|
|
||
|
|
# 创建浏览视图
|
||
|
|
self.browse_view = BrowseView()
|
||
|
|
layout.addWidget(self.browse_view)
|
||
|
|
|
||
|
|
# 连接信号
|
||
|
|
self.browse_view.record_modified.connect(self.on_record_modified)
|
||
|
|
self.browse_view.record_deleted.connect(self.on_record_deleted)
|
||
|
|
|
||
|
|
def on_record_modified(self, record_id: int):
|
||
|
|
"""记录被修改"""
|
||
|
|
print(f"记录 {record_id} 已被修改")
|
||
|
|
|
||
|
|
def on_record_deleted(self, record_id: int):
|
||
|
|
"""记录被删除"""
|
||
|
|
print(f"记录 {record_id} 已被删除")
|
||
|
|
|
||
|
|
|
||
|
|
def main():
|
||
|
|
"""主函数"""
|
||
|
|
# 创建应用
|
||
|
|
app = QApplication(sys.argv)
|
||
|
|
app.setApplicationName("CutThenThink")
|
||
|
|
app.setOrganizationName("CutThenThink")
|
||
|
|
|
||
|
|
# 创建并显示主窗口
|
||
|
|
window = BrowseDemoWindow()
|
||
|
|
window.show()
|
||
|
|
|
||
|
|
# 运行应用
|
||
|
|
sys.exit(app.exec())
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
main()
|