forked from AG_QGIS/Plugin_SN_Basis
Menü und Symbolleiste überarbeitet.
This commit is contained in:
@@ -3,6 +3,7 @@ from qgis.PyQt.QtWidgets import QDockWidget, QTabWidget
|
||||
class BaseDockWidget(QDockWidget):
|
||||
base_title = "LNO Sachsen"
|
||||
tabs = []
|
||||
action = None # Referenz auf die Toolbar-Action
|
||||
|
||||
def __init__(self, parent=None, subtitle=""):
|
||||
super().__init__(parent)
|
||||
@@ -11,11 +12,17 @@ class BaseDockWidget(QDockWidget):
|
||||
title = self.base_title if not subtitle else f"{self.base_title} | {subtitle}"
|
||||
self.setWindowTitle(title)
|
||||
|
||||
# Dock fixieren (Nur schließen erlaubt)
|
||||
# Dock fixieren (nur schließen erlaubt)
|
||||
self.setFeatures(QDockWidget.DockWidgetFeature.DockWidgetClosable)
|
||||
|
||||
|
||||
# Tabs hinzufügen
|
||||
tab_widget = QTabWidget()
|
||||
for tab_class in self.tabs:
|
||||
tab_widget.addTab(tab_class(), getattr(tab_class, "tab_title", tab_class.__name__))
|
||||
self.setWidget(tab_widget)
|
||||
|
||||
def closeEvent(self, event):
|
||||
"""Wird aufgerufen, wenn das Dock geschlossen wird."""
|
||||
if self.action:
|
||||
self.action.setChecked(False) # Toolbar-Button zurücksetzen
|
||||
super().closeEvent(event)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from qgis.PyQt.QtWidgets import QAction, QMenu, QToolBar
|
||||
from qgis.PyQt.QtWidgets import QAction, QMenu, QToolBar, QActionGroup
|
||||
|
||||
class Navigation:
|
||||
def __init__(self, iface):
|
||||
@@ -12,23 +12,39 @@ class Navigation:
|
||||
self.toolbar = QToolBar("LNO Sachsen")
|
||||
iface.addToolBar(self.toolbar)
|
||||
|
||||
def add_action(self, text, callback, tooltip="", priority=100, icon=None):
|
||||
# Gruppe für exklusive Auswahl (nur ein Plugin aktiv)
|
||||
self.plugin_group = QActionGroup(iface.mainWindow())
|
||||
self.plugin_group.setExclusive(True)
|
||||
|
||||
def add_action(self, text, callback, tooltip="", priority=100):
|
||||
action = QAction(text, self.iface.mainWindow())
|
||||
if icon:
|
||||
action.setIcon(icon)
|
||||
if tooltip:
|
||||
action.setToolTip(tooltip)
|
||||
action.setCheckable(True) # Button kann aktiv sein
|
||||
action.triggered.connect(callback)
|
||||
|
||||
# Action in Gruppe aufnehmen
|
||||
self.plugin_group.addAction(action)
|
||||
|
||||
# Action mit Priority speichern
|
||||
self.actions.append((priority, action))
|
||||
return action
|
||||
|
||||
def finalize_menu_and_toolbar(self):
|
||||
# Menü und Toolbar leeren
|
||||
self.menu.clear()
|
||||
self.toolbar.clear()
|
||||
# Sortieren nach Priority
|
||||
self.actions.sort(key=lambda x: x[0])
|
||||
|
||||
# Sortiert nach Priority einfügen
|
||||
for _, action in sorted(self.actions, 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)
|
||||
|
||||
def set_active_plugin(self, active_action):
|
||||
# Alle zurücksetzen, dann aktives Plugin markieren
|
||||
for _, action in self.actions:
|
||||
action.setChecked(False)
|
||||
active_action.setChecked(True)
|
||||
|
||||
Reference in New Issue
Block a user