Initial commit
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/__pycache__/
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
30
plugin.py
30
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
|
||||
|
||||
Reference in New Issue
Block a user