fix: 重构的通用Python执行器

This commit is contained in:
root 2025-07-10 22:51:09 +08:00
parent 5d684f3c4e
commit e2a7c6d9e2
4 changed files with 53 additions and 38 deletions

View File

@ -1,6 +1,14 @@
# Python Executor with Progress Support
# 🚀 通用Python执行器进度支持系统
通用的Python执行器支持实时进度回调和JSON-RPC通信。
一个完全重构的通用Python执行器支持实时进度回调、JSON-RPC通信和简化的命令创建。
## ✨ 新特性
- 🎯 **通用进度支持**:一次实现,到处使用
- 🔧 **简化的API**:多种便利函数和宏
- 📊 **实时进度更新**支持Tauri事件和自定义回调
- 🛠️ **命令构建器**简化Python命令构造
- 📝 **丰富的示例**:涵盖各种使用场景
## 功能特性
@ -13,7 +21,48 @@
- ✅ 超时处理
- ✅ 错误处理
## 使用方法
## 🎯 核心API
### 1. 通用进度执行函数
```rust
// 最通用的函数 - 推荐使用
execute_python_action_with_progress(
app: AppHandle,
module: &str, // Python模块路径
action: &str, // 要执行的动作
params: &[(&str, &str)], // 参数键值对
event_name: &str, // 前端事件名称
config: Option<PythonExecutorConfig>
) -> Result<String, String>
```
### 2. 便利函数
```rust
// Tauri事件进度推荐用于前端集成
execute_python_with_events(app, &args, config, "event-name")
// 函数回调进度(用于自定义处理)
execute_python_with_callback(app, &args, config, callback)
// 基本执行(无进度)
execute_python_command(app, &args, config)
```
### 3. 宏支持
```rust
// 简单命令宏
python_action_command! {
name: my_simple_command,
module: "python_core.my_module",
action: "my_action",
event: "my-progress-event"
}
```
## 📋 使用方法
### 1. 基本用法(无进度)

View File

@ -184,29 +184,6 @@ const AIVideoGenerator: React.FC<AIVideoGeneratorProps> = ({ className = '' }) =
{isProcessing ? '生成中...' : '开始生成'}
</button>
</div>
{/* Jobs List */}
<div className="p-6">
<div className="flex items-center justify-between mb-4">
<h3 className="text-lg font-medium text-secondary-900"></h3>
{jobs.length > 0 && (
<button
onClick={clearCompletedJobs}
className="text-sm text-secondary-600 hover:text-secondary-900"
>
</button>
)}
</div>
<VideoJobList
jobs={jobs}
onPreview={openPreview}
onDelete={deleteJob}
onRetry={handleRetryJob}
/>
</div>
{/* Video Preview Modal */}
<AIVideoResultPreview
isOpen={previewData.isOpen}

View File

@ -50,17 +50,6 @@ const AIVideoPage: React.FC = () => {
<p className="text-secondary-600">使 AI </p>
</div>
</div>
<div className="flex items-center space-x-2">
<button className="btn-ghost px-3 py-2">
<Settings size={16} className="mr-2" />
</button>
<button className="btn-ghost px-3 py-2">
<HelpCircle size={16} className="mr-2" />
</button>
</div>
</div>
</div>

View File

@ -1,4 +1,4 @@
import { invoke } from '@tauri-apps/api/tauri'
import { invoke } from '@tauri-apps/api/core'
export interface TemplateInfo {
id: string