""" Base Plugin class for EU-Utility plugin system. All plugins must inherit from this class. """ from abc import ABC, abstractmethod from typing import Optional, Any, Dict, List class BasePlugin(ABC): """ Abstract base class for all EU-Utility plugins. Plugins must implement: - name: Plugin identifier - description: Brief description - version: Plugin version - on_start(): Initialization logic - on_stop(): Cleanup logic """ # Plugin metadata (override in subclass) name: str = "base_plugin" description: str = "Base plugin class" version: str = "1.0.0" author: str = "Unknown" def __init__(self): self._initialized = False self._config: Dict[str, Any] = {} self._clipboard_manager: Optional[Any] = None @abstractmethod def on_start(self) -> None: """Called when the plugin is started. Initialize resources here.""" pass @abstractmethod def on_stop(self) -> None: """Called when the plugin is stopped. Clean up resources here.""" pass def is_initialized(self) -> bool: """Check if the plugin has been initialized.""" return self._initialized def get_config(self) -> Dict[str, Any]: """Get plugin configuration.""" return self._config.copy() def set_config(self, config: Dict[str, Any]) -> None: """Set plugin configuration.""" self._config = config.copy() # Clipboard Service Integration def _set_clipboard_manager(self, manager: Any) -> None: """Internal method to set the clipboard manager reference.""" self._clipboard_manager = manager def copy_to_clipboard(self, text: str) -> bool: """ Copy text to the system clipboard. Args: text: The text to copy Returns: True if successful, False otherwise Example: # Copy coordinates to clipboard self.copy_to_clipboard("123, 456") """ if self._clipboard_manager is None: print(f"[{self.name}] Clipboard manager not available") return False return self._clipboard_manager.copy(text, source=self.name) def paste_from_clipboard(self) -> Optional[str]: """ Get the current content from the system clipboard. Returns: The clipboard content, or None if unavailable Example: # Read user-pasted value user_input = self.paste_from_clipboard() if user_input: process_input(user_input) """ if self._clipboard_manager is None: print(f"[{self.name}] Clipboard manager not available") return None return self._clipboard_manager.paste() def get_clipboard_history(self, limit: Optional[int] = None) -> List[Dict[str, Any]]: """ Get the clipboard history. Args: limit: Maximum number of entries to return (default: all) Returns: List of clipboard history entries as dictionaries Example: # Get last 10 clipboard entries history = self.get_clipboard_history(limit=10) for entry in history: print(f"{entry['timestamp']}: {entry['content']}") """ if self._clipboard_manager is None: print(f"[{self.name}] Clipboard manager not available") return [] entries = self._clipboard_manager.get_history(limit=limit) return [entry.to_dict() for entry in entries] def clear_clipboard_history(self) -> None: """Clear the clipboard history.""" if self._clipboard_manager is None: print(f"[{self.name}] Clipboard manager not available") return self._clipboard_manager.clear_history() def __repr__(self) -> str: return f"{self.__class__.__name__}(name='{self.name}', version='{self.version}')"