92 lines
2.4 KiB
Python
92 lines
2.4 KiB
Python
"""
|
|
EU-Utility Premium - Base Widget Components
|
|
============================================
|
|
|
|
Base widget classes and components for building custom widgets.
|
|
"""
|
|
|
|
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__ = [
|
|
'Widget',
|
|
'WidgetConfig',
|
|
'WidgetHeader',
|
|
'WidgetContent',
|
|
'DashboardWidget',
|
|
'MetricsCard',
|
|
'StatItem',
|
|
'ChartWidget',
|
|
'ChartType',
|
|
]
|