diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..00983fe --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/__pycache__/ \ No newline at end of file diff --git a/__pycache__/__init__.cpython-312.pyc b/__pycache__/__init__.cpython-312.pyc deleted file mode 100644 index 16de37c..0000000 Binary files a/__pycache__/__init__.cpython-312.pyc and /dev/null differ diff --git a/__pycache__/api_client.cpython-312.pyc b/__pycache__/api_client.cpython-312.pyc deleted file mode 100644 index 597ca54..0000000 Binary files a/__pycache__/api_client.cpython-312.pyc and /dev/null differ diff --git a/__pycache__/layer_manager.cpython-312.pyc b/__pycache__/layer_manager.cpython-312.pyc deleted file mode 100644 index 6badb2f..0000000 Binary files a/__pycache__/layer_manager.cpython-312.pyc and /dev/null differ diff --git a/__pycache__/notification_server.cpython-312.pyc b/__pycache__/notification_server.cpython-312.pyc deleted file mode 100644 index 2a6abe5..0000000 Binary files a/__pycache__/notification_server.cpython-312.pyc and /dev/null differ diff --git a/__pycache__/plugin.cpython-312.pyc b/__pycache__/plugin.cpython-312.pyc deleted file mode 100644 index dd66462..0000000 Binary files a/__pycache__/plugin.cpython-312.pyc and /dev/null differ diff --git a/plugin.py b/plugin.py index 2055e4d..6354107 100644 --- a/plugin.py +++ b/plugin.py @@ -1,4 +1,6 @@ +import os from PyQt5.QtCore import QTimer +from PyQt5.QtGui import QIcon from PyQt5.QtWidgets import QAction from qgis.core import Qgis, QgsProject from qgis.gui import QgisInterface @@ -40,17 +42,37 @@ class BAPEBridgePlugin: # ------------------------------------------------------------------ def initGui(self) -> None: - """Add entry to the Layer menu.""" - self._toggle_action = QAction("BAPE Bridge", self._iface.mainWindow()) + """Add entry to the Layer menu, after 'Add From Layer Definition File'.""" + icon = QIcon(os.path.join(os.path.dirname(__file__), "icon.png")) + self._toggle_action = QAction(icon, "BAPE Bridge", self._iface.mainWindow()) self._toggle_action.setCheckable(True) self._toggle_action.setToolTip("Enable / disable the BAPE Bridge layer") self._toggle_action.triggered.connect(self._on_toggle) - self._iface.addPluginToLayerMenu("BAPE Bridge", self._toggle_action) + + layer_menu = self._iface.layerMenu() + # Find the 'Add From Layer Definition File' action and insert after it. + after_action = None + for action in layer_menu.actions(): + if "layer definition" in action.text().lower(): + after_action = action + break + + if after_action is not None: + # insertAction inserts *before* the reference; get the next item instead. + actions = layer_menu.actions() + idx = actions.index(after_action) + next_action = actions[idx + 1] if idx + 1 < len(actions) else None + if next_action is not None: + layer_menu.insertAction(next_action, self._toggle_action) + else: + layer_menu.addAction(self._toggle_action) + else: + layer_menu.addAction(self._toggle_action) def unload(self) -> None: """Clean up when the plugin is disabled or QGIS closes.""" self._deactivate() - self._iface.removePluginFromLayerMenu("BAPE Bridge", self._toggle_action) + self._iface.layerMenu().removeAction(self._toggle_action) # ------------------------------------------------------------------ # Toggle on / off