forked from AG_QGIS/Plugin_SN_Basis
Anpassung an den Wrappern für sn_plan41
This commit is contained in:
@@ -2,7 +2,10 @@
|
||||
sn_basis/functions/qgisui_wrapper.py – zentrale QGIS-UI-Abstraktion
|
||||
"""
|
||||
|
||||
from typing import Any, List
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, List, Type
|
||||
|
||||
|
||||
from sn_basis.functions.qt_wrapper import QDockWidget
|
||||
|
||||
@@ -10,18 +13,39 @@ from sn_basis.functions.qt_wrapper import QDockWidget
|
||||
iface: Any
|
||||
QGIS_UI_AVAILABLE = False
|
||||
|
||||
QgsFileWidget: Type[Any]
|
||||
QgsMapLayerComboBox: Type[Any]
|
||||
|
||||
|
||||
# ---------------------------------------------------------
|
||||
# iface initialisieren (QGIS oder Mock)
|
||||
# iface + QGIS-Widgets initialisieren (QGIS oder Mock)
|
||||
# ---------------------------------------------------------
|
||||
|
||||
try:
|
||||
from qgis.utils import iface as _iface
|
||||
from qgis.gui import (
|
||||
QgsFileWidget as _QgsFileWidget,
|
||||
QgsMapLayerComboBox as _QgsMapLayerComboBox,
|
||||
)
|
||||
|
||||
iface = _iface
|
||||
QgsFileWidget = _QgsFileWidget
|
||||
QgsMapLayerComboBox = _QgsMapLayerComboBox
|
||||
QGIS_UI_AVAILABLE = True
|
||||
|
||||
except Exception:
|
||||
|
||||
QGIS_UI_AVAILABLE = False
|
||||
|
||||
class _MockSignal:
|
||||
def __init__(self):
|
||||
self._callbacks: list[Any] = []
|
||||
|
||||
def connect(self, callback):
|
||||
self._callbacks.append(callback)
|
||||
|
||||
def emit(self, *args, **kwargs):
|
||||
for cb in list(self._callbacks):
|
||||
cb(*args, **kwargs)
|
||||
|
||||
class _MockMessageBar:
|
||||
def pushMessage(self, title, text, level=0, duration=5):
|
||||
@@ -53,6 +77,48 @@ except Exception:
|
||||
|
||||
iface = _MockIface()
|
||||
|
||||
class _MockQgsFileWidget:
|
||||
GetFile = 0
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self._path = ""
|
||||
self.fileChanged = _MockSignal()
|
||||
|
||||
def setStorageMode(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def setFilter(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def setFilePath(self, path: str):
|
||||
self._path = path
|
||||
self.fileChanged.emit(path)
|
||||
|
||||
def filePath(self) -> str:
|
||||
return self._path
|
||||
|
||||
class _MockQgsMapLayerComboBox:
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.layerChanged = _MockSignal()
|
||||
self._layer = None
|
||||
self._count = 0
|
||||
|
||||
def setFilters(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def setLayer(self, layer):
|
||||
self._layer = layer
|
||||
self.layerChanged.emit(layer)
|
||||
|
||||
def count(self) -> int:
|
||||
return self._count
|
||||
|
||||
def setCurrentIndex(self, idx: int):
|
||||
pass
|
||||
|
||||
QgsFileWidget = _MockQgsFileWidget
|
||||
QgsMapLayerComboBox = _MockQgsMapLayerComboBox
|
||||
|
||||
|
||||
# ---------------------------------------------------------
|
||||
# Main Window
|
||||
@@ -108,8 +174,6 @@ def add_menu(menu):
|
||||
main_window.menuBar().addMenu(menu)
|
||||
|
||||
|
||||
|
||||
|
||||
def remove_menu(menu):
|
||||
main_window = iface.mainWindow()
|
||||
if not main_window:
|
||||
@@ -119,9 +183,6 @@ def remove_menu(menu):
|
||||
main_window.menuBar().removeAction(menu.menuAction())
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# ---------------------------------------------------------
|
||||
# Toolbar-Handling
|
||||
# ---------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user