Ablauf optimiert, Styles laden implementiert
This commit is contained in:
44
functions/messages.py
Normal file
44
functions/messages.py
Normal file
@@ -0,0 +1,44 @@
|
||||
# sn_basis/functions/messages.py
|
||||
|
||||
from typing import Optional
|
||||
from qgis.core import Qgis
|
||||
from qgis.PyQt.QtWidgets import QWidget
|
||||
from qgis.utils import iface
|
||||
|
||||
|
||||
def push_message(
|
||||
level: Qgis.MessageLevel,
|
||||
title: str,
|
||||
text: str,
|
||||
duration: Optional[int] = 5,
|
||||
parent: Optional[QWidget] = None,
|
||||
):
|
||||
"""
|
||||
Zeigt eine Meldung in der QGIS-MessageBar.
|
||||
- level: Qgis.Success | Qgis.Info | Qgis.Warning | Qgis.Critical
|
||||
- title: Überschrift links (kurz halten)
|
||||
- text: eigentliche Nachricht
|
||||
- duration: Sekunden bis Auto-Ausblendung; None => bleibt sichtbar (mit Close-Button)
|
||||
- parent: optionales Eltern-Widget (für Kontext), normalerweise nicht nötig
|
||||
Rückgabe: MessageBarItem-Widget (kann später geschlossen/entfernt werden).
|
||||
"""
|
||||
bar = iface.messageBar()
|
||||
# QGIS akzeptiert None als "sticky" Meldung
|
||||
return bar.pushMessage(title, text, level=level, duration=duration)
|
||||
|
||||
|
||||
def success(title: str, text: str, duration: int = 5):
|
||||
return push_message(Qgis.Success, title, text, duration)
|
||||
|
||||
|
||||
def info(title: str, text: str, duration: int = 5):
|
||||
return push_message(Qgis.Info, title, text, duration)
|
||||
|
||||
|
||||
def warning(title: str, text: str, duration: int = 5):
|
||||
return push_message(Qgis.Warning, title, text, duration)
|
||||
|
||||
|
||||
def error(title: str, text: str, duration: Optional[int] = 5):
|
||||
# Fehler evtl. länger sichtbar lassen; setze duration=None falls gewünscht
|
||||
return push_message(Qgis.Critical, title, text, duration)
|
||||
Reference in New Issue
Block a user