87 lines
3.5 KiB
Python
87 lines
3.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
/***************************************************************************
|
|
PegelonlineDockWidgetGraph
|
|
A QGIS plugin
|
|
Stellt Pegelstandsverläufe von Pegelonline grafisch dar
|
|
Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/
|
|
-------------------
|
|
begin : 2025-09-26
|
|
git sha : $Format:%H$
|
|
copyright : (C) 2025 by Katrin Haßel
|
|
email : s6kathom@uni-trier.de
|
|
***************************************************************************/
|
|
|
|
/***************************************************************************
|
|
* *
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
* it under the terms of the GNU General Public License as published by *
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
* (at your option) any later version. *
|
|
* *
|
|
***************************************************************************/
|
|
"""
|
|
|
|
import os
|
|
|
|
from qgis.PyQt import QtWidgets, uic, QtGui
|
|
from qgis.PyQt.QtCore import pyqtSignal
|
|
|
|
from .po_modules.po_graph_reader import PoGraphReader
|
|
|
|
FORM_CLASS, _ = uic.loadUiType(os.path.join(os.path.dirname(__file__), 'pegelonline_dockwidget_graph.ui'))
|
|
|
|
|
|
class PegelonlineDockWidgetGraph(QtWidgets.QDockWidget, FORM_CLASS):
|
|
closingPlugin = pyqtSignal()
|
|
|
|
def __init__(self, parent=None):
|
|
super(PegelonlineDockWidgetGraph, self).__init__(parent)
|
|
self.setupUi(self)
|
|
|
|
def closeEvent(self, event):
|
|
self.closingPlugin.emit()
|
|
event.accept()
|
|
|
|
"""
|
|
Versucht den aktuell gewünschten Pegelstandsverlauf herunterzuladen und im GraphWidget anzuzeigen.
|
|
:param station: Der 'Kurzname' der gewünschten Station
|
|
:type station: str
|
|
:param days: Anzahl der gewünschten vergangenen Tage
|
|
:type days: int
|
|
"""
|
|
|
|
def load(self, station, days):
|
|
print("PegelonlineDockWidgetGraph::load: station=%s days=%s" % (station, days))
|
|
|
|
self.lbGraph.clear()
|
|
self.setWindowTitle("%s / %d Tag(e)" % (station, days))
|
|
self.show()
|
|
|
|
if station == '' or station is None:
|
|
# Keine Station ausgewählt → Abbruch
|
|
print("PegelonlineDockWidgetGraph::load: Fehler: Ungültige Station: %s" % (station,))
|
|
self.lbGraph.setText("Bitte Station wählen...")
|
|
return
|
|
|
|
if days is None or days < 1 or days > 30:
|
|
# Ungültige Anzahl an Tagen ausgewählt → Abbruch
|
|
print("PegelonlineDockWidgetGraph::load: Fehler: Ungültige Anzahl von Tagen: %s" % (days,))
|
|
self.lbGraph.setText("Bitte Tage [1, 30] wählen...")
|
|
return
|
|
|
|
graph = PoGraphReader(station, days)
|
|
image_data = graph.download()
|
|
|
|
if image_data is None or len(image_data) == 0:
|
|
# Keine Bild-Daten beim Herunterladen erhalten → Abbruch
|
|
print("PegelonlineDockWidgetGraph::load: Fehler: Keine Daten erhalten")
|
|
self.lbGraph.setText("Fehler beim Download!")
|
|
return
|
|
|
|
pixmap = QtGui.QPixmap()
|
|
pixmap.loadFromData(image_data)
|
|
self.lbGraph.setPixmap(pixmap)
|
|
self.lbGraph.resize(pixmap.width(), pixmap.height())
|
|
|
|
print("PegelonlineDockWidgetGraph::load: Bild erfolgreich geladen") |