38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
from qgis.PyQt.QtWidgets import QAction, QMenu, QToolBar
|
|
|
|
class Navigation:
|
|
def __init__(self, iface):
|
|
self.iface = iface
|
|
self.actions = []
|
|
|
|
# Menü und Toolbar einmalig anlegen
|
|
self.menu = QMenu("LNO Sachsen", iface.mainWindow())
|
|
iface.mainWindow().menuBar().addMenu(self.menu)
|
|
|
|
self.toolbar = QToolBar("LNO Sachsen")
|
|
iface.addToolBar(self.toolbar)
|
|
|
|
def add_action(self, text, callback, tooltip="", priority=100, icon=None):
|
|
action = QAction(icon, text, self.iface.mainWindow()) if icon else QAction(text, self.iface.mainWindow())
|
|
if tooltip:
|
|
action.setToolTip(tooltip)
|
|
action.triggered.connect(callback)
|
|
|
|
# Action mit Priority speichern
|
|
self.actions.append((priority, action))
|
|
return action
|
|
|
|
def finalize_menu_and_toolbar(self):
|
|
# Sortieren nach Priority
|
|
self.actions.sort(key=lambda x: x[0])
|
|
|
|
# Menüeinträge
|
|
self.menu.clear()
|
|
for _, action in self.actions:
|
|
self.menu.addAction(action)
|
|
|
|
# Toolbar-Einträge
|
|
self.toolbar.clear()
|
|
for _, action in self.actions:
|
|
self.toolbar.addAction(action)
|