From 504ef7ec4820d6184c6fb006b7f54ed79392716c Mon Sep 17 00:00:00 2001
From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr>
Date: Fri, 7 Jul 2023 10:50:17 +0200
Subject: [PATCH] pamhyr: End switch print to logging.

---
 src/View/BoundaryCondition/Edit/Table.py   |  7 +++++--
 src/View/BoundaryCondition/Window.py       |  7 +++++--
 src/View/Geometry/PlotAC.py                |  6 +++++-
 src/View/Geometry/PlotKPC.py               |  6 +++++-
 src/View/Geometry/Profile/Plot.py          |  6 +++++-
 src/View/Geometry/Window.py                |  4 ++--
 src/View/InitialConditions/Window.py       |  7 +++++--
 src/View/LateralContribution/Edit/Table.py |  6 ++++--
 src/View/LateralContribution/Window.py     |  7 +++++--
 src/View/Plot/mpl_canvas_onpick_event.py   |  8 +++++---
 src/View/Plot/navigation_toolbar_2qt.py    |  4 +++-
 src/View/Sections/Window.py                |  8 ++++++--
 src/View/SolverParameters/Window.py        |  7 +++++--
 src/View/Stricklers/Window.py              |  7 +++++--
 src/tools.py                               | 12 ++++++------
 15 files changed, 71 insertions(+), 31 deletions(-)

diff --git a/src/View/BoundaryCondition/Edit/Table.py b/src/View/BoundaryCondition/Edit/Table.py
index 6c94b928..dfe805e1 100644
--- a/src/View/BoundaryCondition/Edit/Table.py
+++ b/src/View/BoundaryCondition/Edit/Table.py
@@ -1,5 +1,7 @@
 # -*- coding: utf-8 -*-
 
+import logging
+
 from datetime import date, time, datetime, timedelta
 
 from tools import trace, timer
@@ -32,6 +34,7 @@ from View.BoundaryCondition.Edit.translate import *
 
 _translate = QCoreApplication.translate
 
+logger = logging.getLogger()
 
 class ExtendedTimeEdit(AWidget):
     def __init__(self, parent=None):
@@ -108,7 +111,7 @@ class ExTimeDelegate(QItemDelegate):
             self.editor = ExtendedDateTimeEdit(parent=parent)
         value = index.data(Qt.DisplayRole)
         self.editor.set_time(value)
-        print(value)
+        logger.debug(str(value))
         return self.editor
 
     def setModelData(self, editor, model, index):
@@ -116,7 +119,7 @@ class ExTimeDelegate(QItemDelegate):
         if self._mode == "time":
             model.setData(index, int(time.total_seconds()))
         else:
-            print(time.timestamp())
+            logger.debug(str(time.timestamp()))
             model.setData(index, int(time.timestamp()))
         editor.close()
         editor.deleteLater()
diff --git a/src/View/BoundaryCondition/Window.py b/src/View/BoundaryCondition/Window.py
index 62d823d7..2e7dd430 100644
--- a/src/View/BoundaryCondition/Window.py
+++ b/src/View/BoundaryCondition/Window.py
@@ -1,5 +1,7 @@
 # -*- coding: utf-8 -*-
 
+import logging
+
 from tools import trace, timer
 
 from View.ASubWindow import ASubMainWindow
@@ -43,6 +45,7 @@ from View.BoundaryCondition.Edit.Window import EditBoundaryConditionWindow
 
 _translate = QCoreApplication.translate
 
+logger = logging.getLogger()
 
 class BoundaryConditionWindow(ASubMainWindow, ListedSubWindow):
     def __init__(self, title="Boundary conditions", study=None, parent=None):
@@ -184,10 +187,10 @@ class BoundaryConditionWindow(ASubMainWindow, ListedSubWindow):
         self._table[tab].move_down(row)
 
     def copy(self):
-        print("TODO")
+        logger.info("TODO: copy")
 
     def paste(self):
-        print("TODO")
+        logger.info("TODO: paste")
 
     def undo(self):
         tab = self.current_tab()
