de306ffe by 柴进

feat(ui): 接入主入口 + 迁移 LoginDialog/ImageGeneratorWindow 样式

- main() 创建 QApplication 后立即 apply_theme,所有后续 widget(含 preflight QMessageBox)都吃全局主题
- LoginDialog: 删 80 行 inline QSS 块,objectName=loginDialog/loginTitle,主按钮 variant=primary,error_label status property
- ImageGeneratorWindow: 删 50 行 apply_styles QSS 块,删 30 处 inline setStyleSheet
- "生成图片" 主按钮 variant=primary(pill 圆角 + accent 实色背景)
- status_label 全部用 _set_status(success|warning|danger|info|muted) helper
- DragDropScrollArea 拖拽态走 drag_state property(idle/active)
- 缩略图 role=thumb/thumb_index,删除按钮 #thumbDeleteBtn variant=danger
- generated_image_label has_image property,"已复制" success-flash variant
- preview_label/prompt_display 走 objectName + 全局 QSS

剩余:StyleDesignerTab 和 task_queue.py。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 3bc29f7b
1 ## Design Document: Image History Management
2
3 ### Context
4 当前应用缺乏图片历史记录功能,用户生成图片后需要手动下载和管理。需要实现自动保存、管理和查看历史生成记录的功能,提升用户体验和工作效率。
5
6 ### Goals / Non-Goals
7 **Goals:**
8 - 自动保存所有生成的图片和相关元数据
9 - 提供直观的历史记录浏览界面
10 - 支持从历史记录快速重新加载图片
11 - 保持与现有功能的完全兼容
12
13 **Non-Goals:**
14 - 不实现云同步功能(纯本地存储)
15 - 不修改现有图片生成核心逻辑
16 - 不依赖外部数据库或复杂依赖
17
18 ### Decisions
19
20 #### 1. 存储架构
21 **Decision**: 使用文件系统 + JSON索引的轻量级存储方案
22 - **Why**: 避免引入重型数据库依赖,保持应用轻量化
23 - **Alternatives considered**: SQLite数据库, Redis缓存, 文件系统-only方案
24 - **Chosen approach**: `/images/YYYYMMDDHHMMSS/` 目录结构 + 全局 `history_index.json`
25
26 #### 2. 数据结构设计
27 **Decision**: 采用分层存储结构
28 ```
29 /images/
30 ├── history_index.json # 全局索引文件
31 └── 20241201123456/ # 按时间戳的目录
32 ├── metadata.json # 该会话的元数据
33 ├── generated.png # 生成的图片
34 ├── reference1.jpg # 参考图片1
35 └── reference2.jpg # 参考图片2
36 ```
37
38 #### 3. UI集成方案
39 **Decision**: 在现有主界面添加"历史记录"标签页
40 - **Why**: 保持界面一致性,最小化学习成本
41 - **Alternatives considered**: 独立历史记录窗口, 侧边栏集成, 右键菜单
42
43 #### 4. 性能优化策略
44 **Decision**: 延迟加载和缩略图缓存
45 - 历史记录列表只加载基本信息和缩略图
46 - 点击时才加载完整图片
47 - 实现缩略图缓存机制
48
49 ### Risks / Trade-offs
50 - **[磁盘空间使用]** → 添加用户配置选项:最大历史记录数量限制
51 - **[大量历史记录性能]** → 实现分页加载和虚拟滚动
52 - **[跨平台路径处理]** → 使用 `pathlib.Path` 确保跨平台兼容性
53 - **[UI响应性]** → 使用异步加载避免界面冻结
54
55 ### Migration Plan
56 1. **Phase 1**: 实现 `HistoryManager` 类和基础存储逻辑
57 2. **Phase 2**: 修改现有图片生成流程,添加自动保存
58 3. **Phase 3**: 开发历史记录界面和交互功能
59 4. **Phase 4**: 添加配置选项和性能优化
60
61 **Rollback plan**: 所有功能都是增量添加,移除新功能不会影响现有系统稳定性。
62
63 ### Open Questions
64 - 历史记录的默认数量上限应该是多少?
65 - 是否需要历史记录的搜索功能?
66 - 是否需要支持历史记录的导入/导出?
67 - 如何处理参考图片的版权和隐私问题?
68
69 ### Technical Architecture Details
70
71 #### HistoryManager Class Structure
72 ```python
73 class HistoryManager:
74 def __init__(self, base_path: Path)
75 def save_generation(self, image_bytes, prompt, references, params)
76 def load_history_index(self) -> List[HistoryItem]
77 def get_history_item(self, timestamp: str) -> HistoryItem
78 def delete_history_item(self, timestamp: str) -> bool
79 def cleanup_old_records(self, max_count: int)
80 ```
81
82 #### Data Models
83 ```python
84 @dataclass
85 class HistoryItem:
86 timestamp: str
87 prompt: str
88 generated_image_path: Path
89 reference_image_paths: List[Path]
90 aspect_ratio: str
91 image_size: str
92 model: str
93 created_at: datetime
94 ```
95
96 #### Integration Points
97 - **ImageGenerationWorker**: 修改 `on_image_generated` 回调
98 - **ImageGeneratorWindow**: 添加历史记录标签页和相关UI组件
99 - **Configuration**: 扩展 `config.json` 添加历史记录相关配置
...\ No newline at end of file ...\ No newline at end of file
1 # Change: Add Image History Management
2
3 ## Why
4 用户需要一个图片历史记录功能来管理和查看之前生成的图片,目前每次生成图片后都需要手动下载,缺乏历史记录管理和本地图片库功能。
5
6 ## What Changes
7 - 添加图片自动下载功能:在图片生成成功后自动保存到本地 `/images/` 目录
8 - 创建历史记录管理系统:按时间戳存储图片和相关元数据(prompt、参考图等)
9 - 新增历史记录界面:在主界面添加历史记录标签页,展示所有历史生成记录
10 - 实现本地图片加载:允许用户点击历史记录中的缩略图来加载和查看完整图片
11
12 ## Impact
13 - **Affected specs**:
14 - `image-generation` (MODIFIED: 添加自动下载和历史记录保存)
15 - `user-interface` (MODIFIED: 添加历史记录标签页)
16 - **Affected code**:
17 - `image_generator.py:937-944` (修改 `on_image_generated` 方法添加自动保存)
18 - `image_generator.py:1002-1020` (修改 `download_image` 方法)
19 - 新增 `HistoryManager` 类和相关历史记录管理逻辑
20 - 主界面UI修改:添加历史记录标签页和展示组件
...\ No newline at end of file ...\ No newline at end of file
1 ## ADDED Requirements
2
3 ### Requirement: Automatic Image History Storage
4 The system SHALL automatically save all generated images and their metadata to local storage when image generation is successful.
5
6 #### Scenario: Image generation auto-save
7 - **WHEN** image generation is completed successfully
8 - **THEN** the system SHALL automatically save the generated image to a timestamped directory
9 - **AND** save the prompt text and generation parameters
10 - **AND** copy any reference images used
11 - **AND** update the global history index
12
13 #### Scenario: Directory structure creation
14 - **WHEN** creating a new history record
15 - **THEN** the system SHALL create a directory named with YYYYMMDDHHMMSS timestamp format
16 - **AND** ensure the directory structure is: `/images/{timestamp}/generated.png, reference1.jpg, reference2.jpg, metadata.json`
17
18 ### Requirement: History Record Management
19 The system SHALL provide functionality to manage and browse image generation history.
20
21 #### Scenario: History index loading
22 - **WHEN** the application starts or the history tab is opened
23 - **THEN** the system SHALL load the history index from `history_index.json`
24 - **AND** display a list of all historical generation records sorted by timestamp
25
26 #### Scenario: History record deletion
27 - **WHEN** the user selects a history record and chooses to delete it
28 - **THEN** the system SHALL remove the record from the index
29 - **AND** delete the corresponding directory and all its files
30 - **AND** confirm the deletion action with the user
31
32 ### Requirement: History Browser Interface
33 The system SHALL provide a user interface to browse and interact with image generation history.
34
35 #### Scenario: History list display
36 - **WHEN** the history tab is opened
37 - **THEN** the system SHALL display a list of historical records
38 - **AND** show thumbnail previews of generated images
39 - **AND** display prompt text, generation date, and parameters for each record
40
41 #### Scenario: History item selection
42 - **WHEN** the user clicks on a history item
43 - **THEN** the system SHALL load the corresponding image into the main preview area
44 - **AND** display the original prompt text in the prompt input field
45 - **AND** restore the generation parameters (aspect ratio, size, model)
46
47 ### Requirement: Local Image Loading
48 The system SHALL enable loading previously generated images from local history.
49
50 #### Scenario: Load image from history
51 - **WHEN** a history item is selected
52 - **THEN** the system SHALL load the full-resolution image from local storage
53 - **AND** display it in the preview area with the same functionality as newly generated images
54 - **AND** enable download and full-screen viewing options
55
56 #### Scenario: Reference image restoration
57 - **WHEN** loading a history item that had reference images
58 - **THEN** the system SHALL display the reference images in the reference area
59 - **AND** allow the user to modify or remove them before generating new images
60
61 ### Requirement: Configuration and Settings
62 The system SHALL provide configuration options for history management.
63
64 #### Scenario: History storage location
65 - **WHEN** the application starts
66 - **THEN** the system SHALL create the images directory in the application's data directory
67 - **AND** allow users to configure a custom storage location through settings
68
69 #### Scenario: History limits configuration
70 - **WHEN** the number of history records exceeds the configured limit
71 - **THEN** the system SHALL automatically remove the oldest records
72 - **AND** provide user settings to configure the maximum number of history records
73
74 ### Requirement: History Data Persistence
75 The system SHALL ensure history data persists across application sessions.
76
77 #### Scenario: Data persistence
78 - **WHEN** the application is closed and reopened
79 - **THEN** the system SHALL preserve all saved history records
80 - **AND** maintain the same directory structure and file organization
81 - **AND** recover gracefully if the history index file is corrupted
82
83 ## MODIFIED Requirements
84
85 ### Requirement: Image Generation Workflow
86 The system SHALL integrate history saving into the existing image generation workflow.
87
88 #### Scenario: Enhanced image generation completion
89 - **WHEN** image generation is completed successfully
90 - **THEN** the system SHALL perform all existing success behaviors (display image, enable download)
91 - **AND** additionally save the image and metadata to local history
92 - **AND** update the history index with the new record
93
94 #### Scenario: Error handling in history saving
95 - **WHEN** history saving encounters an error
96 - **THEN** the system SHALL not affect the image generation success state
97 - **AND** log the error without interrupting user experience
98 - **AND** continue with normal image display and download functionality
...\ No newline at end of file ...\ No newline at end of file
1 ## 1. 核心数据结构和存储
2 - [x] 1.1 创建 `HistoryManager` 类,负责历史记录的管理
3 - [x] 1.2 设计历史记录数据结构:时间戳、prompt、参考图路径、生成图路径
4 - [x] 1.3 实现本地文件存储逻辑:`/images/YYYYMMDDHHMMSS/` 目录结构
5 - [x] 1.4 创建历史记录索引文件 `history_index.json`
6
7 ## 2. 图片自动下载和保存
8 - [x] 2.1 修改 `on_image_generated()` 方法,在生成成功后自动保存图片
9 - [x] 2.2 实现参考图片的本地复制和保存
10 - [x] 2.3 创建元数据文件 `metadata.json` 保存prompt和参数信息
11 - [x] 2.4 更新历史记录索引文件
12
13 ## 3. 历史记录管理功能
14 - [x] 3.1 实现 `HistoryManager.load_history()` 方法加载历史记录
15 - [x] 3.2 实现 `HistoryManager.get_history_item()` 方法获取单个历史记录
16 - [x] 3.3 实现 `HistoryManager.delete_history_item()` 方法删除历史记录
17 - [x] 3.4 实现历史记录的搜索和过滤功能
18
19 ## 4. 历史记录界面开发
20 - [x] 4.1 在主界面添加"历史记录"标签页
21 - [x] 4.2 创建历史记录列表组件,显示缩略图和基本信息
22 - [x] 4.3 实现历史记录项的点击加载功能
23 - [x] 4.4 添加历史记录的右键菜单(删除、导出等)
24
25 ## 5. 图片展示和交互
26 - [x] 5.1 实现从历史记录加载图片到预览区域
27 - [x] 5.2 创建历史记录详情查看功能(显示完整prompt、参数等)
28 - [x] 5.3 实现历史记录图片的双击全屏查看
29 - [x] 5.4 添加历史记录图片的批量导出功能
30
31 ## 6. 配置和设置
32 - [x] 6.1 添加历史记录存储路径配置选项
33 - [x] 6.2 实现历史记录数量限制和自动清理设置
34 - [x] 6.3 添加历史记录功能的启用/禁用开关
35
36 ## 7. 测试和验证
37 - [x] 7.1 测试图片生成后自动保存到历史记录
38 - [x] 7.2 测试历史记录界面的加载和显示
39 - [x] 7.3 测试从历史记录加载图片功能
40 - [x] 7.4 测试历史记录的删除和清理功能
41 - [x] 7.5 验证大量历史记录下的性能表现
42
43 ## 8. 文档和部署
44 - [ ] 8.1 更新README.md,添加历史记录功能说明
45 - [ ] 8.2 创建历史记录功能的使用指南
46 - [ ] 8.3 测试在不同操作系统下的兼容性
...\ No newline at end of file ...\ No newline at end of file
1 ## Design Document: Simple Logging System
2
3 ### Context
4 当前应用缺乏基本的日志记录功能,当出现问题时难以诊断。需要建立简单实用的日志系统来记录关键事件和错误信息。
5
6 ### Goals / Non-Goals
7 **Goals:**
8 - 提供基本的日志记录功能
9 - 记录关键操作和错误信息
10 - 实现简单的日志文件管理
11 - 使用标准库,保持简单
12 - 帮助快速定位和解决问题
13
14 **Non-Goals:**
15 - 不实现复杂的日志分析功能
16 - 不集成第三方日志服务
17 - 不实现实时日志监控
18 - 不设计复杂的日志分类系统
19
20 ### Decisions
21
22 #### 1. 日志框架选择
23 **Decision**: 使用 Python 标准库 `logging` 模块
24 - **Why**: 标准库提供足够的基础功能,无额外依赖
25 - **Alternatives considered**: print语句、简单的文件写入
26 - **Chosen approach**: Python logging + 基础配置
27
28 #### 2. 日志文件结构
29 **Decision**: 单一日志文件
30 ```
31 logs/
32 └── app.log # 统一的应用日志文件
33 ```
34
35 #### 3. 日志轮转策略
36 **Decision**: 基于文件大小的简单轮转
37 - 最大文件大小:10MB
38 - 保留最近 5 个历史文件
39 - 不使用压缩,保持简单
40
41 #### 4. 日志级别策略
42 - **INFO**: 记录正常操作流程
43 - **WARNING**: 记录潜在问题
44 - **ERROR**: 记录操作失败和错误
45 - **DEBUG**: 开发时可启用详细信息
46
47 ### Technical Architecture Details
48
49 #### 简化的日志系统
50 ```
51 SimpleLogger
52 ├── 初始化基础配置
53 ├── 创建单一logger
54 ├── 设置简单格式化器
55 └── 实现基础轮转
56
57 格式化器
58 ├── 时间戳
59 ├── 日志级别
60 ├── 模块名称
61 └── 消息内容
62 ```
63
64 #### 关键日志记录点
65 1. **应用启动**: 应用启动、配置加载
66 2. **用户认证**: 登录成功/失败、认证错误
67 3. **配置操作**: 配置文件读取错误
68 4. **数据库连接**: 连接成功/失败、查询错误
69 5. **图片生成**: API调用成功/失败、生成错误
70 6. **文件操作**: 图片保存成功/失败、历史记录错误
71
72 #### 性能考虑
73 - 使用标准库的优化性能
74 - 简单格式减少格式化开销
75 - 合理的轮转避免大文件问题
76 - 关键操作才记录,避免过度日志
77
78 ### Integration Points
79
80 #### 模块集成
81 - **DatabaseManager**: 添加基础数据库日志
82 - **ImageGeneratorWindow**: 添加关键操作日志
83 - **ImageGenerationWorker**: 添加生成过程日志
84 - **HistoryManager**: 添加文件操作日志
85
86 #### 配置集成
87 ```json
88 {
89 "logging": {
90 "enabled": true,
91 "level": "INFO",
92 "max_file_size_mb": 10
93 }
94 }
95 ```
96
97 ### Implementation Plan
98 1. **Step 1**: 创建简单的日志初始化函数
99 2. **Step 2**: 集成到 DatabaseManager
100 3. **Step 3**: 集成到图片生成模块
101 4. **Step 4**: 集成到错误处理
102 5. **Step 5**: 测试和验证
103
104 ### Design Principles
105 - 简单实用:只记录必要信息
106 - 不影响性能:关键操作才记录
107 - 易于查看:日志文件直接可读
108 - 维护简单:最小化代码复杂度
...\ No newline at end of file ...\ No newline at end of file
1 # Change: Add Simple Logging System
2
3 ## Why
4 当前应用缺乏基本的日志记录功能,当用户遇到API错误、配置问题、图片生成失败等情况时,开发者无法获得基本的诊断信息。添加简单的日志系统将帮助快速定位和解决常见问题。
5
6 ## What Changes
7 - 添加简单的日志记录功能,统一输出到 `logs/app.log`
8 - 记录关键事件:应用启动、用户登录、图片生成、错误信息
9 - 使用标准Python logging模块,保持简单实用
10 - 实现基本的日志文件轮转(大小限制)
11 - 记录基本的错误信息和操作状态
12
13 ## Impact
14 - **Affected specs**:
15 - `logging-system` (ADDED: 基础日志记录功能)
16 - `error-handling` (MODIFIED: 添加基本错误日志)
17 - `user-operations` (MODIFIED: 记录关键操作日志)
18 - **Affected code**:
19 - 全局添加简单日志初始化
20 - DatabaseManager 类添加基础数据库日志
21 - ImageGeneratorWindow 类添加关键操作日志
22 - ImageGenerationWorker 类添加生成过程日志
23 - 主要错误处理函数添加日志记录
...\ No newline at end of file ...\ No newline at end of file
1 ## ADDED Requirements
2
3 ### Requirement: Simple Logging System
4 The system SHALL provide a simple logging system that records key application events and errors for basic troubleshooting.
5
6 #### Scenario: Application initialization logging
7 - **WHEN** the application starts
8 - **THEN** the system SHALL log startup information and configuration loading
9 - **AND** SHALL record logging system initialization
10 - **AND** SHALL note the application version and platform
11
12 #### Scenario: Basic logging classification
13 - **WHEN** logging events occur
14 - **THEN** the system SHALL categorize logs into appropriate levels (INFO, WARNING, ERROR, DEBUG)
15 - **AND** SHALL write all logs to a single app.log file
16 - **AND** SHALL maintain consistent formatting across log entries
17
18 ### Requirement: Basic Log File Management
19 The system SHALL implement simple log file management with size-based rotation.
20
21 #### Scenario: Log file creation and rotation
22 - **WHEN** the application starts
23 - **THEN** the system SHALL create a logs/ directory in the application folder
24 - **AND** SHALL create a single app.log file for all logs
25 - **AND** SHALL implement file rotation when file reaches 10MB size limit
26 - **AND** SHALL keep the 5 most recent log files
27
28 ### Requirement: Database Operation Logging
29 The system SHALL record basic database-related operations for simple debugging.
30
31 #### Scenario: Database connection logging
32 - **WHEN** attempting to connect to the database
33 - **THEN** the system SHALL log connection attempts and results
34 - **AND** SHALL record basic database information
35 - **AND** SHALL log connection failures with error messages
36
37 #### Scenario: Database error logging
38 - **WHEN** database operations fail
39 - **THEN** the system SHALL log the error type and basic information
40 - **AND** SHALL record the operation that failed
41 - **AND** SHALL avoid logging sensitive database data
42
43 ### Requirement: User Operation Logging
44 The system SHALL log key user actions for troubleshooting user experience issues.
45
46 #### Scenario: User authentication logging
47 - **WHEN** users attempt to log in
48 - **THEN** the system SHALL log login attempts and results
49 - **AND** SHALL record authentication failures with basic error info
50 - **AND** SHALL not log sensitive user credentials
51
52 #### Scenario: Image generation logging
53 - **WHEN** users generate images
54 - **THEN** the system SHALL log generation requests and basic parameters
55 - **AND** SHALL record API call results
56 - **AND** SHALL log generation failures with error information
57
58 ### Requirement: Error Handling Logging
59 The system SHALL provide basic error logging for troubleshooting common issues.
60
61 #### Scenario: Basic exception logging
62 - **WHEN** key exceptions occur
63 - **THEN** the system SHALL log the exception type and message
64 - **AND** SHALL record the operation context
65 - **AND** SHALL avoid overly detailed stack traces
66
67 #### Scenario: Configuration error logging
68 - **WHEN** configuration loading fails
69 - **THEN** the system SHALL log the configuration error
70 - **AND** SHALL record the file path and error details
71 - **AND** SHALL provide fallback behavior information
72
73 ### Requirement: Simple Configuration
74 The system SHALL provide basic logging configuration options.
75
76 #### Scenario: Logging configuration management
77 - **WHEN** the application starts
78 - **THEN** the system SHALL load logging settings from config.json
79 - **AND** SHALL support enabling/disabling the logging system
80 - **AND** SHALL support basic log level configuration
81
82 #### Scenario: Log level control
83 - **WHEN** different logging needs arise
84 - **THEN** the system SHALL support switching between INFO, WARNING, ERROR levels
85 - **AND** SHALL allow enabling DEBUG level for development
86 - **AND** SHALL apply configuration changes immediately
87
88 ### Requirement: Cross-Platform Compatibility
89 The logging system SHALL work consistently across Windows, macOS, and Linux platforms.
90
91 #### Scenario: Simple cross-platform behavior
92 - **WHEN** running on different operating systems
93 - **THEN** the system SHALL use standard file permissions
94 - **AND** SHALL handle basic path and encoding issues
95 - **THEN** SHALL create logs in application directory
96
97 #### Scenario: Log file readability
98 - **WHEN** users need to view log files
99 - **THEN** the system SHALL ensure log files are readable by text editors
100 - **AND** SHALL use UTF-8 encoding for character support
101 - **AND** SHALL keep log format simple and clear
...\ No newline at end of file ...\ No newline at end of file
1 ## 1. 简单日志系统实现
2 - [ ] 1.1 创建简单的日志初始化函数
3 - [ ] 1.2 实现单一日志文件(logs/app.log)
4 - [ ] 1.3 设置基础日志格式化器
5 - [ ] 1.4 实现简单的文件轮转(10MB大小限制)
6 - [ ] 1.5 创建 logs/ 目录
7
8 ## 2. 基础日志级别
9 - [ ] 2.1 实现 INFO、WARNING、ERROR 三个主要级别
10 - [ ] 2.2 可选 DEBUG 级别用于开发调试
11 - [ ] 2.3 实现简单的日志级别控制
12 - [ ] 2.4 添加控制台输出选项
13 - [ ] 2.5 实现日志启用/禁用开关
14
15 ## 3. 集成到关键模块
16 - [ ] 3.1 DatabaseManager 集成:记录连接状态和错误
17 - [ ] 3.2 ImageGeneratorWindow 集成:记录用户关键操作
18 - [ ] 3.3 ImageGenerationWorker 集成:记录API调用结果
19 - [ ] 3.4 HistoryManager 集成:记录文件操作状态
20 - [ ] 3.5 主函数集成:记录应用启动和退出
21
22 ## 4. 错误处理日志
23 - [ ] 4.1 为主要异常添加基本日志记录
24 - [ ] 4.2 记录关键错误信息(无需完整堆栈)
25 - [ ] 4.3 添加配置加载错误日志
26 - [ ] 4.4 记录网络和API调用错误
27 - [ ] 4.5 记录文件操作失败信息
28
29 ## 5. 配置集成
30 - [ ] 5.1 在 config.json 中添加基础日志配置
31 - [ ] 5.2 实现日志启用/禁用开关
32 - [ ] 5.3 添加日志级别配置选项
33 - [ ] 5.4 实现日志文件大小限制配置
34 - [ ] 5.5 集成日志配置到启动流程
35
36 ## 6. 基础性能优化
37 - [ ] 6.1 确保日志不阻塞主线程
38 - [ ] 6.2 只在关键操作时记录日志
39 - [ ] 6.3 使用简单的日志格式
40 - [ ] 6.4 避免过度详细的日志记录
41 - [ ] 6.5 测试日志对性能的影响
42
43 ## 7. 测试和验证
44 - [ ] 7.1 测试日志文件创建和基本写入
45 - [ ] 7.2 验证日志文件轮转功能
46 - [ ] 7.3 测试不同级别日志输出
47 - [ ] 7.4 验证错误日志记录功能
48 - [ ] 7.5 确保日志不影响正常功能
49
50 ## 8. 简单文档
51 - [ ] 8.1 创建日志系统简要说明
52 - [ ] 8.2 编写常见问题排查指南
53 - [ ] 8.3 创建日志配置说明
54 - [ ] 8.4 编写基本调试方法
55 - [ ] 8.5 更新README中的故障排查部分
...\ No newline at end of file ...\ No newline at end of file
1 ## Design Document: Standalone History Browsing Interface
2
3 ### Context
4 当前历史记录实现允许用户双击历史项目将其加载到图片生成界面,但这会干扰用户的当前工作状态。用户希望历史记录作为纯粹的浏览功能,直接在历史记录界面中查看完整信息。
5
6 ### Goals / Non-Goals
7 **Goals:**
8 - 提供独立的历史记录浏览功能
9 - 在历史记录界面直接显示prompt、参考图和生成图
10 - 支持prompt文本复制功能
11 - 保持与图片生成功能的完全隔离
12 - 提供直观的图片预览和详情展示
13
14 **Non-Goals:**
15 - 不再支持从历史记录加载到生成界面
16 - 不修改现有的图片生成工作流程
17 - 不增加复杂的编辑功能
18
19 ### Decisions
20
21 #### 1. 界面重构方案
22 **Decision**: 重新设计历史记录标签页为详情浏览模式
23 - **Why**: 避免界面间的操作干扰,提供更清晰的用户体验
24 - **Alternatives considered**: 弹窗详情、侧边栏详情页
25 - **Chosen approach**: 在历史记录标签页内实现完整的详情显示
26
27 #### 2. 信息展示布局
28 **Decision**: 采用上下布局:历史列表在上(显示生成图预览),详情展示在下
29 - **Why**: 类似文件管理器的熟悉交互模式,预览图让用户快速识别内容
30 - **Alternatives considered**: 左右分栏、全屏切换、纯列表模式
31 - **Chosen approach**: 固定比例的上下分割布局,列表项显示生成图缩略图
32
33 #### 3. 交互方式
34 **Decision**: 单击选择历史项显示详情,双击或右键提供额外操作
35 - **Why**: 提供清晰的选择反馈和操作入口
36 - **Alternatives considered**: 仅单击、仅右键菜单
37 - **Chosen approach**: 简单的单击选择 + 右键菜单操作
38
39 ### Technical Architecture Details
40
41 #### 新的UI组件结构
42 ```
43 历史记录标签页
44 ├── 工具栏 (刷新、清空、删除)
45 ├── 分割器 (QSplitter)
46 │ ├── 上部: 历史记录列表 (QListWidget)
47 │ │ ├── 每个列表项显示:
48 │ │ │ ├── 生成图片缩略图 (120x120)
49 │ │ │ ├── 时间戳
50 │ │ │ └── Prompt前20个字符
51 │ │ └── 悬停显示完整信息
52 │ └── 下部: 详情展示区域 (QWidget)
53 │ ├── Prompt区域 (QTextEdit + 复制按钮)
54 │ ├── 参数信息 (宽高比、尺寸)
55 │ ├── 参考图片区域 (QScrollArea)
56 │ └── 生成图片大预览 (QLabel)
57 ```
58
59 #### 数据流设计
60 1. **选择历史项**: 用户点击列表项 → 加载详细数据 → 更新详情区域
61 2. **复制Prompt**: 点击复制按钮 → 复制到剪贴板 → 显示成功提示
62 3. **删除操作**: 右键菜单删除 → 确认对话框 → 更新列表和详情
63
64 ### Risks / Trade-offs
65 - **[界面复杂度]** → 通过清晰的布局和分组来管理
66 - **[图片加载性能]** → 实现延迟加载和缓存机制
67 - **[用户体验]** → 提供清晰的视觉反馈和操作提示
68
69 ### Implementation Plan
70 1. **Phase 1**: 移除现有的加载到界面功能
71 2. **Phase 2**: 重新设计历史记录标签页UI
72 3. **Phase 3**: 实现详情展示功能
73 4. **Phase 4**: 添加复制和操作功能
74 5. **Phase 5**: 测试和优化
75
76 ### Open Questions
77 - 历史记录列表和详情区域的比例应该是多少?
78 - 是否需要添加历史记录的搜索功能?
79 - 如何处理大量历史记录时的性能问题?
...\ No newline at end of file ...\ No newline at end of file
1 # Change: Refactor History Browsing to Standalone Interface
2
3 ## Why
4 当前的历史记录实现会干扰原有的图片生成界面,用户希望历史记录作为一个独立的浏览界面,直接显示prompt、参考图和生成图,而不需要加载到原有界面中,避免操作冲突和界面混乱。
5
6 ## What Changes
7 - 重新设计历史记录界面为独立的详情浏览模式
8 - 移除历史记录加载到原有界面的功能
9 - 在历史记录标签页中直接显示完整信息:
10 - Prompt文本(支持复制)
11 - 参考图片缩略图
12 - 生成图片大图预览
13 - 保持两个功能完全独立,互不干扰
14
15 ## Impact
16 - **Affected specs**:
17 - `history-interface` (MODIFIED: 改为独立浏览模式)
18 - `user-interface` (MODIFIED: 移除界面间加载功能)
19 - **Affected code**:
20 - `image_generator.py:1447-1484` (移除 load_history_item 方法中加载到界面的逻辑)
21 - `image_generator.py:1033` (重新设计历史记录标签页UI)
22 - 新增独立的历史记录详情显示组件
...\ No newline at end of file ...\ No newline at end of file
1 ## MODIFIED Requirements
2
3 ### Requirement: Standalone History Browsing Interface
4 The system SHALL provide a standalone history browsing interface that displays complete information without interfering with the image generation interface.
5
6 #### Scenario: History item selection for detail viewing
7 - **WHEN** the user clicks on a history item
8 - **THEN** the system SHALL display detailed information in the details panel
9 - **AND** SHALL not modify any controls in the image generation interface
10 - **AND** SHALL show the complete prompt text, reference images, and generated image
11
12 #### Scenario: Independent interface operation
13 - **WHEN** the user switches between generation tab and history tab
14 - **THEN** the system SHALL preserve the state of each tab independently
15 - **AND** SHALL not load history data into generation controls
16 - **AND** SHALL maintain separate user contexts for each tab
17
18 ## REMOVED Requirements
19
20 ### Requirement: History Item Loading to Generation Interface
21 **Reason**: This feature interferes with the user's current work state and creates confusing interactions. Users want history as a pure browsing feature.
22
23 **Migration**: Replace with standalone detail viewing within the history tab.
24
25 ## ADDED Requirements
26
27 ### Requirement: History List with Image Previews
28 The system SHALL display generated image thumbnails directly in the history list for quick visual identification.
29
30 #### Scenario: History item thumbnail display
31 - **WHEN** the history list is loaded
32 - **THEN** the system SHALL display a 120x120 pixel thumbnail of each generated image
33 - **AND** SHALL include the timestamp and prompt preview (first 20 characters)
34 - **AND** SHALL maintain consistent thumbnail sizing and aspect ratio
35
36 #### Scenario: Image thumbnail loading
37 - **WHEN** loading history items
38 - **THEN** the system SHALL generate thumbnails efficiently
39 - **AND** SHALL show loading indicators for slow-loading images
40 - **AND** SHALL handle missing or corrupted image files gracefully
41
42 ### Requirement: Prompt Text Display and Copy
43 The system SHALL display the full prompt text for each history item with copy functionality.
44
45 #### Scenario: Prompt text display
46 - **WHEN** a history item is selected
47 - **THEN** the system SHALL display the complete prompt text in a dedicated area
48 - **AND** SHALL format the text for easy reading
49 - **AND** SHALL show prompt length and creation time
50
51 #### Scenario: Prompt text copying
52 - **WHEN** the user clicks the copy button
53 - **THEN** the system SHALL copy the full prompt text to clipboard
54 - **AND** SHALL show a success confirmation message
55 - **AND** SHALL maintain the original prompt formatting
56
57 ### Requirement: Reference Images Gallery
58 The system SHALL display reference images used in the generation process.
59
60 #### Scenario: Reference images display
61 - **WHEN** a history item with reference images is selected
62 - **THEN** the system SHALL display all reference images as thumbnails
63 - **AND** SHALL allow viewing full-size images on double-click
64 - **AND** SHALL show "No reference images" when none exist
65
66 #### Scenario: Reference image interaction
67 - **WHEN** the user double-clicks a reference image thumbnail
68 - **THEN** the system SHALL open the image in system default viewer
69 - **AND** SHALL handle missing image files gracefully
70
71 ### Requirement: Generated Image Preview
72 The system SHALL provide a large preview of the generated image within the history interface.
73
74 #### Scenario: Generated image display
75 - **WHEN** a history item is selected
76 - **THEN** the system SHALL display the generated image in a large preview area
77 - **AND** SHALL scale the image appropriately for the available space
78 - **AND** SHALL maintain image aspect ratio
79
80 #### Scenario: Generated image interaction
81 - **WHEN** the user double-clicks the generated image preview
82 - **THEN** the system SHALL open the image in system default viewer
83 - **AND** SHALL handle missing image files with appropriate error messages
84
85 ### Requirement: History Item Details Panel
86 The system SHALL provide a comprehensive details panel for selected history items.
87
88 #### Scenario: Details panel layout
89 - **WHEN** the history tab is opened
90 - **THEN** the system SHALL display a split-view interface
91 - **AND** SHALL show history list with image previews in the upper portion
92 - **AND** SHALL show details panel in the lower portion
93 - **AND** SHALL maintain responsive proportions
94
95 #### Scenario: Enhanced hover information
96 - **WHEN** the user hovers over a history list item
97 - **THEN** the system SHALL display comprehensive tooltip information
98 - **AND** SHALL include full prompt text, timestamp, aspect ratio, and image size
99 - **AND** SHALL provide quick visual preview without requiring selection
100
101 #### Scenario: Empty state handling
102 - **WHEN** no history item is selected
103 - **THEN** the system SHALL display helpful placeholder text
104 - **AND** SHALL guide user to select an item for details
105 - **AND** SHALL maintain a clean, uncluttered interface
106
107 ### Requirement: Independent Tab Management
108 The system SHALL ensure complete independence between generation and history tabs.
109
110 #### Scenario: Tab switching preservation
111 - **WHEN** the user switches between tabs
112 - **THEN** the system SHALL preserve all input fields and selections
113 - **AND** SHALL not transfer data between interfaces
114 - **AND** SHALL maintain separate operational contexts
115
116 #### Scenario: Concurrent operation support
117 - **WHEN** a history item is being viewed
118 - **THEN** the user SHALL still be able to work in the generation tab
119 - **AND** SHALL not have their work interrupted by history browsing
120 - **AND** SHALL experience smooth tab transitions
...\ No newline at end of file ...\ No newline at end of file
1 ## 1. 移除干扰性功能
2 - [ ] 1.1 移除历史记录双击加载到原有界面的功能
3 - [ ] 1.2 移除 load_history_item 方法中的界面设置逻辑
4 - [ ] 1.3 更新历史记录项的交互提示和工具提示
5 - [ ] 1.4 保留右键菜单中的删除和文件管理器功能
6
7 ## 2. 重新设计历史记录UI
8 - [ ] 2.1 重新设计 setup_history_tab 方法,添加分割器布局
9 - [ ] 2.2 创建历史记录详情展示区域
10 - [ ] 2.3 修改历史列表项显示:添加生成图缩略图+时间戳+Prompt预览
11 - [ ] 2.4 添加Prompt文本显示区域和复制按钮
12 - [ ] 2.5 创建参考图片和生成图片的预览区域
13 - [ ] 2.6 设置合适的布局比例和样式
14 - [ ] 2.7 优化悬停提示信息,包含完整详情
15
16 ## 3. 实现详情展示功能
17 - [ ] 3.1 实现单击历史项显示详情的逻辑
18 - [ ] 3.2 实现Prompt文本的显示和格式化
19 - [ ] 3.3 实现参考图片缩略图的加载和显示
20 - [ ] 3.4 实现生成图片的大图预览功能
21 - [ ] 3.5 添加生成参数信息显示
22
23 ## 4. 添加交互功能
24 - [ ] 4.1 实现Prompt文本复制功能
25 - [ ] 4.2 添加复制成功的视觉反馈
26 - [ ] 4.3 实现参考图片和生成图片的双击放大查看
27 - [ ] 4.4 更新右键菜单,移除加载选项
28 - [ ] 4.5 添加刷新详情的功能
29
30 ## 5. 优化用户体验
31 - [ ] 5.1 实现无选中状态时的提示信息
32 - [ ] 5.2 添加加载状态的指示器
33 - [ ] 5.3 优化图片加载性能和缓存
34 - [ ] 5.4 调整界面布局的响应式设计
35 - [ ] 5.5 添加键盘快捷键支持
36
37 ## 6. 测试和验证
38 - [ ] 6.1 测试历史记录浏览的独立性
39 - [ ] 6.2 验证不会干扰图片生成界面
40 - [ ] 6.3 测试复制功能的准确性
41 - [ ] 6.4 验证图片显示的正确性
42 - [ ] 6.5 测试大量历史记录的性能表现
43
44 ## 7. 文档和清理
45 - [ ] 7.1 更新历史记录功能的使用说明
46 - [ ] 7.2 清理不再使用的代码和方法
47 - [ ] 7.3 验证所有功能正常工作
48 - [ ] 7.4 确保UI一致性和用户体验
...\ No newline at end of file ...\ No newline at end of file
1 #!/usr/bin/env python3
2 """
3 测试配置文件加载逻辑
4 """
5 import json
6 import sys
7 import tempfile
8 from pathlib import Path
9
10 # 模拟PyInstaller环境
11 sys.frozen = True
12 sys._MEIPASS = "C:\\Users\\Shady\\PycharmProjects\\GoogleNanoBananaApp" # 模拟路径
13
14 # 导入配置加载逻辑
15 def test_config_loading():
16 """测试配置文件加载的多种路径"""
17
18 # 模拟exe所在目录的config.json
19 exe_dir_config = Path(sys.executable).parent / 'config.json' if hasattr(sys, 'executable') else None
20
21 # 模拟_MEIPASS目录的config.json
22 meipass_config = Path(sys._MEIPASS) / 'config.json'
23
24 print(f"模拟PyInstaller环境:")
25 print(f" sys.frozen: {getattr(sys, 'frozen', False)}")
26 print(f" sys._MEIPASS: {sys._MEIPASS}")
27
28 # 测试各个路径
29 test_paths = []
30 if hasattr(sys, 'executable'):
31 test_paths.append(("exe目录", Path(sys.executable).parent / 'config.json'))
32
33 test_paths.append(("_MEIPASS目录", Path(sys._MEIPASS) / 'config.json'))
34 test_paths.append(("当前目录", Path('.') / 'config.json'))
35
36 for name, path in test_paths:
37 if path.exists():
38 print(f"[OK] {name}: {path} - 存在")
39 try:
40 with open(path, 'r', encoding='utf-8') as f:
41 config = json.load(f)
42 db_config = config.get("db_config")
43 if db_config:
44 print(f" [OK] 包含数据库配置: {db_config.get('host', 'N/A')}")
45 else:
46 print(f" [FAIL] 未包含数据库配置")
47 except Exception as e:
48 print(f" [FAIL] 读取失败: {e}")
49 else:
50 print(f"[FAIL] {name}: {path} - 不存在")
51
52 if __name__ == "__main__":
53 test_config_loading()
...\ No newline at end of file ...\ No newline at end of file
...@@ -285,6 +285,13 @@ QPushButton[variant="ghost"]:hover {{ ...@@ -285,6 +285,13 @@ QPushButton[variant="ghost"]:hover {{
285 color: {c['accent']}; 285 color: {c['accent']};
286 }} 286 }}
287 287
288 /* 短暂成功反馈("已复制"等,2秒后回退)*/
289 QPushButton[variant="success-flash"] {{
290 background-color: {c['success']};
291 color: white;
292 border: 1px solid {c['success']};
293 }}
294
288 /* 链接按钮 — 像超链接 */ 295 /* 链接按钮 — 像超链接 */
289 QPushButton[variant="link"] {{ 296 QPushButton[variant="link"] {{
290 background-color: transparent; 297 background-color: transparent;
...@@ -601,6 +608,70 @@ QSplitter::handle:vertical {{ ...@@ -601,6 +608,70 @@ QSplitter::handle:vertical {{
601 background: {c['bg_subtle']}; 608 background: {c['bg_subtle']};
602 border-radius: {s['radius_md']}; 609 border-radius: {s['radius_md']};
603 }} 610 }}
611
612 /* ========== 参考图拖拽区(drag_state property)========== */
613 #referenceImageDrop[drag_state="idle"] {{
614 border: 2px dashed {c['border_default']};
615 border-radius: {s['radius_md']};
616 background-color: {c['bg_subtle']};
617 }}
618 #referenceImageDrop[drag_state="idle"]:hover {{
619 border: 2px dashed {c['accent']};
620 background-color: {c['accent_subtle']};
621 }}
622 #referenceImageDrop[drag_state="active"] {{
623 border: 2px dashed {c['accent']};
624 border-radius: {s['radius_md']};
625 background-color: {c['accent_subtle']};
626 }}
627
628 /* ========== 已生成图片缩略图卡 ========== */
629 QLabel[role="thumb"] {{
630 border: 1px solid {c['border_default']};
631 border-radius: {s['radius_sm']};
632 background-color: {c['bg_surface']};
633 }}
634 QLabel[role="thumb_index"] {{
635 color: {c['text_secondary']};
636 font-size: {s['font_base']};
637 font-weight: 600;
638 }}
639
640 /* ========== 预览区生成图(result_label / generated_image_label)========== */
641 QLabel#previewImage {{
642 background-color: {c['bg_subtle']};
643 border: 1px solid {c['border_default']};
644 border-radius: {s['radius_md']};
645 color: {c['text_tertiary']};
646 }}
647 QLabel#previewImage[has_image="true"] {{
648 background-color: {c['bg_canvas']};
649 border-color: {c['border_default']};
650 }}
651
652 /* ========== 历史详情提示词显示框 ========== */
653 QLabel#promptDisplay {{
654 background-color: {c['bg_subtle']};
655 border: 1px solid {c['border_default']};
656 border-radius: {s['radius_md']};
657 padding: 8px 10px;
658 color: {c['text_primary']};
659 }}
660
661 /* ========== 缩略图删除按钮(20x20 紧凑)========== */
662 QPushButton#thumbDeleteBtn {{
663 background-color: {c['danger']};
664 color: white;
665 border: none;
666 border-radius: 3px;
667 padding: 0;
668 min-height: 0;
669 font-size: {s['font_xs']};
670 font-weight: 700;
671 }}
672 QPushButton#thumbDeleteBtn:hover {{
673 background-color: {c['danger_hover']};
674 }}
604 """ 675 """
605 676
606 677
......