Files
flares-plugins/test-plugin/__init__.py
T
2026-09-01 16:27:28 -07:00

68 lines
2.4 KiB
Python

"""
Basic Test Plugin
Creates a widget window and registers submenu items under the Plugins menu.
"""
from PySide6.QtGui import QAction
from PySide6.QtWidgets import QLabel, QMenu, QMessageBox, QPushButton, QVBoxLayout, QWidget
class PluginWidget(QWidget):
"""Custom widget UI owned by the plugin."""
def __init__(self, parent: QWidget | None = None) -> None:
super().__init__(parent)
self.setWindowTitle("Test Plugin Window")
self.resize(350, 200)
layout = QVBoxLayout(self)
label = QLabel("Hello from the Test Plugin!", self)
btn_action = QPushButton("Click Me", self)
btn_action.clicked.connect(self._on_button_clicked)
layout.addWidget(label)
layout.addWidget(btn_action)
def _on_button_clicked(self) -> None:
QMessageBox.information(self, "Plugin Interactive", "Button inside the plugin QWidget was clicked!")
class Plugin:
"""Plugin entry point contract loaded by the main application."""
def __init__(self, main_window: QWidget) -> None:
self.main_window = main_window
self.name = "Test Plugin"
self.widget_instance: PluginWidget | None = None
def register_menu(self, plugin_menu: QMenu) -> None:
"""
Populates the plugin's dedicated submenu in the main menubar.
Called by the main app after creating the submenu header.
"""
open_action = QAction("Open Tool Window", self.main_window)
open_action.triggered.connect(self.show_widget)
about_action = QAction("About Test Plugin", self.main_window)
about_action.triggered.connect(self.show_about)
plugin_menu.addAction(open_action)
plugin_menu.addAction(about_action)
def show_widget(self) -> None:
"""Instantiates and displays the plugin's QWidget window."""
if self.widget_instance is None or not self.widget_instance.isVisible():
self.widget_instance = PluginWidget()
self.widget_instance.show()
else:
self.widget_instance.raise_()
self.widget_instance.activateWindow()
def show_about(self) -> None:
"""Secondary menu action example."""
QMessageBox.about(
self.main_window,
"About Test Plugin",
"This is a basic test plugin demonstrating submenu registration and custom QWidget window spawning.",
)