Design main window: New tab with network of the study

dev_dylan
Dylan Jeannin 2026-09-07 16:31:35 +02:00
parent 0a0c00d877
commit 499e16975f
3 changed files with 114 additions and 0 deletions

View File

@ -61,6 +61,7 @@ from View.WaitingDialog import WaitingDialog
from View.MainWindowTabInfo import WidgetInfo from View.MainWindowTabInfo import WidgetInfo
from View.MainWindowTabChecker import WidgetChecker from View.MainWindowTabChecker import WidgetChecker
from View.MainWindowTabGraph import WidgetGraph
from View.Configure.Window import ConfigureWindow from View.Configure.Window import ConfigureWindow
from View.Study.Window import NewStudyWindow from View.Study.Window import NewStudyWindow
@ -235,6 +236,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
def setup_tab(self): def setup_tab(self):
self.setup_tab_info() self.setup_tab_info()
self.setup_tab_graph()
self.setup_tab_checker() self.setup_tab_checker()
def setup_tab_info(self): def setup_tab_info(self):
@ -261,6 +263,18 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
self._trad["tab_checker_name"] self._trad["tab_checker_name"]
) )
def setup_tab_graph(self):
tab_widget = self.findChild(QTabWidget, "tabWidget")
self._tab_widget_graph = WidgetGraph(
study=self._study, trad=self._trad, parent=self
)
tab_widget.addTab(
self._tab_widget_graph,
self._trad["tab_graph_name"]
)
def enable_actions(self, action: str, enable: bool): def enable_actions(self, action: str, enable: bool):
"""Enable of disable an action componant """Enable of disable an action componant
@ -545,6 +559,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
self._do_propagate_update_rec(window, keys) self._do_propagate_update_rec(window, keys)
self._tab_widget_checker.update(modules=keys) self._tab_widget_checker.update(modules=keys)
self._tab_widget_graph.update()
def _do_propagate_update_info_tab(self, keys): def _do_propagate_update_info_tab(self, keys):
modules = Modules.modelling_list() modules = Modules.modelling_list()
@ -570,6 +585,10 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
self._tab_widget_info.study = self._study self._tab_widget_info.study = self._study
self._tab_widget_info.update() self._tab_widget_info.update()
if self._tab_widget_graph.study != self._study:
self._tab_widget_graph.study = self._study
self._tab_widget_graph.update()
if self._tab_widget_checker.study != self._study: if self._tab_widget_checker.study != self._study:
self._tab_widget_checker.study = self._study self._tab_widget_checker.study = self._study
self._tab_widget_checker.update(modules=Modules.STUDY) self._tab_widget_checker.update(modules=Modules.STUDY)

View File

@ -0,0 +1,92 @@
# 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()

View File

@ -175,6 +175,9 @@ class MainTranslate(UnitTranslate):
self._dict["tab_checker_name"] = _translate( self._dict["tab_checker_name"] = _translate(
"MainWindow", "Checks" "MainWindow", "Checks"
) )
self._dict["tab_graph_name"] = _translate(
"MainWindow", "Graph"
)
self._dict["open_debug"] = _translate( self._dict["open_debug"] = _translate(
"MainWindow", "Open debug window" "MainWindow", "Open debug window"