""" MainWindow - Finestra principale dell'applicazione desktop """ from PyQt6.QtWidgets import ( QMainWindow, QWidget, QVBoxLayout, QMenuBar, QMenu, QMessageBox, QLabel, QStatusBar ) from PyQt6.QtCore import Qt from PyQt6.QtGui import QAction, QKeySequence from desktop.ui.chat_widget import ChatWidget class MainWindow(QMainWindow): """Finestra principale di Jarvis-Cognitive Desktop""" def __init__(self, kernel): super().__init__() self.kernel = kernel self.init_ui() self.apply_stylesheet() def init_ui(self): """Inizializza l'interfaccia utente""" # Titolo dinamico basato su profilo profile_names = { 'aurelio': 'Marco Aurelio (Imperatore Filosofo)', 'warren': 'Warren Mentor (Investment Advisor)' } profile_display = profile_names.get( self.kernel.active_profile, self.kernel.active_profile.capitalize() ) # Titolo e dimensioni self.setWindowTitle(f"Jarvis - {profile_display}") self.setGeometry(100, 100, 900, 700) # Widget centrale: ChatWidget self.chat_widget = ChatWidget(self.kernel) self.setCentralWidget(self.chat_widget) # Menu bar self.create_menu_bar() # Status bar dinamico self.statusBar = QStatusBar() self.setStatusBar(self.statusBar) philosopher_name = profile_display.split('(')[0].strip() self.statusBar.showMessage(f"Pronto | {philosopher_name} ti dà il benvenuto") def create_menu_bar(self): """Crea la barra dei menu""" menubar = self.menuBar() # Menu File file_menu = menubar.addMenu("&File") # Azione: Indicizza Documento index_action = QAction("đ Indicizza Documento", self) index_action.setShortcut(QKeySequence("Ctrl+O")) index_action.triggered.connect(self.chat_widget.upload_document) file_menu.addAction(index_action) file_menu.addSeparator() # Azione: Esci exit_action = QAction("Esci", self) exit_action.setShortcut(QKeySequence("Ctrl+Q")) exit_action.triggered.connect(self.close) file_menu.addAction(exit_action) # Menu Chat chat_menu = menubar.addMenu("&Chat") # Azione: Nuova Conversazione new_chat_action = QAction("đī¸ Pulisci Chat", self) new_chat_action.setShortcut(QKeySequence("Ctrl+N")) new_chat_action.triggered.connect(self.chat_widget.clear_chat) chat_menu.addAction(new_chat_action) # Menu Aiuto help_menu = menubar.addMenu("&Aiuto") # Azione: Info about_action = QAction("âšī¸ Info", self) about_action.triggered.connect(self.show_about) help_menu.addAction(about_action) def show_about(self): """Mostra finestra About con info dinamiche profilo""" profile_info = { 'aurelio': ('Marco Aurelio', 'Imperatore Romano e Filosofo Stoico', '121-180 d.C.'), 'warren': ('Warren Mentor', 'Deep Value Investment Advisor', 'Buffett/Munger/Graham') } name, title, period = profile_info.get( self.kernel.active_profile, (self.kernel.active_profile.capitalize(), 'Filosofo Stoico', 'Sconosciuto') ) QMessageBox.about( self, f"Info - Jarvis {name}", f"
Versione: 2.0 Desktop (PyQt6)
" f"Profilo: {name}, {title}
" f"Periodo: {period}
" "Applicazione desktop per conversazioni filosofiche con l'antica saggezza stoica.
" "LLM: Claude Anthropic (Haiku 4.5)
" "RAG: ChromaDB + ParentDocumentRetriever
" "Framework: PyQt6 + LangChain
" "Un ponte tra l'antica saggezza e il mondo contemporaneo.
" ) def apply_stylesheet(self): """Applica lo stile all'applicazione""" # Stile semplice e pulito self.setStyleSheet(""" QMainWindow { background-color: #f5f5f5; } QTextEdit { background-color: white; border: 1px solid #ddd; border-radius: 5px; padding: 10px; font-size: 13px; font-family: 'Segoe UI', 'Arial', sans-serif; } QLineEdit { background-color: white; border: 1px solid #ddd; border-radius: 5px; padding: 8px; font-size: 13px; } QLineEdit:focus { border: 2px solid #4CAF50; } QPushButton { background-color: #4CAF50; color: white; border: none; border-radius: 5px; padding: 8px 16px; font-size: 13px; font-weight: bold; } QPushButton:hover { background-color: #45a049; } QPushButton:pressed { background-color: #3d8b40; } QPushButton:disabled { background-color: #cccccc; color: #666666; } QLabel { color: #333; } QMenuBar { background-color: #fff; border-bottom: 1px solid #ddd; } QMenuBar::item:selected { background-color: #4CAF50; color: white; } QMenu { background-color: white; border: 1px solid #ddd; } QMenu::item:selected { background-color: #4CAF50; color: white; } QStatusBar { background-color: #fff; border-top: 1px solid #ddd; color: #666; } """) def closeEvent(self, event): """Gestisce la chiusura dell'applicazione""" reply = QMessageBox.question( self, "Conferma uscita", "Vuoi davvero chiudere Jarvis?", QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No, QMessageBox.StandardButton.No ) if reply == QMessageBox.StandardButton.Yes: self.statusBar.showMessage("Arresto Kernel...") event.accept() else: event.ignore()