|
@@ -4,6 +4,7 @@ GUI 显示模块 - 使用 QML 实现.
|
|
|
"""
|
|
"""
|
|
|
|
|
|
|
|
import asyncio
|
|
import asyncio
|
|
|
|
|
+import json
|
|
|
import os
|
|
import os
|
|
|
import signal
|
|
import signal
|
|
|
from abc import ABCMeta
|
|
from abc import ABCMeta
|
|
@@ -340,6 +341,7 @@ class GuiDisplay(BaseDisplay, QObject, metaclass=CombinedMeta):
|
|
|
完成启动流程.
|
|
完成启动流程.
|
|
|
"""
|
|
"""
|
|
|
await self.update_emotion("neutral")
|
|
await self.update_emotion("neutral")
|
|
|
|
|
+ self._load_quick_commands()
|
|
|
|
|
|
|
|
# 根据配置决定显示模式
|
|
# 根据配置决定显示模式
|
|
|
if getattr(self, "_is_fullscreen", False):
|
|
if getattr(self, "_is_fullscreen", False):
|
|
@@ -349,6 +351,49 @@ class GuiDisplay(BaseDisplay, QObject, metaclass=CombinedMeta):
|
|
|
|
|
|
|
|
self._setup_system_tray()
|
|
self._setup_system_tray()
|
|
|
|
|
|
|
|
|
|
+ def _load_quick_commands(self):
|
|
|
|
|
+ """
|
|
|
|
|
+ 加载快捷指令配置.
|
|
|
|
|
+ """
|
|
|
|
|
+ try:
|
|
|
|
|
+ # 获取项目根目录 (假设当前文件在 src/display/)
|
|
|
|
|
+ root_dir = Path(__file__).resolve().parents[2]
|
|
|
|
|
+ config_dir = root_dir / "config"
|
|
|
|
|
+ config_file = config_dir / "quick_commands.json"
|
|
|
|
|
+
|
|
|
|
|
+ # 确保config目录存在
|
|
|
|
|
+ if not config_dir.exists():
|
|
|
|
|
+ config_dir.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
+
|
|
|
|
|
+ if not config_file.exists():
|
|
|
|
|
+ # 默认配置
|
|
|
|
|
+ default_commands = [
|
|
|
|
|
+ {"label": "音量 80%", "text": "音量调整到80"},
|
|
|
|
|
+ {"label": "音量 20%", "text": "音量调整到20"},
|
|
|
|
|
+ {"label": "打开灯光", "text": "打开灯光"},
|
|
|
|
|
+ {"label": "关闭灯光", "text": "关闭灯光"},
|
|
|
|
|
+ ]
|
|
|
|
|
+ with open(config_file, "w", encoding="utf-8") as f:
|
|
|
|
|
+ json.dump(default_commands, f, indent=4, ensure_ascii=False)
|
|
|
|
|
+ commands = default_commands
|
|
|
|
|
+ else:
|
|
|
|
|
+ with open(config_file, "r", encoding="utf-8") as f:
|
|
|
|
|
+ commands = json.load(f)
|
|
|
|
|
+
|
|
|
|
|
+ # 简单的校验
|
|
|
|
|
+ valid_commands = []
|
|
|
|
|
+ if isinstance(commands, list):
|
|
|
|
|
+ for cmd in commands:
|
|
|
|
|
+ if isinstance(cmd, dict) and "label" in cmd and "text" in cmd:
|
|
|
|
|
+ valid_commands.append(cmd)
|
|
|
|
|
+
|
|
|
|
|
+ self.display_model.set_quick_commands(valid_commands)
|
|
|
|
|
+ self.logger.info(f"已加载 {len(valid_commands)} 条快捷指令")
|
|
|
|
|
+
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ self.logger.error(f"加载快捷指令失败: {e}")
|
|
|
|
|
+ self.display_model.set_quick_commands([])
|
|
|
|
|
+
|
|
|
# =========================================================================
|
|
# =========================================================================
|
|
|
# 信号连接
|
|
# 信号连接
|
|
|
# =========================================================================
|
|
# =========================================================================
|