forked from AG_QGIS/Plugin_SN_Basis
35 lines
1.1 KiB
Python
35 lines
1.1 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(text, self.iface.mainWindow())
|
|
if icon:
|
|
action.setIcon(icon)
|
|
if tooltip:
|
|
action.setToolTip(tooltip)
|
|
action.triggered.connect(callback)
|
|
|
|
self.actions.append((priority, action))
|
|
return action
|
|
|
|
def finalize_menu_and_toolbar(self):
|
|
# Menü und Toolbar leeren
|
|
self.menu.clear()
|
|
self.toolbar.clear()
|
|
|
|
# Sortiert nach Priority einfügen
|
|
for _, action in sorted(self.actions, key=lambda x: x[0]):
|
|
self.menu.addAction(action)
|
|
self.toolbar.addAction(action)
|