base_agent/uas/inout/signals.py

67 lines
3.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding: utf-8 -*-
"""
PyQt5 全局信号定义
─────────────────────────────────────────────────────────────────
使用 QObject + pyqtSignal 定义所有 IO 信号,
支持跨线程安全分发Qt 自动处理线程间信号队列)
─────────────────────────────────────────────────────────────────
"""
from PyQt5.QtCore import QObject, pyqtSignal
class IOSignals(QObject):
"""
统一 IO 信号集合(单例)
所有输入/输出/处理器通过此信号对象通信
信号说明:
input_received —— 原始输入到达
input_processed —— 输入处理完成,携带处理结果
output_ready —— 输出就绪,通知输出模块渲染
error_occurred —— 任意环节发生错误
status_changed —— IO 状态变更pending/processing/done
progress_updated —— 长任务进度更新0~100
"""
# ── 输入信号 ──────────────────────────────────────────────────
# (data_id: str, io_type: str, raw_data: object)
input_received = pyqtSignal(str, str, object)
# ── 处理信号 ──────────────────────────────────────────────────
# (data_id: str, io_type: str, result: object)
input_processed = pyqtSignal(str, str, object)
# ── 输出信号 ──────────────────────────────────────────────────
# (data_id: str, io_type: str, output_data: object)
output_ready = pyqtSignal(str, str, object)
# ── 错误信号 ──────────────────────────────────────────────────
# (data_id: str, source: str, error_msg: str)
error_occurred = pyqtSignal(str, str, str)
# ── 状态信号 ──────────────────────────────────────────────────
# (data_id: str, status: str)
status_changed = pyqtSignal(str, str)
# ── 进度信号 ──────────────────────────────────────────────────
# (data_id: str, progress: int)
progress_updated = pyqtSignal(str, int)
# ── 语音专用 ──────────────────────────────────────────────────
# (text: str)
speech_recognized = pyqtSignal(str)
# (text: str)
tts_finished = pyqtSignal(str)
# ─── 单例 ────────────────────────────────────────────────────
_instance = None
def __new__(cls, *args, **kwargs):
if cls._instance is None:
cls._instance = super().__new__(cls)
return cls._instance
# 全局信号总线实例(全模块共享)
io_signals = IOSignals()