""" EU-Utility - Widgets View (Core Framework Component) Shows registered widgets from plugins. """ from PyQt6.QtWidgets import ( QWidget, QVBoxLayout, QHBoxLayout, QLabel, QPushButton, QFrame, QScrollArea, QGridLayout ) from PyQt6.QtCore import Qt from core.icon_manager import get_icon_manager class WidgetsView(QWidget): """Widgets management interface - shows registered widgets from plugins.""" def __init__(self, overlay_window, parent=None): super().__init__(parent) self.overlay = overlay_window self.plugin_manager = overlay_window.plugin_manager if hasattr(overlay_window, 'plugin_manager') else None self.icon_manager = get_icon_manager() self._setup_ui() def _setup_ui(self): """Create the widgets UI.""" layout = QVBoxLayout(self) layout.setSpacing(16) layout.setContentsMargins(24, 24, 24, 24) # Header with icon header_layout = QHBoxLayout() header_layout.setSpacing(12) header_icon = QLabel() header_pixmap = self.icon_manager.get_pixmap("widgets", size=28) header_icon.setPixmap(header_pixmap) header_layout.addWidget(header_icon) header = QLabel("Widgets") header.setStyleSheet("font-size: 24px; font-weight: bold; color: white;") header_layout.addWidget(header) header_layout.addStretch() layout.addLayout(header_layout) # Info label info = QLabel("Manage overlay widgets for in-game use. Enable widgets to show them on the activity bar.") info.setStyleSheet("color: rgba(255,255,255,150); font-size: 13px;") info.setWordWrap(True) layout.addWidget(info) # Scroll area for widgets scroll = QScrollArea() scroll.setWidgetResizable(True) scroll.setStyleSheet("background: transparent; border: none;") scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff) self.widgets_container = QWidget() self.widgets_layout = QVBoxLayout(self.widgets_container) self.widgets_layout.setAlignment(Qt.AlignmentFlag.AlignTop) self.widgets_layout.setSpacing(12) self._populate_widgets() scroll.setWidget(self.widgets_container) layout.addWidget(scroll) def _populate_widgets(self): """Populate the widgets list from registered widgets.""" # Clear existing while self.widgets_layout.count(): item = self.widgets_layout.takeAt(0) if item.widget(): item.widget().deleteLater() # Get widgets from widget registry widgets = [] try: from core.widget_registry import get_widget_registry registry = get_widget_registry() widgets = registry.get_all_widgets() except ImportError: pass # Also check plugins for widgets plugin_widgets = [] if self.plugin_manager: try: all_plugins = self.plugin_manager.get_all_plugins() for plugin in all_plugins: if hasattr(plugin, 'get_widgets'): plugin_widgets.extend(plugin.get_widgets()) except: pass # Hardcoded widgets for now until registry is fully implemented builtin_widgets = [ { 'id': 'clock', 'name': 'Clock Widget', 'description': 'Digital clock with date display for activity bar', 'plugin': 'Clock Widget', 'enabled': True }, { 'id': 'system_monitor', 'name': 'System Monitor', 'description': 'CPU and RAM usage display', 'plugin': 'System Tools', 'enabled': False }, { 'id': 'skill_tracker', 'name': 'Skill Tracker Mini', 'description': 'Quick view of skill gains', 'plugin': 'Skill Scanner', 'enabled': False }, ] all_widgets = widgets + plugin_widgets + builtin_widgets if not all_widgets: no_widgets = QLabel("No widgets available.\n\nInstall plugins that provide widgets to see them here.") no_widgets.setStyleSheet("color: rgba(255,255,255,100); padding: 40px;") no_widgets.setAlignment(Qt.AlignmentFlag.AlignCenter) self.widgets_layout.addWidget(no_widgets) return for widget_info in all_widgets: widget_card = self._create_widget_card(widget_info) self.widgets_layout.addWidget(widget_card) self.widgets_layout.addStretch() def _create_widget_card(self, widget_info) -> QFrame: """Create a widget card.""" card = QFrame() card.setStyleSheet(""" QFrame { background: rgba(255, 255, 255, 0.03); border-radius: 12px; padding: 4px; } QFrame:hover { background: rgba(255, 255, 255, 0.05); } """) layout = QHBoxLayout(card) layout.setContentsMargins(16, 12, 16, 12) layout.setSpacing(12) # Enable checkbox enabled = widget_info.get('enabled', False) cb = QCheckBox() cb.setChecked(enabled) cb.setToolTip("Enable/disable widget on activity bar") layout.addWidget(cb) # Widget info info_layout = QVBoxLayout() info_layout.setSpacing(4) # Name and plugin name_row = QHBoxLayout() name = QLabel(widget_info.get('name', 'Unknown Widget')) name.setStyleSheet("color: white; font-size: 14px; font-weight: 500;") name_row.addWidget(name) plugin = widget_info.get('plugin', '') if plugin: plugin_label = QLabel(f"via {plugin}") plugin_label.setStyleSheet("color: rgba(255,140,66,0.8); font-size: 11px;") name_row.addWidget(plugin_label) name_row.addStretch() info_layout.addLayout(name_row) # Description desc = widget_info.get('description', 'No description') desc_label = QLabel(desc) desc_label.setStyleSheet("color: rgba(255,255,255,120); font-size: 12px;") desc_label.setWordWrap(True) info_layout.addWidget(desc_label) layout.addLayout(info_layout, 1) # Preview button preview_btn = QPushButton("Preview") preview_btn.setStyleSheet(""" QPushButton { background: rgba(255, 140, 66, 0.2); color: #ff8c42; border: 1px solid rgba(255, 140, 66, 0.3); border-radius: 6px; padding: 6px 12px; font-size: 11px; } QPushButton:hover { background: rgba(255, 140, 66, 0.3); } """) layout.addWidget(preview_btn) return card