fix: Add Widget and WidgetConfig classes to fix import errors
This commit is contained in:
parent
665d140b49
commit
81c26a07d3
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
Loading…
Reference in New Issue