cleanup: Remove ClockWidget and SystemMonitorWidget from core

These example widgets are now provided by plugins.
Core widget_system.py now only contains BaseWidget class.
This commit is contained in:
LemonNexus 2026-02-15 16:18:02 +00:00
parent defb83d213
commit 84b73298e8
1 changed files with 0 additions and 214 deletions

View File

@ -359,219 +359,5 @@ class BaseWidget(QFrame):
return cls(data['widget_id'], data['name'], config)
class ClockWidget(BaseWidget):
"""Example clock widget - demonstrates the system."""
def __init__(self, parent=None):
super().__init__("clock", "Clock", parent=parent)
self.time_label = QLabel("--:--:--")
self.time_label.setStyleSheet("""
QLabel {
color: white;
font-size: 24px;
font-weight: bold;
font-family: monospace;
}
""")
self.time_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.content_layout.addWidget(self.time_label)
self.date_label = QLabel("----/--/--")
self.date_label.setStyleSheet("color: rgba(255,255,255,150); font-size: 12px;")
self.date_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.content_layout.addWidget(self.date_label)
# Update timer
self.timer = QTimer(self)
self.timer.timeout.connect(self._update)
self.timer.start(1000) # Update every second
self._update()
def _update(self):
"""Update clock display."""
from datetime import datetime
now = datetime.now()
self.time_label.setText(now.strftime("%H:%M:%S"))
self.date_label.setText(now.strftime("%Y-%m-%d"))
class SystemMonitorWidget(BaseWidget):
"""Example system monitor widget."""
def __init__(self, parent=None):
super().__init__("system", "System Monitor", parent=parent)
self.cpu_label = QLabel("CPU: --%")
self.cpu_label.setStyleSheet("color: #4ecdc4; font-size: 14px;")
self.content_layout.addWidget(self.cpu_label)
self.ram_label = QLabel("RAM: --%")
self.ram_label.setStyleSheet("color: #ff8c42; font-size: 14px;")
self.content_layout.addWidget(self.ram_label)
# Update timer
self.timer = QTimer(self)
self.timer.timeout.connect(self._update)
self.timer.start(2000) # Update every 2 seconds
self._update()
def _update(self):
"""Update system stats."""
try:
import psutil
cpu = psutil.cpu_percent()
ram = psutil.virtual_memory().percent
self.cpu_label.setText(f"CPU: {cpu:.1f}%")
self.ram_label.setText(f"RAM: {ram:.1f}%")
except ImportError:
self.cpu_label.setText("CPU: N/A")
self.ram_label.setText("RAM: N/A")
class WidgetManager(QObject):
"""Manager for overlay widgets.
Handles widget lifecycle, positioning, and persistence.
"""
WIDGETS_FILE = Path("config/widgets.json")
def __init__(self, parent=None):
super().__init__(parent)
self.widgets: Dict[str, BaseWidget] = {}
self.WIDGETS_FILE.parent.mkdir(parents=True, exist_ok=True)
# Load saved widgets
self._load_widgets()
def register_widget_type(self, widget_id: str, widget_class: type, name: str):
"""Register a widget type that plugins can create.
Args:
widget_id: Unique identifier for this widget type
widget_class: Class inheriting from BaseWidget
name: Human-readable name
"""
self._widget_types[widget_id] = {
'class': widget_class,
'name': name
}
def create_widget(self, widget_id: str, instance_id: Optional[str] = None, config: Optional[WidgetConfig] = None) -> BaseWidget:
"""Create a new widget instance.
Args:
widget_id: Type of widget to create
instance_id: Optional unique instance ID
config: Optional configuration
Returns:
Created widget
"""
if instance_id is None:
instance_id = f"{widget_id}_{len(self.widgets)}"
# Create widget (for now, just create built-in types)
if widget_id == "clock":
widget = ClockWidget()
elif widget_id == "system":
widget = SystemMonitorWidget()
else:
# For plugin-created widgets, they'd pass their own class
widget = BaseWidget(instance_id, widget_id, config)
widget.widget_id = instance_id
self.widgets[instance_id] = widget
# Connect signals
widget.moved.connect(lambda x, y, wid=instance_id: self._on_widget_moved(wid, x, y))
widget.closed.connect(lambda wid=instance_id: self._on_widget_closed(wid))
return widget
def show_widget(self, widget_id: str):
"""Show a widget by ID."""
if widget_id in self.widgets:
self.widgets[widget_id].show()
def hide_widget(self, widget_id: str):
"""Hide a widget by ID."""
if widget_id in self.widgets:
self.widgets[widget_id].hide()
def remove_widget(self, widget_id: str):
"""Remove and destroy a widget."""
if widget_id in self.widgets:
self.widgets[widget_id].close()
del self.widgets[widget_id]
self._save_widgets()
def _on_widget_moved(self, widget_id: str, x: int, y: int):
"""Handle widget moved."""
self._save_widgets()
def _on_widget_closed(self, widget_id: str):
"""Handle widget closed."""
if widget_id in self.widgets:
del self.widgets[widget_id]
self._save_widgets()
def _save_widgets(self):
"""Save widget configurations."""
data = {
'widgets': [
widget.save_config()
for widget in self.widgets.values()
]
}
with open(self.WIDGETS_FILE, 'w') as f:
json.dump(data, f, indent=2)
def _load_widgets(self):
"""Load widget configurations."""
self._widget_types = {}
if not self.WIDGETS_FILE.exists():
return
try:
with open(self.WIDGETS_FILE, 'r') as f:
data = json.load(f)
# Recreate widgets (would need widget type registry for full implementation)
for widget_data in data.get('widgets', []):
# For now, skip loading - plugins would recreate their widgets
pass
except Exception as e:
print(f"[WidgetManager] Failed to load widgets: {e}")
def get_all_widgets(self) -> List[BaseWidget]:
"""Get all managed widgets."""
return list(self.widgets.values())
def show_all(self):
"""Show all widgets."""
for widget in self.widgets.values():
widget.show()
def hide_all(self):
"""Hide all widgets."""
for widget in self.widgets.values():
widget.hide()
# Global widget manager instance
_widget_manager: Optional[WidgetManager] = None
def get_widget_manager() -> WidgetManager:
"""Get the global widget manager instance."""
global _widget_manager
if _widget_manager is None:
_widget_manager = WidgetManager()
return _widget_manager