diff --git a/src/View/Geometry/PlotAC.py b/src/View/Geometry/PlotAC.py
index da5f1149..9709d3bc 100644
--- a/src/View/Geometry/PlotAC.py
+++ b/src/View/Geometry/PlotAC.py
@@ -1,5 +1,7 @@
 # -*- coding: utf-8 -*-
 
+import logging
+
 from tools import timer
 from View.Plot.APlot import APlot
 
@@ -9,6 +11,8 @@ from PyQt5.QtCore import (
 
 _translate = QCoreApplication.translate
 
+logger = logging.getLogger()
+
 class PlotAC(APlot):
     def __init__(self, canvas=None, data=None, toolbar=None, plot_xy=None):
         super(PlotAC, self).__init__(
@@ -284,7 +288,7 @@ class PlotAC(APlot):
                         self.color_incomplete_gl[lincomplete.index(txt)]
                     )
         except Exception as e:
-            print(f"{e}")
+            logger.warning(f"{e}")
 
         self.canvas.figure.canvas.draw_idle()
 
diff --git a/src/View/Geometry/PlotKPC.py b/src/View/Geometry/PlotKPC.py
index d48381c4..f3e883f3 100644
--- a/src/View/Geometry/PlotKPC.py
+++ b/src/View/Geometry/PlotKPC.py
@@ -1,5 +1,7 @@
 # -*- coding: utf-8 -*-
 
+import logging
+
 from tools import timer
 from View.Plot.APlot import APlot
 
@@ -9,6 +11,8 @@ from PyQt5.QtCore import (
 
 _translate = QCoreApplication.translate
 
+logger = logging.getLogger()
+
 class PlotKPC(APlot):
     def __init__(self, canvas=None, data=None, toolbar=None,
                  display_current=True):
@@ -214,7 +218,7 @@ class PlotKPC(APlot):
                         kp, z_complete[i]
                     )
             except Exception as e:
-                print(f"Failed to update graphic 2: {e}")
+                logger.warning(f"Failed to update graphic KPC: {e}")
 
             self.canvas.axes.autoscale_view(True, True, True)
             self.canvas.figure.canvas.draw_idle()
diff --git a/src/View/Geometry/Profile/Plot.py b/src/View/Geometry/Profile/Plot.py
index 100426f8..2dc7f522 100644
--- a/src/View/Geometry/Profile/Plot.py
+++ b/src/View/Geometry/Profile/Plot.py
@@ -1,5 +1,7 @@
 # -*- coding: utf-8 -*-
 
+import logging
+
 from tools import timer, trace
 from View.Plot.APlot import APlot
 from View.Plot.mpl_canvas_onpick_event import OnpickEvent
@@ -10,6 +12,8 @@ from PyQt5.QtCore import (
 
 _translate = QCoreApplication.translate
 
+logger = logging.getLogger()
+
 class Plot(APlot):
     def __init__(self, canvas=None, data=None, toolbar=None, table=None):
         super(Plot, self).__init__(
@@ -123,5 +127,5 @@ class Plot(APlot):
 
     @timer
     def update(self, ind=None):
-        print("TODO: implemente update")
+        logger.info("TODO: implemente update")
         self.draw()
diff --git a/src/View/Geometry/Window.py b/src/View/Geometry/Window.py
index 0428a006..37f83aff 100644
--- a/src/View/Geometry/Window.py
+++ b/src/View/Geometry/Window.py
@@ -150,8 +150,8 @@ class GeometryWindow(QMainWindow, WindowToolKit):
         msg_box.setStandardButtons(QtWidgets.QMessageBox.Ok)
 
         return_value = msg_box.exec()
-        if return_value == QtWidgets.QMessageBox.Ok:
-            print('OK clicked')
+        # if return_value == QtWidgets.QMessageBox.Ok:
+        #     print('OK clicked')
 
     def edit_profile(self):
         self.tableView.model().blockSignals(True)
diff --git a/src/View/InitialConditions/Window.py b/src/View/InitialConditions/Window.py
index 22cade03..35822811 100644
--- a/src/View/InitialConditions/Window.py
+++ b/src/View/InitialConditions/Window.py
@@ -1,5 +1,7 @@
 # -*- coding: utf-8 -*-
 
+import logging
+
 from tools import trace, timer
 
 from View.ASubWindow import ASubMainWindow
@@ -39,6 +41,7 @@ from View.InitialConditions.DialogDischarge import DischargeDialog
 
 _translate = QCoreApplication.translate
 
+logger = logging.getLogger()
 
 class InitialConditionsWindow(ASubMainWindow, ListedSubWindow):
     def __init__(self, title="Initial condition",
@@ -197,11 +200,11 @@ class InitialConditionsWindow(ASubMainWindow, ListedSubWindow):
         self._update_plot()
 
     def copy(self):
-        print("TODO")
+        logger.info("TODO: copy")
         self._update_plot()
 
     def paste(self):
-        print("TODO")
+        logger.info("TODO: paste")
         self._update_plot()
 
     def undo(self):
diff --git a/src/View/LateralContribution/Edit/Table.py b/src/View/LateralContribution/Edit/Table.py
index e3e74483..4101995c 100644
--- a/src/View/LateralContribution/Edit/Table.py
+++ b/src/View/LateralContribution/Edit/Table.py
@@ -1,5 +1,6 @@
 # -*- coding: utf-8 -*-
 
+import logging
 from datetime import date, time, datetime, timedelta
 
 from tools import trace, timer
@@ -31,6 +32,7 @@ from View.LateralContribution.Edit.translate import *
 
 _translate = QCoreApplication.translate
 
+logger = logging.getLogger()
 
 class ExtendedTimeEdit(AWidget):
     def __init__(self, parent=None):
@@ -107,7 +109,7 @@ class ExTimeDelegate(QItemDelegate):
             self.editor = ExtendedDateTimeEdit(parent=parent)
         value = index.data(Qt.DisplayRole)
         self.editor.set_time(value)
-        print(value)
+        logger.debug(str(value))
         return self.editor
 
     def setModelData(self, editor, model, index):
@@ -115,7 +117,7 @@ class ExTimeDelegate(QItemDelegate):
         if self._mode == "time":
             model.setData(index, int(time.total_seconds()))
         else:
-            print(time.timestamp())
+            logger.debug(str(time.timestamp()))
             model.setData(index, int(time.timestamp()))
         editor.close()
         editor.deleteLater()
diff --git a/src/View/LateralContribution/Window.py b/src/View/LateralContribution/Window.py
index a6b7b03e..b87e9968 100644
--- a/src/View/LateralContribution/Window.py
+++ b/src/View/LateralContribution/Window.py
@@ -1,5 +1,7 @@
 # -*- coding: utf-8 -*-
 
+import logging
+
 from tools import trace, timer
 
 from View.ASubWindow import ASubMainWindow
@@ -43,6 +45,7 @@ from View.LateralContribution.Edit.Window import EditLateralContributionWindow
 
 _translate = QCoreApplication.translate
 
+logger = logging.getLogger()
 
 class LateralContributionWindow(ASubMainWindow, ListedSubWindow):
     def __init__(self, title="Lateral contribution", study=None, parent=None):
@@ -226,11 +229,11 @@ class LateralContributionWindow(ASubMainWindow, ListedSubWindow):
         self._set_current_reach()
 
     def copy(self):
-        print("TODO")
+        logger.info("TODO: copy")
         self._set_current_reach()
 
     def paste(self):
-        print("TODO")
+        logger.info("TODO: paste")
         self._set_current_reach()
 
     def undo(self):
diff --git a/src/View/Plot/mpl_canvas_onpick_event.py b/src/View/Plot/mpl_canvas_onpick_event.py
index 6415aee7..010959bc 100644
--- a/src/View/Plot/mpl_canvas_onpick_event.py
+++ b/src/View/Plot/mpl_canvas_onpick_event.py
@@ -1,3 +1,5 @@
+import logging
+
 from time import time
 
 import numpy as np
@@ -6,6 +8,7 @@ from PyQt5.QtCore import QItemSelectionModel, Qt
 from PyQt5.QtWidgets import QApplication
 from shapely.geometry.polygon import Polygon as ShapelyPolygon
 
+logger = logging.getLogger()
 
 class OnpickEvent(object):
     def __init__(self, ax, x, y, x_carto, y_carto, tableview=None):
@@ -105,14 +108,13 @@ class OnpickEvent(object):
                         [pl[0].set_data([], [])
                          for pl in self.pt if len(self.pt) > 1]
                     except:
-                        print("Probleme  de mise à jour ... update_select_point_point()")
+                        logger.info("update_select_point_point: Update issue")
 
                     try:
                         self.update_select_point_point_bis(self.x[row],
                                                            self.y[row])
                     except:
-                        print("index introuvable pour la mise à jour de l'affichage de la sélection du point."
-                              "Editer les cases en 'nan'.")
+                        logger.info("update_select_point_point_bis: Update issue, possible index missing")
 
             self.ax.figure.canvas.draw_idle()
 
diff --git a/src/View/Plot/navigation_toolbar_2qt.py b/src/View/Plot/navigation_toolbar_2qt.py
index d07386de..37186450 100644
--- a/src/View/Plot/navigation_toolbar_2qt.py
+++ b/src/View/Plot/navigation_toolbar_2qt.py
@@ -1,6 +1,7 @@
 # -*- coding: utf-8 -*-
 
 import os
+import logging
 import matplotlib as mpl
 from matplotlib.backends import qt_compat
 from PyQt5 import QtCore, QtGui, QtWidgets
@@ -10,6 +11,7 @@ from PyQt5.QtCore import pyqtSignal, QSize
 
 _translate = QtCore.QCoreApplication.translate
 
+logger = logging.getLogger()
 file_path = os.path.abspath(os.path.dirname(__file__))
 
 
@@ -123,7 +125,7 @@ class PamHyrNavigationToolbar2QT(NavigationToolbar2QT):
                 )
 
     def cursor1(self):
-        print("TODO")
+        logger.info("TODO: cursor1")
 
     def isometric_view(self):
         self.my_canvas.axes.axis("equal")
diff --git a/src/View/Sections/Window.py b/src/View/Sections/Window.py
index 5690b472..63eb4b7e 100644
--- a/src/View/Sections/Window.py
+++ b/src/View/Sections/Window.py
@@ -1,5 +1,7 @@
 # -*- coding: utf-8 -*-
 
+import logging
+
 from tools import trace, timer
 
 from View.ASubWindow import ASubMainWindow
@@ -39,6 +41,8 @@ from View.Stricklers.Window import StricklersWindow
 
 _translate = QCoreApplication.translate
 
+logger = logging.getLogger()
+
 class SectionsWindow(ASubMainWindow, ListedSubWindow):
     def __init__(self, title="Sections", study=None, parent=None):
         self._study = study
@@ -214,10 +218,10 @@ class SectionsWindow(ASubMainWindow, ListedSubWindow):
         self._table.move_down(row)
 
     def copy(self):
-        print("TODO")
+        logger.info("TODO: copy")
 
     def paste(self):
-        print("TODO")
+        logger.info("TODO: paste")
 
     def undo(self):
         self._table.undo()
diff --git a/src/View/SolverParameters/Window.py b/src/View/SolverParameters/Window.py
index e2ceae2b..4e154a54 100644
--- a/src/View/SolverParameters/Window.py
+++ b/src/View/SolverParameters/Window.py
@@ -1,5 +1,7 @@
 # -*- coding: utf-8 -*-
 
+import logging
+
 from tools import trace, timer
 
 from View.ASubWindow import ASubMainWindow
@@ -31,6 +33,7 @@ from Solver.Solvers import solver_long_name, solver_type_list
 
 _translate = QCoreApplication.translate
 
+logger = logging.getLogger()
 
 class SolverParametersWindow(ASubMainWindow, ListedSubWindow):
     def __init__(self, title="Solver parameters", study=None, parent=None):
@@ -120,7 +123,7 @@ class SolverParametersWindow(ASubMainWindow, ListedSubWindow):
         self._set_current_reach()
 
     def copy(self):
-        print("TODO")
+        logger.info("TODO: copy")
 
     def paste(self):
-        print("TODO")
+        logger.info("TODO: paste")
diff --git a/src/View/Stricklers/Window.py b/src/View/Stricklers/Window.py
index be02f4e7..1d2bfe43 100644
--- a/src/View/Stricklers/Window.py
+++ b/src/View/Stricklers/Window.py
@@ -1,5 +1,7 @@
 # -*- coding: utf-8 -*-
 
+import logging
+
 from tools import trace, timer
 
 from View.ASubWindow import ASubMainWindow
@@ -29,6 +31,7 @@ from View.Stricklers.Table import TableModel
 
 _translate = QCoreApplication.translate
 
+logger = logging.getLogger()
 
 class StricklersWindow(ASubMainWindow, ListedSubWindow):
     def __init__(self, title="Stricklers", study=None, config=None, parent=None):
@@ -115,10 +118,10 @@ class StricklersWindow(ASubMainWindow, ListedSubWindow):
         self._table['study'].sort(False)
 
     def copy(self):
-        print("TODO")
+        logger.info("TODO: copy")
 
     def paste(self):
-        print("TODO")
+        logger.info("TODO: paste")
 
     def undo(self):
         self._table['study'].undo()
diff --git a/src/tools.py b/src/tools.py
index 701dd236..0e7a48d6 100644
--- a/src/tools.py
+++ b/src/tools.py
@@ -53,7 +53,7 @@ def display_timers():
     for t in range(fmax + 26):
         head += "-"
     head += "+"
-    print(head)
+    logger.debug(head)
 
     lst = sorted(
         map(
@@ -67,13 +67,13 @@ def display_timers():
     for func, time, calls in lst:
         name = (f"{Fore.BLUE}{func.__module__}{Style.RESET_ALL}" +
                 f".{Style.BRIGHT}{Fore.GREEN}{func.__qualname__:<{fmax - len(func.__module__)}}{Style.RESET_ALL}")
-        print(f" | {name} | {time:>10.6f} sec | {calls:>5} calls |")
+        logger.debug(f" | {name} | {time:>10.6f} sec | {calls:>5} calls |")
 
     tail = " +--"
     for t in range(fmax + 32):
         tail += "-"
     tail += "+"
-    print(tail)
+    logger.debug(tail)
 
 def timer(func):
     """Function wrapper to register function runtime"""
@@ -85,7 +85,7 @@ def timer(func):
         try:
             value = func(*args, **kwargs)
         except Exception as e:
-            print(f"[{Fore.RED}ERROR{Style.RESET_ALL}]" +
+            logger.debug(f"[{Fore.RED}ERROR{Style.RESET_ALL}]" +
                   f"[{func.__module__}.{Fore.GREEN}{func.__qualname__}{Style.RESET_ALL}]: " +
                   f"{Fore.RED}{e}{Style.RESET_ALL}")
             traceback.print_exc()
@@ -113,13 +113,13 @@ def trace(func):
         t = time.ctime()
         head = f"[{Fore.BLUE}TRACE{Style.RESET_ALL}]"
         c = f"{head}[{t}] Call {func.__module__}.{Fore.GREEN}{func.__qualname__}{Style.RESET_ALL}({args}, {kwargs})"
-        print(c)
+        logger.debug(c)
 
         value = func(*args, **kwargs)
 
         t = time.ctime()
         r = f"{head}[{t}] Return {func.__module__}.{Fore.GREEN}{func.__qualname__}{Style.RESET_ALL}: {value}"
-        print(r)
+        logger.debug(r)
 
         return value
 
-- 
GitLab