From 3e085dd7c66340537b8d51a5d54f400bc486ef37 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby Date: Tue, 27 Feb 2024 11:46:06 +0100 Subject: [PATCH] MainWindow: Add minimal info tab. --- src/Model/Network/Graph.py | 7 + src/View/MainWindow.py | 33 +++- src/View/MainWindowTabInfo.py | 117 ++++++++++++ src/View/Translate.py | 4 + src/View/ui/MainWindow.ui | 16 ++ src/View/ui/Widgets/MainWindowTabInfo.ui | 229 +++++++++++++++++++++++ 6 files changed, 403 insertions(+), 3 deletions(-) create mode 100644 src/View/MainWindowTabInfo.py create mode 100644 src/View/ui/Widgets/MainWindowTabInfo.ui diff --git a/src/Model/Network/Graph.py b/src/Model/Network/Graph.py index c92c5095..4b154840 100644 --- a/src/Model/Network/Graph.py +++ b/src/Model/Network/Graph.py @@ -67,6 +67,13 @@ class Graph(object): def edges_counts(self): return len(self._edges) + def enable_nodes_counts(self): + return reduce( + lambda acc, n: acc + 1 if self.is_enable_node(n) else acc, + self._nodes, + 0 + ) + def enable_edges_counts(self): return reduce( lambda acc, e: acc + 1 if e.is_enable() else acc, diff --git a/src/View/MainWindow.py b/src/View/MainWindow.py index 93baaaf4..f8763814 100644 --- a/src/View/MainWindow.py +++ b/src/View/MainWindow.py @@ -34,7 +34,7 @@ from PyQt5.QtCore import ( from PyQt5.QtWidgets import ( QMainWindow, QApplication, QAction, QFileDialog, QShortcut, QMenu, QToolBar, - QMessageBox, QProgressDialog, + QMessageBox, QProgressDialog, QTabWidget, ) from PyQt5.uic import loadUi @@ -44,6 +44,8 @@ from View.DummyWindow import DummyWindow from View.Translate import MainTranslate +from View.MainWindowTabInfo import WidgetInfo + from View.Configure.Window import ConfigureWindow from View.Study.Window import NewStudyWindow from View.About.Window import AboutWindow @@ -143,6 +145,7 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): self ) + self.setup_tab() self.setup_sc() self.setup_connection() self.default_style() @@ -167,6 +170,21 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): title += "Pamhyr2" self.setWindowTitle(title) + def setup_tab(self): + self.setup_tab_info() + + def setup_tab_info(self): + tab_widget = self.findChild(QTabWidget, "tabWidget") + + self._tab_widget_info = WidgetInfo( + study=self._study, parent=self + ) + + tab_widget.addTab( + self._tab_widget_info, + self._trad["tab_info_name"] + ) + def enable_actions(self, action: str, enable: bool): """Enable of disable an action componant @@ -348,6 +366,8 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): logger.debug(f"Propagation keys: {self._propagation_keys}") def _do_propagate_update(self): + self.update() + keys = self._propagation_keys.copy() self._init_propagation_keys() @@ -361,6 +381,12 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): for _, window in self.sub_win_list: window._propagated_update(key=key) + def update(self): + self.set_title() + + self._tab_widget_info.study = self._study + self._tab_widget_info.update() + ######### # MODEL # ######### @@ -372,14 +398,15 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): self._study = model self.update_enable_action() self.conf.set_last_study(self._study.filename) - self.set_title() + + self.update() def close_model(self): self._study = None self.update_enable_action() self.conf.set_close_correctly() - self.set_title() + self.update() self._close_sub_window() def update_enable_action(self): diff --git a/src/View/MainWindowTabInfo.py b/src/View/MainWindowTabInfo.py new file mode 100644 index 00000000..bdfb7e63 --- /dev/null +++ b/src/View/MainWindowTabInfo.py @@ -0,0 +1,117 @@ +# MainWindowTabInfo.py -- Pamhyr +# Copyright (C) 2024 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. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# -*- coding: utf-8 -*- + +import logging + +from tools import timer, trace + +from View.Tools.PamhyrWidget import PamhyrWidget + +logger = logging.getLogger() + + +class WidgetInfo(PamhyrWidget): + _pamhyr_ui = "MainWindowTabInfo" + + color_grey = "" + color_end = "" + + def __init__(self, study=None, parent=None): + self._study = study + + super(WidgetInfo, self).__init__( + parent=parent + ) + + self.set_initial_values() + + @property + def study(self): + return self._study + + @study.setter + def study(self, study): + self._study = study + + def set_initial_values(self): + self.set_label_text("label_study_name", "") + self.set_text_edit_text("textBrowser_study", "") + + self.set_label_text("label_current_reach", "None") + self.set_label_text("label_nodes", "0") + self.set_label_text("label_edges", "0") + + self.set_label_text("label_cs", "0") + self.set_label_text("label_points", "0") + + def update(self): + if self._study is None: + self.set_initial_values() + return + + self.set_label_text("label_study_name", self._study.name) + self.set_text_edit_text("textBrowser_study", self._study.description) + + self.set_network_values() + self.set_geometry_values() + + def set_network_values(self): + n_nodes = self._study.river.enable_nodes_counts() + n_d_nodes = self._study.river.nodes_counts() - n_nodes + n_edges = self._study.river.enable_edges_counts() + n_d_edges = self._study.river.edges_counts() - n_edges + + self.set_label_text( + "label_nodes", + f"{n_nodes} {self.color_grey}({n_d_nodes}){self.color_end}" + ) + self.set_label_text( + "label_edges", + f"{n_edges} {self.color_grey}({n_d_edges}){self.color_end}" + ) + + current = self._study.river.current_reach() + if current is not None: + name = current.reach.name + else: + name = "None" + self.set_label_text("label_current_reach", name) + + def set_geometry_values(self): + n_cs = 0 + n_d_cs = 0 + n_points = 0 + n_d_points = 0 + + for edge in self._study.river.edges(): + for profile in edge.reach.profiles: + if edge.is_enable(): + n_points += len(profile) + n_cs += 1 + else: + n_d_points += len(profile) + n_d_cs += 1 + + self.set_label_text( + "label_cs", + f"{n_cs} {self.color_grey}({n_d_cs}){self.color_end}" + ) + self.set_label_text( + "label_points", + f"{n_points} {self.color_grey}({n_d_points}){self.color_end}" + ) diff --git a/src/View/Translate.py b/src/View/Translate.py index 6ca09d6a..bbebaf5f 100644 --- a/src/View/Translate.py +++ b/src/View/Translate.py @@ -75,6 +75,10 @@ class MainTranslate(UnitTranslate): def __init__(self): super(MainTranslate, self).__init__() + self._dict["tab_info_name"] = _translate( + "MainWindow", "Info" + ) + self._dict["open_debug"] = _translate( "MainWindow", "Open debug window" ) diff --git a/src/View/ui/MainWindow.ui b/src/View/ui/MainWindow.ui index 2458faa2..bb9f0ad7 100644 --- a/src/View/ui/MainWindow.ui +++ b/src/View/ui/MainWindow.ui @@ -59,6 +59,22 @@ Qt::NoContextMenu + + + + + + Ubuntu + 50 + false + + + + -1 + + + + diff --git a/src/View/ui/Widgets/MainWindowTabInfo.ui b/src/View/ui/Widgets/MainWindowTabInfo.ui new file mode 100644 index 00000000..c037b248 --- /dev/null +++ b/src/View/ui/Widgets/MainWindowTabInfo.ui @@ -0,0 +1,229 @@ + + + Form + + + + 0 + 0 + 897 + 480 + + + + Form + + + + + + + + + Qt::ScrollBarAlwaysOn + + + true + + + + + 0 + 0 + 864 + 460 + + + + + + + Qt::Horizontal + + + + + + + Study + + + + + + Description: + + + + + + + + + + + + + + Name: + + + + + + + + + + @study_name + + + + + + + + + + River network + + + + + + Reach: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Node: + + + + + + + + + + @nb_nodes + + + + + + + + + + @nb_edges + + + + + + + Current reach: + + + + + + + + + + @current_reach + + + + + + + + + + Geometry + + + + + + + + + @nb_points + + + + + + + Cross-sections: + + + + + + + Points: + + + + + + + + + + @nb_cs + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + + + + + + + + +