Navigation in sn_basis ausgelagert

This commit is contained in:
Michael Otto
2025-10-09 13:57:01 +02:00
parent 7adbbe07e4
commit fa0fc55699
3 changed files with 2 additions and 79 deletions

View File

@@ -8,8 +8,7 @@ from qgis.utils import plugins
from .resources import *
# Import der gemeinsamen UI-Klasse für Menü und Symbolleiste
from .shared import UI
#from .shared import DockManager
from sn_basis.ui.navigation import Navigation
# Import des Dockwidgets, das beim Ausführen des Plugins angezeigt wird
from .ui.sn_plan41_dockwidget import Plan41DockWidget
@@ -35,7 +34,7 @@ class Plan41:
"""
self.action_text = "Plan 41" # Einheitlicher Text für Menü und Toolbar
icon = QIcon(":/sn_plugin1/icons/icon.png") # Icon aus Ressourcen laden
self.ui = UI() # Gemeinsame UI-Instanz für Menü und Toolbar
self.ui = Navigation() # Gemeinsame UI-Instanz für Menü und Toolbar
self.ui.add_action(self.action_text, self.run, icon, tooltip="Öffnet Plan41")
def onClosePlugin(self):

View File

@@ -1 +0,0 @@
from .ui import UI

View File

@@ -1,75 +0,0 @@
from qgis.PyQt.QtWidgets import QMenu, QToolBar, QAction
from qgis.PyQt.QtGui import QIcon
from qgis.utils import iface
_shared_toolbar = None # globale Toolbar-Instanz
_shared_menu = None # globale Menü-Instanz
class UI:
TITLE = "LNO Sachsen"
def __init__(self):
self.menu = self._get_or_create_menu()
self.toolbar = self._get_or_create_toolbar()
def _get_or_create_menu(self):
global _shared_menu
if _shared_menu:
return _shared_menu
menubar = iface.mainWindow().menuBar()
for action in menubar.actions():
if action.menu() and action.text() == self.TITLE:
_shared_menu = action.menu()
return _shared_menu
menu = QMenu(self.TITLE, iface.mainWindow())
menu.setObjectName(self.TITLE)
menubar.addMenu(menu)
_shared_menu = menu
return menu
def _get_or_create_toolbar(self):
global _shared_toolbar
if _shared_toolbar:
return _shared_toolbar
main_window = iface.mainWindow()
toolbar = main_window.findChild(QToolBar, self.TITLE)
if not toolbar:
toolbar = QToolBar(self.TITLE, main_window)
toolbar.setObjectName(self.TITLE)
main_window.addToolBar(toolbar)
_shared_toolbar = toolbar
return toolbar
def add_action(self, text, callback, icon=None, tooltip=None):
# Menüeintrag
if not any(a.text() == text for a in self.menu.actions()):
action = QAction(icon, text, iface.mainWindow()) if icon else QAction(text, iface.mainWindow())
if tooltip:
action.setToolTip(tooltip)
action.triggered.connect(callback)
self.menu.addAction(action)
# Symbolleistenaktion
if not any(a.text() == text for a in self.toolbar.actions()):
action = QAction(icon, text, iface.mainWindow()) if icon else QAction(text, iface.mainWindow())
if tooltip:
action.setToolTip(tooltip)
action.triggered.connect(callback)
self.toolbar.addAction(action)
def remove_action(self, text):
# Menüeintrag entfernen
for act in self.menu.actions():
if act.text() == text:
self.menu.removeAction(act)
break
# Symbolleistenaktion entfernen
for act in self.toolbar.actions():
if act.text() == text:
self.toolbar.removeAction(act)
break