Spaces:
Build error
Build error
File size: 10,485 Bytes
ad160e7 4770c4f ad160e7 4770c4f ad160e7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
"""
Frontend Application - Main UI for Vision OS
"""
import sys
import os
from pathlib import Path
from typing import Dict, List, Any, Optional
from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout,
QHBoxLayout, QLabel, QPushButton, QTextEdit,
QLineEdit, QTabWidget, QSplitter, QFrame,
QStackedWidget, QScrollArea, QFileDialog)
from PyQt5.QtGui import QFont, QColor, QPixmap, QIcon, QPainter, QBrush, QLinearGradient
from PyQt5.QtCore import Qt, QSize, QTimer, QPropertyAnimation, QEasingCurve, QRect
# Import core components
from agents.orchestrator import AgentOrchestrator
from memory.memory_manager import MemoryManager
# Import UI components
from frontend.components.chat_panel import ChatPanel
from frontend.components.task_panel import TaskPanel
from frontend.components.web_panel import WebAutomationPanel
from frontend.components.file_panel import FilePanel
from frontend.components.settings_panel import SettingsPanel
from frontend.components.project_panel import ProjectPanel
from frontend.theme import ThemeManager
class VisionOSApp:
"""
Main application class for Vision OS
"""
def __init__(self, config: Dict[str, Any], agent_orchestrator: AgentOrchestrator,
memory_manager: MemoryManager):
"""
Initialize the Vision OS application
Args:
config: Application configuration
agent_orchestrator: Agent orchestrator instance
memory_manager: Memory manager instance
"""
self.config = config
self.agent_orchestrator = agent_orchestrator
self.memory_manager = memory_manager
self.app = QApplication(sys.argv)
self.theme_manager = ThemeManager(config.get("theme", "dark"))
# Apply theme to application
self.apply_theme()
# Create main window
self.main_window = MainWindow(config, agent_orchestrator, memory_manager, self.theme_manager)
def run(self):
"""Run the application"""
self.main_window.show()
sys.exit(self.app.exec_())
def apply_theme(self):
"""Apply theme to application"""
# Set application style sheet
style_sheet = self.theme_manager.get_application_style()
self.app.setStyleSheet(style_sheet)
class MainWindow(QMainWindow):
"""
Main window for Vision OS application
"""
def __init__(self, config: Dict[str, Any], agent_orchestrator: AgentOrchestrator,
memory_manager: MemoryManager, theme_manager: ThemeManager):
"""
Initialize the main window
Args:
config: Application configuration
agent_orchestrator: Agent orchestrator instance
memory_manager: Memory manager instance
theme_manager: Theme manager instance
"""
super().__init__()
self.config = config
self.agent_orchestrator = agent_orchestrator
self.memory_manager = memory_manager
self.theme_manager = theme_manager
# Set window properties
self.setWindowTitle(f"{config.get('app_name', 'Vision OS')} v{config.get('version', '1.0.0')}")
self.setMinimumSize(1200, 800)
# Create UI
self.init_ui()
def init_ui(self):
"""Initialize the user interface"""
# Create central widget
central_widget = QWidget()
self.setCentralWidget(central_widget)
# Create main layout
main_layout = QVBoxLayout(central_widget)
main_layout.setContentsMargins(0, 0, 0, 0)
main_layout.setSpacing(0)
# Create header
header = self.create_header()
main_layout.addWidget(header)
# Create content area
content = self.create_content()
main_layout.addWidget(content, 1) # 1 = stretch factor
# Create command bar
command_bar = self.create_command_bar()
main_layout.addWidget(command_bar)
def create_header(self) -> QWidget:
"""Create the header widget"""
header = QWidget()
header.setObjectName("header")
header.setFixedHeight(60)
layout = QHBoxLayout(header)
layout.setContentsMargins(20, 0, 20, 0)
# Logo and title
logo_label = QLabel("VISION OS")
logo_label.setObjectName("logo")
logo_label.setFont(QFont("SF Pro Display", 18, QFont.Bold))
# Spacer
spacer = QWidget()
spacer.setSizePolicy(QWidget.QSizePolicy.Expanding, QWidget.QSizePolicy.Preferred)
# Navigation buttons
nav_buttons = QWidget()
nav_layout = QHBoxLayout(nav_buttons)
nav_layout.setContentsMargins(0, 0, 0, 0)
nav_layout.setSpacing(10)
for name in ["Chat", "Tasks", "Web", "Files", "Projects"]:
button = QPushButton(name)
button.setObjectName("nav-button")
button.setFixedSize(100, 40)
button.clicked.connect(lambda checked, n=name: self.switch_panel(n.lower()))
nav_layout.addWidget(button)
# Settings button
settings_button = QPushButton("Settings")
settings_button.setObjectName("settings-button")
settings_button.setFixedSize(40, 40)
settings_button.clicked.connect(lambda: self.switch_panel("settings"))
# Add widgets to layout
layout.addWidget(logo_label)
layout.addWidget(spacer)
layout.addWidget(nav_buttons)
layout.addWidget(settings_button)
return header
def create_content(self) -> QWidget:
"""Create the content widget"""
content = QWidget()
content.setObjectName("content")
layout = QVBoxLayout(content)
layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(0)
# Create stacked widget for different panels
self.stacked_widget = QStackedWidget()
# Create panels
self.chat_panel = ChatPanel(self.agent_orchestrator, self.memory_manager, self.theme_manager)
self.task_panel = TaskPanel(self.agent_orchestrator, self.memory_manager, self.theme_manager)
self.web_panel = WebAutomationPanel(self.agent_orchestrator, self.memory_manager, self.theme_manager)
self.file_panel = FilePanel(self.agent_orchestrator, self.memory_manager, self.theme_manager)
self.project_panel = ProjectPanel(self.agent_orchestrator, self.memory_manager, self.theme_manager)
self.settings_panel = SettingsPanel(self.config, self.theme_manager)
# Add panels to stacked widget
self.stacked_widget.addWidget(self.chat_panel)
self.stacked_widget.addWidget(self.task_panel)
self.stacked_widget.addWidget(self.web_panel)
self.stacked_widget.addWidget(self.file_panel)
self.stacked_widget.addWidget(self.project_panel)
self.stacked_widget.addWidget(self.settings_panel)
# Set default panel
self.stacked_widget.setCurrentWidget(self.chat_panel)
layout.addWidget(self.stacked_widget)
return content
def create_command_bar(self) -> QWidget:
"""Create the command bar widget"""
command_bar = QWidget()
command_bar.setObjectName("command-bar")
command_bar.setFixedHeight(60)
layout = QHBoxLayout(command_bar)
layout.setContentsMargins(20, 10, 20, 10)
# Command input
self.command_input = QLineEdit()
self.command_input.setObjectName("command-input")
self.command_input.setPlaceholderText("What would you like to create today?")
self.command_input.returnPressed.connect(self.process_command)
# Voice button
voice_button = QPushButton()
voice_button.setObjectName("voice-button")
voice_button.setFixedSize(40, 40)
voice_button.setIcon(QIcon("frontend/assets/mic.png"))
voice_button.setIconSize(QSize(20, 20))
voice_button.clicked.connect(self.toggle_voice_input)
# Add widgets to layout
layout.addWidget(self.command_input)
layout.addWidget(voice_button)
return command_bar
def switch_panel(self, panel_name: str):
"""
Switch to the specified panel
Args:
panel_name: Name of the panel to switch to
"""
panel_map = {
"chat": self.chat_panel,
"tasks": self.task_panel,
"web": self.web_panel,
"files": self.file_panel,
"projects": self.project_panel,
"settings": self.settings_panel
}
if panel_name in panel_map:
self.stacked_widget.setCurrentWidget(panel_map[panel_name])
def process_command(self):
"""Process the command from the command bar"""
command = self.command_input.text()
if not command:
return
# Clear command input
self.command_input.clear()
# Process command through agent orchestrator
response = self.agent_orchestrator.route_request(command)
# Switch to appropriate panel based on agent response
agent_panel_map = {
"task": "tasks",
"ui": "projects",
"grant": "projects",
"file": "files",
"system": "chat",
"automation": "web",
"memory": "chat",
"creative": "projects"
}
if "agent" in response and response["agent"] in agent_panel_map:
self.switch_panel(agent_panel_map[response["agent"]])
# Update the current panel with the response
current_panel = self.stacked_widget.currentWidget()
if hasattr(current_panel, "update_with_response"):
current_panel.update_with_response(command, response)
def toggle_voice_input(self):
"""Toggle voice input for commands"""
# This would be implemented with Whisper.cpp integration
# For now, just show a placeholder message
self.command_input.setText("Voice input coming soon...")
QTimer.singleShot(2000, self.command_input.clear)
|