feat: Clock Widget now registers with WidgetRegistry on initialize
This commit is contained in:
parent
b6144290b9
commit
d5ebd95dc5
|
|
@ -117,7 +117,6 @@ class ClockWidgetPlugin(BasePlugin):
|
||||||
|
|
||||||
def initialize(self):
|
def initialize(self):
|
||||||
"""Initialize the clock widget plugin."""
|
"""Initialize the clock widget plugin."""
|
||||||
self.widget = None
|
|
||||||
self.config = self.load_data('clock_config', {
|
self.config = self.load_data('clock_config', {
|
||||||
'show_seconds': True,
|
'show_seconds': True,
|
||||||
'use_24h': False,
|
'use_24h': False,
|
||||||
|
|
@ -125,6 +124,113 @@ class ClockWidgetPlugin(BasePlugin):
|
||||||
'font_size': 32
|
'font_size': 32
|
||||||
})
|
})
|
||||||
|
|
||||||
|
# Register widget with the system
|
||||||
|
self._register_widget()
|
||||||
|
|
||||||
|
def _register_widget(self):
|
||||||
|
"""Register the clock widget with EU-Utility."""
|
||||||
|
try:
|
||||||
|
from core.widget_registry import get_widget_registry
|
||||||
|
from core.widget_system import BaseWidget, WidgetConfig
|
||||||
|
|
||||||
|
registry = get_widget_registry()
|
||||||
|
|
||||||
|
# Widget creator function
|
||||||
|
def create_clock_widget():
|
||||||
|
"""Create a clock widget instance."""
|
||||||
|
# Create with proper window flags for overlay
|
||||||
|
widget = BaseWidget("clock", "Clock", WidgetConfig(
|
||||||
|
width=220,
|
||||||
|
height=120,
|
||||||
|
x=100,
|
||||||
|
y=100
|
||||||
|
))
|
||||||
|
|
||||||
|
# Add clock content
|
||||||
|
from PyQt6.QtWidgets import QLabel, QVBoxLayout
|
||||||
|
from PyQt6.QtCore import Qt, QTimer, QTime, QDate
|
||||||
|
|
||||||
|
# Clear default content and add our own
|
||||||
|
# Remove all existing widgets from content_layout
|
||||||
|
while widget.content_layout.count():
|
||||||
|
item = widget.content_layout.takeAt(0)
|
||||||
|
if item.widget():
|
||||||
|
item.widget().deleteLater()
|
||||||
|
|
||||||
|
# Time label
|
||||||
|
time_label = QLabel("--:--:--")
|
||||||
|
time_label.setStyleSheet("""
|
||||||
|
QLabel {
|
||||||
|
color: #4ecdc4;
|
||||||
|
font-size: 28px;
|
||||||
|
font-weight: bold;
|
||||||
|
font-family: 'Consolas', 'Monaco', monospace;
|
||||||
|
}
|
||||||
|
""")
|
||||||
|
time_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||||
|
widget.content_layout.addWidget(time_label)
|
||||||
|
|
||||||
|
# Date label
|
||||||
|
date_label = QLabel("----/--/--")
|
||||||
|
date_label.setStyleSheet("""
|
||||||
|
QLabel {
|
||||||
|
color: rgba(255, 255, 255, 150);
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
""")
|
||||||
|
date_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||||
|
widget.content_layout.addWidget(date_label)
|
||||||
|
|
||||||
|
# Update timer
|
||||||
|
def update_time():
|
||||||
|
current_time = QTime.currentTime()
|
||||||
|
current_date = QDate.currentDate()
|
||||||
|
|
||||||
|
# Use config for 12/24h format
|
||||||
|
use_24h = self.config.get('use_24h', False)
|
||||||
|
show_seconds = self.config.get('show_seconds', True)
|
||||||
|
|
||||||
|
if use_24h:
|
||||||
|
if show_seconds:
|
||||||
|
time_text = current_time.toString("HH:mm:ss")
|
||||||
|
else:
|
||||||
|
time_text = current_time.toString("HH:mm")
|
||||||
|
else:
|
||||||
|
if show_seconds:
|
||||||
|
time_text = current_time.toString("hh:mm:ss AP")
|
||||||
|
else:
|
||||||
|
time_text = current_time.toString("hh:mm AP")
|
||||||
|
|
||||||
|
time_label.setText(time_text)
|
||||||
|
|
||||||
|
if self.config.get('show_date', True):
|
||||||
|
date_label.setText(current_date.toString("yyyy-MM-dd"))
|
||||||
|
date_label.show()
|
||||||
|
else:
|
||||||
|
date_label.hide()
|
||||||
|
|
||||||
|
timer = QTimer(widget)
|
||||||
|
timer.timeout.connect(update_time)
|
||||||
|
timer.start(1000)
|
||||||
|
update_time()
|
||||||
|
|
||||||
|
return widget
|
||||||
|
|
||||||
|
# Register with the system
|
||||||
|
registry.register_widget(
|
||||||
|
widget_id="clock",
|
||||||
|
name="Clock",
|
||||||
|
description="A customizable clock with 12/24h format and date display",
|
||||||
|
icon="⏰",
|
||||||
|
creator=create_clock_widget,
|
||||||
|
plugin_id="clock_widget"
|
||||||
|
)
|
||||||
|
|
||||||
|
print("[ClockWidget] Registered with widget system")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"[ClockWidget] Failed to register widget: {e}")
|
||||||
|
|
||||||
def get_ui(self):
|
def get_ui(self):
|
||||||
"""Create the plugin settings UI."""
|
"""Create the plugin settings UI."""
|
||||||
from PyQt6.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QLabel
|
from PyQt6.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QLabel
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue