| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- # -*- coding: utf-8 -*-
- """
- GUI 显示窗口数据模型 - 用于 QML 数据绑定.
- """
- from PyQt5.QtCore import QObject, pyqtProperty, pyqtSignal
- class GuiDisplayModel(QObject):
- """
- GUI 主窗口的数据模型,用于 Python 和 QML 之间的数据绑定.
- """
- # 属性变化信号
- statusTextChanged = pyqtSignal()
- emotionPathChanged = pyqtSignal()
- ttsTextChanged = pyqtSignal()
- buttonTextChanged = pyqtSignal()
- modeTextChanged = pyqtSignal()
- autoModeChanged = pyqtSignal()
- quickCommandsChanged = pyqtSignal()
- exhibitionVolumeChanged = pyqtSignal()
- videoListChanged = pyqtSignal()
- # 用户操作信号
- manualButtonPressed = pyqtSignal()
- manualButtonReleased = pyqtSignal()
- autoButtonClicked = pyqtSignal()
- abortButtonClicked = pyqtSignal()
- modeButtonClicked = pyqtSignal()
- exhibitionButtonClicked = pyqtSignal()
- videoButtonClicked = pyqtSignal()
- playVideo = pyqtSignal(int)
- sendButtonClicked = pyqtSignal(str) # 携带输入的文本
- settingsButtonClicked = pyqtSignal()
- def __init__(self, parent=None):
- super().__init__(parent)
- # 私有属性
- self._status_text = "状态: 未连接"
- self._emotion_path = "" # 表情资源路径(GIF/图片)或 emoji 字符
- self._tts_text = "待命"
- self._button_text = "开始对话" # 自动模式按钮文本
- self._mode_text = "手动对话" # 模式切换按钮文本
- self._auto_mode = False # 是否自动模式
- self._is_connected = False
- self._quick_commands = [] # 快捷指令列表
- self._exhibition_volume = 50 # 展厅音量
- self._video_list = [] # 视频列表
- # 状态文本属性
- @pyqtProperty(str, notify=statusTextChanged)
- def statusText(self):
- return self._status_text
- @statusText.setter
- def statusText(self, value):
- if self._status_text != value:
- self._status_text = value
- self.statusTextChanged.emit()
- # 表情路径属性
- @pyqtProperty(str, notify=emotionPathChanged)
- def emotionPath(self):
- return self._emotion_path
- @emotionPath.setter
- def emotionPath(self, value):
- if self._emotion_path != value:
- self._emotion_path = value
- self.emotionPathChanged.emit()
- # TTS 文本属性
- @pyqtProperty(str, notify=ttsTextChanged)
- def ttsText(self):
- return self._tts_text
- @ttsText.setter
- def ttsText(self, value):
- if self._tts_text != value:
- self._tts_text = value
- self.ttsTextChanged.emit()
- # 自动模式按钮文本属性
- @pyqtProperty(str, notify=buttonTextChanged)
- def buttonText(self):
- return self._button_text
- @buttonText.setter
- def buttonText(self, value):
- if self._button_text != value:
- self._button_text = value
- self.buttonTextChanged.emit()
- # 模式切换按钮文本属性
- @pyqtProperty(str, notify=modeTextChanged)
- def modeText(self):
- return self._mode_text
- @modeText.setter
- def modeText(self, value):
- if self._mode_text != value:
- self._mode_text = value
- self.modeTextChanged.emit()
- # 自动模式标志属性
- @pyqtProperty(bool, notify=autoModeChanged)
- def autoMode(self):
- return self._auto_mode
- @autoMode.setter
- def autoMode(self, value):
- if self._auto_mode != value:
- self._auto_mode = value
- self.autoModeChanged.emit()
- # 快捷指令列表属性
- @pyqtProperty(list, notify=quickCommandsChanged)
- def quickCommands(self):
- return self._quick_commands
- @quickCommands.setter
- def quickCommands(self, value):
- if self._quick_commands != value:
- self._quick_commands = value
- self.quickCommandsChanged.emit()
- # 展厅音量属性
- @pyqtProperty(int, notify=exhibitionVolumeChanged)
- def exhibitionVolume(self):
- return self._exhibition_volume
- @exhibitionVolume.setter
- def exhibitionVolume(self, value):
- if self._exhibition_volume != value:
- self._exhibition_volume = value
- self.exhibitionVolumeChanged.emit()
- # 视频列表属性
- @pyqtProperty(list, notify=videoListChanged)
- def videoList(self):
- return self._video_list
- @videoList.setter
- def videoList(self, value):
- if self._video_list != value:
- self._video_list = value
- self.videoListChanged.emit()
- # 便捷方法
- def update_status(self, status: str, connected: bool):
- """
- 更新状态文本和连接状态.
- """
- self.statusText = f"状态: {status}"
- self._is_connected = connected
- def update_text(self, text: str):
- """
- 更新 TTS 文本.
- """
- self.ttsText = text
- def update_emotion(self, emotion_path: str):
- """
- 更新表情路径.
- """
- self.emotionPath = emotion_path
- def update_button_text(self, text: str):
- """
- 更新自动模式按钮文本.
- """
- self.buttonText = text
- def update_mode_text(self, text: str):
- """
- 更新模式按钮文本.
- """
- self.modeText = text
- def set_auto_mode(self, is_auto: bool):
- """
- 设置自动模式.
- """
- self.autoMode = is_auto
- if is_auto:
- self.modeText = "自动对话"
- else:
- self.modeText = "手动对话"
- def set_quick_commands(self, commands: list):
- """
- 设置快捷指令列表.
- """
- self.quickCommands = commands
|