feat: 实现CutThenThink P0阶段核心功能

项目初始化
- 创建完整项目结构(src/, data/, docs/, examples/, tests/)
- 配置requirements.txt依赖
- 创建.gitignore

P0基础框架
- 数据库模型:Record模型,6种分类类型
- 配置管理:YAML配置,支持AI/OCR/云存储/UI配置
- OCR模块:PaddleOCR本地识别,支持云端扩展
- AI模块:支持OpenAI/Claude/通义/Ollama,6种分类
- 存储模块:完整CRUD,搜索,统计,导入导出
- 主窗口框架:侧边栏导航,米白配色方案
- 图片处理:截图/剪贴板/文件选择/图片预览
- 处理流程整合:OCR→AI→存储串联,Markdown展示,剪贴板复制
- 分类浏览:卡片网格展示,分类筛选,搜索,详情查看

技术栈
- PyQt6 + SQLAlchemy + PaddleOCR + OpenAI/Claude SDK
- 共47个Python文件,4000+行代码

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
congsh
2026-02-11 18:21:31 +08:00
commit c4a77f8aa4
79 changed files with 19412 additions and 0 deletions

170
examples/storage_example.py Normal file
View File

@@ -0,0 +1,170 @@
"""
存储模块使用示例
演示常见的使用场景
"""
import sys
from pathlib import Path
# 添加项目根目录到路径
project_root = Path(__file__).parent.parent
sys.path.insert(0, str(project_root))
from src.core.storage import Storage
def example_basic_usage():
"""基本使用示例"""
print("=" * 60)
print("示例 1: 基本使用")
print("=" * 60)
storage = Storage()
# 创建几条笔记
storage.create(
title="项目会议记录",
content="讨论了新功能的设计方案",
category="工作",
tags=["会议", "重要"]
)
storage.create(
title="Python 学习笔记",
content="今天学习了列表推导式和装饰器",
category="学习",
tags=["Python", "编程"]
)
storage.create(
title="周末计划",
content="周六去图书馆,周日看电影",
category="生活"
)
# 查看所有笔记
all_notes = storage.get_all()
print(f"\n总共有 {len(all_notes)} 条笔记:")
for note in all_notes:
print(f"{note['title']} [{note['category']}]")
def example_search():
"""搜索示例"""
print("\n" + "=" * 60)
print("示例 2: 搜索功能")
print("=" * 60)
storage = Storage()
# 搜索包含"Python"的笔记
results = storage.search("Python")
print(f"\n搜索 'Python' 找到 {len(results)} 条结果:")
for note in results:
print(f"{note['title']}")
# 搜索包含"会议"的笔记
results = storage.search("会议")
print(f"\n搜索 '会议' 找到 {len(results)} 条结果:")
for note in results:
print(f"{note['title']}")
def example_category_management():
"""分类管理示例"""
print("\n" + "=" * 60)
print("示例 3: 分类管理")
print("=" * 60)
storage = Storage()
# 查看所有分类
categories = storage.get_categories()
print(f"\n所有分类 ({len(categories)} 个):")
for category in categories:
count = len(storage.get_by_category(category))
print(f"{category} ({count} 条笔记)")
# 按分类查看笔记
print("\n工作分类下的笔记:")
work_notes = storage.get_by_category("工作")
for note in work_notes:
print(f"{note['title']}")
def example_update_and_delete():
"""更新和删除示例"""
print("\n" + "=" * 60)
print("示例 4: 更新和删除")
print("=" * 60)
storage = Storage()
# 获取第一条笔记
all_notes = storage.get_all()
if all_notes:
first_note = all_notes[0]
print(f"\n原始标题: {first_note['title']}")
# 更新标题
updated = storage.update(
first_note['id'],
title=f"{first_note['title']}(已编辑)"
)
print(f"更新后标题: {updated['title']}")
# 删除最后一条笔记
if len(all_notes) > 1:
last_note = all_notes[-1]
storage.delete(last_note['id'])
print(f"\n已删除: {last_note['title']}")
def example_statistics():
"""统计信息示例"""
print("\n" + "=" * 60)
print("示例 5: 统计信息")
print("=" * 60)
storage = Storage()
stats = storage.get_stats()
print(f"\n📊 笔记统计:")
print(f" • 总记录数: {stats['total_records']}")
print(f" • 总分类数: {stats['total_categories']}")
print(f"\n各分类记录数:")
for category, count in stats['categories'].items():
print(f"{category}: {count}")
def example_backup():
"""备份示例"""
print("\n" + "=" * 60)
print("示例 6: 数据备份")
print("=" * 60)
storage = Storage()
# 导出所有数据
data = storage.export_data()
print(f"\n导出 {len(data)} 条记录")
# 可以保存到备份文件
backup_file = Path("/tmp/notes_backup.json")
import json
with open(backup_file, 'w', encoding='utf-8') as f:
json.dump(data, f, ensure_ascii=False, indent=2)
print(f"备份已保存到: {backup_file}")
if __name__ == "__main__":
# 运行所有示例
example_basic_usage()
example_search()
example_category_management()
example_update_and_delete()
example_statistics()
example_backup()
print("\n" + "=" * 60)
print("所有示例运行完成!")
print("=" * 60)