33# SPDX-FileContributor: Alexandre Benedicto, Martin Lemay
44# ruff: noqa: E402 # disable Module level import not at top of file
55import sys
6+ import logging
67from pathlib import Path
78from typing import Any , Union , cast
89
1718update_paths ()
1819
1920from geos .mesh .utils .multiblockModifiers import mergeBlocks
21+ from geos .utils .Logger import ( CountVerbosityHandler , getLoggerHandlerType )
2022import geos .pv .utils .paraviewTreatments as pvt
2123from geos .pv .utils .checkboxFunction import createModifiedCallback # type: ignore[attr-defined]
2224from geos .pv .utils .DisplayOrganizationParaview import DisplayOrganizationParaview
2830 GetActiveSource , GetActiveView , Render , Show , servermanager )
2931from paraview .util .vtkAlgorithm import VTKPythonAlgorithmBase , smdomain , smproperty # type: ignore[import-not-found]
3032# source: https://github.com/Kitware/ParaView/blob/master/Wrapping/Python/paraview/util/vtkAlgorithm.py
33+ from paraview .detail .loghandler import ( # type: ignore[import-not-found]
34+ VTKHandler ,
35+ ) # source: https://github.com/Kitware/ParaView/blob/master/Wrapping/Python/paraview/detail/loghandler.py
36+
37+
3138
3239from vtkmodules .vtkCommonCore import vtkDataArraySelection , vtkInformation
3340from vtkmodules .vtkCommonDataModel import vtkDataObject , vtkMultiBlockDataSet
5057
5158"""
5259
60+ loggerTitle : str = "Python View Configurator"
61+ HANDLER : VTKHandler = VTKHandler ()
62+
5363
5464@SISOFilter ( category = FilterCategory .QC ,
5565 decoratedLabel = "Python View Configurator" ,
@@ -61,7 +71,6 @@ def __init__( self: Self ) -> None:
6171
6272 Input is a vtkDataObject.
6373 """
64- # super().__init__( nInputPorts=1, nOutputPorts=1 )
6574 # Python view layout and object.
6675 self .m_layoutName : str = ""
6776 self .m_pythonView : Any
@@ -139,6 +148,23 @@ def __init__( self: Self ) -> None:
139148 "curvesAspect" : {},
140149 }
141150
151+ self .logger = logging .getLogger ( loggerTitle )
152+ self .logger .setLevel ( logging .INFO )
153+ self .logger .addHandler ( HANDLER )
154+ self .logger .propagate = False
155+
156+ counter : CountVerbosityHandler = CountVerbosityHandler ()
157+ self .counter : CountVerbosityHandler
158+ self .nbWarnings : int = 0
159+ try :
160+ self .counter = getLoggerHandlerType ( type ( counter ), self .logger )
161+ self .counter .resetWarningCount ()
162+ except ValueError :
163+ self .counter = counter
164+ self .counter .setLevel ( logging .INFO )
165+
166+ self .logger .addHandler ( self .counter )
167+
142168 def getUserChoices ( self : Self ) -> dict [ str , Any ]:
143169 """Access the m_userChoices attribute.
144170
@@ -808,12 +834,29 @@ def ApplyFilter( self, inputMesh: vtkDataObject, outputMesh: vtkDataObject ) ->
808834 outputMesh : A dummy mesh transformed.
809835
810836 """
811- assert self .m_pythonView is not None , "No Python View was found."
812- viewSize = GetActiveView ().ViewSize
813- self .m_userChoices [ "ratio" ] = viewSize [ 0 ] / viewSize [ 1 ]
814- self .defineInputNames ()
815- self .defineUserChoicesCurves ()
816- self .defineCurvesAspect ()
817- self .m_pythonView .Script = self .buildPythonViewScript ()
818- Render ()
837+ self .logger .info ( f"Apply the plugin { self .logger .name } ." )
838+ try :
839+ if self .m_pythonView is None :
840+ raise ValueError ( "No Python View was found." )
841+
842+ viewSize = GetActiveView ().ViewSize
843+ self .m_userChoices [ "ratio" ] = viewSize [ 0 ] / viewSize [ 1 ]
844+ self .defineInputNames ()
845+ self .defineUserChoicesCurves ()
846+ self .defineCurvesAspect ()
847+ self .m_pythonView .Script = self .buildPythonViewScript ()
848+ Render ()
849+
850+ result : str = f"The plugin { self .logger .name } succeeded"
851+ if self .counter .warningCount > 0 :
852+ self .logger .warning ( f"{ result } but { self .counter .warningCount } warnings have been logged." )
853+ else :
854+ self .logger .info ( f"{ result } ." )
855+ except Exception as e :
856+ self .logger .error ( f"The plugin failed due to:\n { e } " )
857+ return
858+
859+ self .nbWarnings = self .counter .warningCount
860+ self .counter .resetWarningCount ()
861+
819862 return
0 commit comments