gui_display_model.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. # -*- coding: utf-8 -*-
  2. """
  3. GUI 显示窗口数据模型 - 用于 QML 数据绑定.
  4. """
  5. from PyQt5.QtCore import QObject, pyqtProperty, pyqtSignal
  6. class GuiDisplayModel(QObject):
  7. """
  8. GUI 主窗口的数据模型,用于 Python 和 QML 之间的数据绑定.
  9. """
  10. # 属性变化信号
  11. statusTextChanged = pyqtSignal()
  12. emotionPathChanged = pyqtSignal()
  13. ttsTextChanged = pyqtSignal()
  14. buttonTextChanged = pyqtSignal()
  15. modeTextChanged = pyqtSignal()
  16. autoModeChanged = pyqtSignal()
  17. quickCommandsChanged = pyqtSignal()
  18. exhibitionVolumeChanged = pyqtSignal()
  19. videoListChanged = pyqtSignal()
  20. # 用户操作信号
  21. manualButtonPressed = pyqtSignal()
  22. manualButtonReleased = pyqtSignal()
  23. autoButtonClicked = pyqtSignal()
  24. abortButtonClicked = pyqtSignal()
  25. modeButtonClicked = pyqtSignal()
  26. exhibitionButtonClicked = pyqtSignal()
  27. videoButtonClicked = pyqtSignal()
  28. playVideo = pyqtSignal(int)
  29. sendButtonClicked = pyqtSignal(str) # 携带输入的文本
  30. settingsButtonClicked = pyqtSignal()
  31. def __init__(self, parent=None):
  32. super().__init__(parent)
  33. # 私有属性
  34. self._status_text = "状态: 未连接"
  35. self._emotion_path = "" # 表情资源路径(GIF/图片)或 emoji 字符
  36. self._tts_text = "待命"
  37. self._button_text = "开始对话" # 自动模式按钮文本
  38. self._mode_text = "手动对话" # 模式切换按钮文本
  39. self._auto_mode = False # 是否自动模式
  40. self._is_connected = False
  41. self._quick_commands = [] # 快捷指令列表
  42. self._exhibition_volume = 50 # 展厅音量
  43. self._video_list = [] # 视频列表
  44. # 状态文本属性
  45. @pyqtProperty(str, notify=statusTextChanged)
  46. def statusText(self):
  47. return self._status_text
  48. @statusText.setter
  49. def statusText(self, value):
  50. if self._status_text != value:
  51. self._status_text = value
  52. self.statusTextChanged.emit()
  53. # 表情路径属性
  54. @pyqtProperty(str, notify=emotionPathChanged)
  55. def emotionPath(self):
  56. return self._emotion_path
  57. @emotionPath.setter
  58. def emotionPath(self, value):
  59. if self._emotion_path != value:
  60. self._emotion_path = value
  61. self.emotionPathChanged.emit()
  62. # TTS 文本属性
  63. @pyqtProperty(str, notify=ttsTextChanged)
  64. def ttsText(self):
  65. return self._tts_text
  66. @ttsText.setter
  67. def ttsText(self, value):
  68. if self._tts_text != value:
  69. self._tts_text = value
  70. self.ttsTextChanged.emit()
  71. # 自动模式按钮文本属性
  72. @pyqtProperty(str, notify=buttonTextChanged)
  73. def buttonText(self):
  74. return self._button_text
  75. @buttonText.setter
  76. def buttonText(self, value):
  77. if self._button_text != value:
  78. self._button_text = value
  79. self.buttonTextChanged.emit()
  80. # 模式切换按钮文本属性
  81. @pyqtProperty(str, notify=modeTextChanged)
  82. def modeText(self):
  83. return self._mode_text
  84. @modeText.setter
  85. def modeText(self, value):
  86. if self._mode_text != value:
  87. self._mode_text = value
  88. self.modeTextChanged.emit()
  89. # 自动模式标志属性
  90. @pyqtProperty(bool, notify=autoModeChanged)
  91. def autoMode(self):
  92. return self._auto_mode
  93. @autoMode.setter
  94. def autoMode(self, value):
  95. if self._auto_mode != value:
  96. self._auto_mode = value
  97. self.autoModeChanged.emit()
  98. # 快捷指令列表属性
  99. @pyqtProperty(list, notify=quickCommandsChanged)
  100. def quickCommands(self):
  101. return self._quick_commands
  102. @quickCommands.setter
  103. def quickCommands(self, value):
  104. if self._quick_commands != value:
  105. self._quick_commands = value
  106. self.quickCommandsChanged.emit()
  107. # 展厅音量属性
  108. @pyqtProperty(int, notify=exhibitionVolumeChanged)
  109. def exhibitionVolume(self):
  110. return self._exhibition_volume
  111. @exhibitionVolume.setter
  112. def exhibitionVolume(self, value):
  113. if self._exhibition_volume != value:
  114. self._exhibition_volume = value
  115. self.exhibitionVolumeChanged.emit()
  116. # 视频列表属性
  117. @pyqtProperty(list, notify=videoListChanged)
  118. def videoList(self):
  119. return self._video_list
  120. @videoList.setter
  121. def videoList(self, value):
  122. if self._video_list != value:
  123. self._video_list = value
  124. self.videoListChanged.emit()
  125. # 便捷方法
  126. def update_status(self, status: str, connected: bool):
  127. """
  128. 更新状态文本和连接状态.
  129. """
  130. self.statusText = f"状态: {status}"
  131. self._is_connected = connected
  132. def update_text(self, text: str):
  133. """
  134. 更新 TTS 文本.
  135. """
  136. self.ttsText = text
  137. def update_emotion(self, emotion_path: str):
  138. """
  139. 更新表情路径.
  140. """
  141. self.emotionPath = emotion_path
  142. def update_button_text(self, text: str):
  143. """
  144. 更新自动模式按钮文本.
  145. """
  146. self.buttonText = text
  147. def update_mode_text(self, text: str):
  148. """
  149. 更新模式按钮文本.
  150. """
  151. self.modeText = text
  152. def set_auto_mode(self, is_auto: bool):
  153. """
  154. 设置自动模式.
  155. """
  156. self.autoMode = is_auto
  157. if is_auto:
  158. self.modeText = "自动对话"
  159. else:
  160. self.modeText = "手动对话"
  161. def set_quick_commands(self, commands: list):
  162. """
  163. 设置快捷指令列表.
  164. """
  165. self.quickCommands = commands