From 81c26a07d3e4d80961d070387f328c39f7edfe93 Mon Sep 17 00:00:00 2001 From: devmatrix Date: Mon, 16 Feb 2026 23:54:26 +0000 Subject: [PATCH] fix: Add Widget and WidgetConfig classes to fix import errors --- premium/__init__.py | 2 +- premium/widgets/base.py | 75 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 74 insertions(+), 3 deletions(-) diff --git a/premium/__init__.py b/premium/__init__.py index c8d3829..f077184 100644 --- a/premium/__init__.py +++ b/premium/__init__.py @@ -39,7 +39,7 @@ from premium.plugins.manager import PluginManager # Widget system from premium.widgets.base import Widget, WidgetConfig -from premium.widgets.dashboard import Dashboard +from premium.widgets.dashboard_widget import DashboardWidget # EU Integration from premium.eu_integration.game_client import GameClient diff --git a/premium/widgets/base.py b/premium/widgets/base.py index bd75559..0b8b193 100644 --- a/premium/widgets/base.py +++ b/premium/widgets/base.py @@ -5,14 +5,85 @@ EU-Utility Premium - Base Widget Components Base widget classes and components for building custom widgets. """ -from .dashboard_widget import DashboardWidget, WidgetHeader, WidgetContent +from dataclasses import dataclass, field +from typing import Any, Dict, Optional, Callable +from PyQt6.QtWidgets import QWidget, QVBoxLayout, QFrame, QLabel +from PyQt6.QtCore import Qt + + +@dataclass +class WidgetConfig: + """Configuration for a widget.""" + name: str = "Widget" + description: str = "" + refresh_interval: int = 1000 # ms + size: tuple = (300, 200) + position: tuple = (0, 0) + settings: Dict[str, Any] = field(default_factory=dict) + + +class Widget(QFrame): + """Base class for all dashboard widgets.""" + + def __init__(self, config: Optional[WidgetConfig] = None, parent=None): + super().__init__(parent) + self.config = config or WidgetConfig() + self._setup_ui() + + def _setup_ui(self): + """Setup the widget UI. Override in subclasses.""" + self.setFrameStyle(QFrame.Shape.StyledPanel) + self.layout = QVBoxLayout(self) + self.layout.setContentsMargins(10, 10, 10, 10) + + # Default header + self.header = QLabel(self.config.name) + self.header.setStyleSheet("font-weight: bold; font-size: 14px;") + self.layout.addWidget(self.header) + + def update_data(self, data: Any): + """Update widget with new data. Override in subclasses.""" + pass + + def refresh(self): + """Refresh widget content. Override in subclasses.""" + pass + + +class WidgetHeader(QFrame): + """Header component for widgets.""" + + def __init__(self, title: str = "", parent=None): + super().__init__(parent) + self.title = title + self._setup_ui() + + def _setup_ui(self): + self.layout = QVBoxLayout(self) + self.label = QLabel(self.title) + self.label.setStyleSheet("font-weight: bold;") + self.layout.addWidget(self.label) + + +class WidgetContent(QFrame): + """Content container for widgets.""" + + def __init__(self, parent=None): + super().__init__(parent) + self.layout = QVBoxLayout(self) + + +# Import concrete widgets +from .dashboard_widget import DashboardWidget from .metrics_card import MetricsCard, StatItem from .chart_widget import ChartWidget, ChartType __all__ = [ - 'DashboardWidget', + 'Widget', + 'WidgetConfig', 'WidgetHeader', 'WidgetContent', + 'DashboardWidget', 'MetricsCard', 'StatItem', 'ChartWidget',