Tools-Menu Plugins

Tools-menu plugins allow you to add custom actions to the Tool Menu located in the top navigation bar. Each plugin appears using the name you provide, and selecting it triggers the function you have linked to that action.

If you have actions that are used less frequently, consider organizing them into a submenu to keep the main Tool Menu concise and easy to navigate.

class wiser.plugins.ToolsMenuPlugin[source]

This is the base type for plugins that integrate into the WISER “Tools” application-menu.

add_tool_menu_items(tool_menu: QMenu, wiser: ApplicationState) None[source]

This method is called by WISER to allow plugins to add menu actions or submenus into the Tools application menu.

If a plugin provides multiple actions, the developer has several choices. If all actions are useful and expected to be invoked regularly, the actions can be added directly to the Tools menu. If some actions are used much less frequently, it is recommended that these actions be put into a submenu, to keep the Tools menu from becoming too cluttered.

Use QMenu.addAction() to add individual actions, or QMenu.addMenu() to add sub-menus to the Tools menu.

Example Tools-Menu Plugin

Okay, lets see an example plugin.

import logging

from wiser.plugins import ToolsMenuPlugin

from PySide2.QtWidgets import QMenu, QMessageBox


logger = logging.getLogger(__name__)


class HelloToolPlugin(ToolsMenuPlugin):
    """
    A simple "Hello world!" example of a Tools plugin.
    """

    def __init__(self):
        super().__init__()

    def add_tool_menu_items(self, tool_menu: QMenu, wiser) -> None:
        """
        Use QMenu.addAction() to add individual actions, or QMenu.addMenu() to
        add sub-menus to the Tools menu.
        """
        logger.info("HelloToolPlugin is adding tool-menu items")
        act = tool_menu.addAction("Say hello...")
        act.triggered.connect(self.say_hello)

    def say_hello(self, checked: bool = False):
        logger.info("HelloToolPlugin.say_hello() was called!")
        QMessageBox.information(None, "Hello-Tool Plugin", "Hello from the toolbar!")