mirror of https://gitlab.com/pamhyr/pamhyr2
92 lines
2.8 KiB
Python
92 lines
2.8 KiB
Python
# MainWindowTabGraph.py -- Pamhyr
|
|
# Copyright (C) 2026 INRAE
|
|
#
|
|
# 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 3 of the License, or
|
|
# (at your option) any later version.
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from View.Tools.Plot.PamhyrCanvas import MplCanvas
|
|
from View.Tools.Plot.PamhyrToolbar import PamhyrPlotToolbar
|
|
from View.PlotXY import PlotXY
|
|
from View.Network.GraphWidget import GraphWidget
|
|
|
|
from PyQt5.QtWidgets import QWidget, QHBoxLayout, QVBoxLayout
|
|
|
|
|
|
class WidgetGraph(QWidget):
|
|
"""Read-only network graph displayed in the main window."""
|
|
|
|
def __init__(self, study=None, trad=None, parent=None):
|
|
super(WidgetGraph, self).__init__(parent)
|
|
|
|
self._study = study
|
|
self._trad = trad
|
|
|
|
layout = QHBoxLayout(self)
|
|
self._graph_widget = None
|
|
|
|
self._graph_layout = QVBoxLayout()
|
|
layout.addLayout(self._graph_layout, 1)
|
|
|
|
self.canvas = MplCanvas(width=5, height=4, dpi=100)
|
|
self.canvas.setObjectName("canvas_graph")
|
|
self.toolbar = PamhyrPlotToolbar(
|
|
self.canvas, self,
|
|
items=["home", "zoom", "save", "iso", "back/forward", "move"]
|
|
)
|
|
self._plot_layout = QVBoxLayout()
|
|
self._plot_layout.addWidget(self.toolbar)
|
|
self._plot_layout.addWidget(self.canvas)
|
|
layout.addLayout(self._plot_layout, 1)
|
|
|
|
self.plot = PlotXY(
|
|
canvas=self.canvas,
|
|
data=None,
|
|
trad=self._trad,
|
|
toolbar=self.toolbar,
|
|
parent=self
|
|
)
|
|
|
|
@property
|
|
def study(self):
|
|
return self._study
|
|
|
|
@study.setter
|
|
def study(self, study):
|
|
self._study = study
|
|
|
|
def update(self):
|
|
if (self._graph_widget is not None
|
|
and (self._study is None
|
|
or self._graph_widget.graph is not self._study.river)):
|
|
self._graph_layout.removeWidget(self._graph_widget)
|
|
self._graph_widget.deleteLater()
|
|
self._graph_widget = None
|
|
|
|
if self._study is not None and self._graph_widget is None:
|
|
self._graph_widget = GraphWidget(
|
|
self._study.river,
|
|
parent=self,
|
|
only_display=True,
|
|
trad=self._trad,
|
|
)
|
|
self._graph_layout.addWidget(self._graph_widget)
|
|
|
|
data = None
|
|
geotiff = None
|
|
if self._study is not None:
|
|
data = self._study.river.enable_edges()
|
|
geotiff = self._study.river.geotiff
|
|
|
|
self.plot = PlotXY(
|
|
canvas=self.canvas,
|
|
data=data,
|
|
geotiff=geotiff,
|
|
trad=self._trad,
|
|
toolbar=self.toolbar,
|
|
parent=self
|
|
)
|
|
self.plot.update() |