-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui_manager.py
More file actions
127 lines (102 loc) · 3.76 KB
/
ui_manager.py
File metadata and controls
127 lines (102 loc) · 3.76 KB
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
"""
UI Manager - Abstraction layer for different UI themes
"""
import eel
import logging
from abc import ABC, abstractmethod
from pathlib import Path
logger = logging.getLogger(__name__)
class UIManager(ABC):
"""Base class defining UI interface that all themes must implement"""
@abstractmethod
def update_voice_input(self, text):
"""Update the voice input display"""
pass
@abstractmethod
def update_response(self, text):
"""Update the HAL response display"""
pass
@abstractmethod
def update_logs(self, entry):
"""Add a log entry to the display"""
pass
@abstractmethod
def update_toolbar(self, listening, speaking):
"""Update toolbar button states"""
pass
@abstractmethod
def show_page(self, page_name, data=None):
"""Show a specific page/view"""
pass
@abstractmethod
def initialize(self):
"""Initialize the UI (start Eel, load theme, etc.)"""
pass
class EelUIManager(UIManager):
"""Eel-based UI implementation that works with any HTML/CSS/JS theme"""
def __init__(self, theme='lcars', web_dir='web'):
self.theme = theme
self.web_dir = Path(web_dir)
self.theme_dir = self.web_dir / 'themes' / theme
if not self.theme_dir.exists():
raise ValueError(f"Theme directory not found: {self.theme_dir}")
logger.info(f"UIManager initialized with theme: {theme}")
def initialize(self):
"""Initialize Eel with the selected theme"""
# Initialize Eel with web directory
eel.init(str(self.web_dir))
logger.info(f"Eel initialized with web directory: {self.web_dir}")
def start(self, page='index.html', size=(1920, 1080), port=8080):
"""Start the Eel web server and open the UI"""
theme_page = f'themes/{self.theme}/{page}'
logger.info(f"Starting UI with page: {theme_page}")
# Start Eel (this blocks until window closes)
eel.start(
theme_page,
size=size,
port=port,
close_callback=self._on_close
)
def _on_close(self, page, sockets):
"""Called when the UI window closes"""
logger.info("UI window closed")
def update_voice_input(self, text):
"""Update the voice input display"""
try:
eel.updateVoiceInput(text)
except Exception as e:
logger.error(f"Error updating voice input: {e}")
def update_response(self, text):
"""Update the HAL response display"""
try:
eel.updateResponse(text)
except Exception as e:
logger.error(f"Error updating response: {e}")
def update_logs(self, entry):
"""Add a log entry to the display"""
try:
eel.updateLogs(entry)
except Exception as e:
logger.error(f"Error updating logs: {e}")
def update_toolbar(self, listening, speaking):
"""Update toolbar button states"""
try:
eel.updateToolbar(listening, speaking)
except Exception as e:
logger.error(f"Error updating toolbar: {e}")
def show_page(self, page_name, data=None):
"""Show a specific page/view"""
try:
if data:
eel.showPageFromPython(page_name, data)
else:
eel.showPageFromPython(page_name, None)
except Exception as e:
logger.error(f"Error showing page {page_name}: {e}")
# Factory function for easy instantiation
def create_ui_manager(theme='lcars', ui_type='eel', web_dir='web'):
"""Factory function to create appropriate UI manager"""
if ui_type == 'eel':
return EelUIManager(theme=theme, web_dir=web_dir)
else:
raise ValueError(f"Unknown UI type: {ui_type}")