Source code for macro_plugin.plugin

#  Copyright (c) 2025-2026 macro-qgis-plugin contributors.
#
#
#  This file is part of macro-qgis-plugin.
#
#  macro-qgis-plugin is free software: you can redistribute it and/or
#  modify it under the terms of the GNU General Public License as published
#  by the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  macro-qgis-plugin is distributed in the hope that it will be
#  useful, but WITHOUT ANY WARRANTY; without even the implied warranty
#  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with macro-qgis-plugin. If not, see <https://www.gnu.org/licenses/>.

"""Main QGIS plugin class that registers the macro dev tool."""

from typing import TYPE_CHECKING, cast

import qgis_macros
import qgis_plugin_tools
from qgis.PyQt.QtCore import QObject
from qgis.utils import iface as iface_
from qgis_plugin_tools.tools.custom_logging import (
    setup_loggers,
)
from qgis_plugin_tools.tools.i18n import tr

import macro_plugin
from macro_plugin.ui.macro_panel import MacroToolFactory

if TYPE_CHECKING:
    from qgis.gui import QgisInterface

iface = cast("QgisInterface", iface_)


[docs] class MacroPlugin(QObject): """QGIS plugin that provides macro recording and playback in dev tools.""" name = tr("Macros") def __init__(self) -> None: """Initialize the plugin and create the macro tool factory.""" super().__init__(parent=None) self._teardown_loggers = lambda: None self._macro_factory = MacroToolFactory()
[docs] def initGui(self) -> None: # noqa: N802 """Set up loggers and register the macro panel factory.""" self._teardown_loggers = setup_loggers( qgis_macros.__name__, macro_plugin.__name__, qgis_plugin_tools.__name__, message_log_name=self.name, ) # Register the macro panel via factory iface.registerDevToolWidgetFactory(self._macro_factory)
[docs] def unload(self) -> None: """Tear down loggers and unregister the macro panel factory.""" self._teardown_loggers() self._teardown_loggers = lambda: None iface.unregisterDevToolWidgetFactory(self._macro_factory)