1+ """This module defines the FourCWebServer class, which manages the application
2+ state, synchronizes server variables, and handles PyVista rendering for the 4C
3+ web viewer."""
4+
15import copy
26import re
37import tempfile
@@ -109,11 +113,14 @@ def __init__(self, page_title, fourc_yaml_file):
109113
110114 @property
111115 def state (self ):
116+ """Get state."""
117+
112118 # self.state contains all the state variables to be shared between server and client
113119 return self .server .state
114120
115121 @property
116122 def ctrl (self ):
123+ """Get controller."""
117124 # self.ctrl contains all the control functions callable on both the Javascript client-side and the Python server (running on the Python server)
118125 return self .server .controller
119126
@@ -773,6 +780,8 @@ def sync_funct_section_from_state(self):
773780 )
774781
775782 def init_mode_state_vars (self ):
783+ """Initialize state variables related to mode changes (edit mode, view
784+ mode) and statuses (e.g. read-in status)."""
776785 # initialize the read-in status and its possible choices
777786 self .state .all_read_in_statuses = {
778787 "success" : "SUCCESS" , # successful read-in of the file
@@ -821,6 +830,8 @@ def init_mode_state_vars(self):
821830 ################################################
822831 @change ("fourc_yaml_file" )
823832 def change_fourc_yaml_file (self , fourc_yaml_file , ** kwargs ):
833+ """Reaction to change of state.fourc_yaml_file."""
834+
824835 # create temporary fourc yaml file from the content of the given file
825836 temp_fourc_yaml_file = Path (
826837 self ._server_vars ["temp_dir_object" ].name , fourc_yaml_file ["name" ]
@@ -848,6 +859,7 @@ def change_fourc_yaml_file(self, fourc_yaml_file, **kwargs):
848859
849860 @change ("export_fourc_yaml_path" )
850861 def change_export_fourc_yaml_path (self , export_fourc_yaml_path , ** kwargs ):
862+ """Reaction to change of state.export_fourc_yaml_path."""
851863 # set the export status to info
852864 self .state .export_status = self .state .all_export_statuses ["info" ]
853865
@@ -856,6 +868,7 @@ def change_export_fourc_yaml_path(self, export_fourc_yaml_path, **kwargs):
856868 ################################################
857869 @change ("selected_main_section_name" )
858870 def change_selected_main_section_name (self , selected_main_section_name , ** kwargs ):
871+ """Reaction to change of state.selected_main_section_name."""
859872 # set selected section name to the first one within the selected
860873 # main section
861874 self .state .selected_section_name = self .state .section_names [
@@ -864,6 +877,7 @@ def change_selected_main_section_name(self, selected_main_section_name, **kwargs
864877
865878 @change ("selected_material" )
866879 def change_selected_material (self , selected_material , ** kwargs ):
880+ """Reaction to change of state.selected_material."""
867881 # we need to select the material region based on the newly selected
868882 # material (if we are not in an initial rendering scenario)
869883 if self ._server_vars ["render_count" ]["change_selected_material" ] > 0 :
@@ -888,6 +902,7 @@ def change_selected_material(self, selected_material, **kwargs):
888902
889903 @change ("selected_dc_geometry_type" )
890904 def change_selected_dc_geometry_type (self , selected_dc_geometry_type , ** kwargs ):
905+ """Reaction to change of state.selected_dc_geometry_type."""
891906 # change entity to the first of the selected geometry
892907 self .state .selected_dc_entity = next (
893908 iter (self .state .dc_sections [selected_dc_geometry_type ])
@@ -910,6 +925,7 @@ def change_selected_dc_geometry_type(self, selected_dc_geometry_type, **kwargs):
910925
911926 @change ("selected_dc_entity" )
912927 def change_selected_dc_entity (self , selected_dc_entity , ** kwargs ):
928+ """Reaction to change of state.selected_dc_entity."""
913929 # change selected condition for the geometry-entity combination
914930 self .state .selected_dc_condition = next (
915931 iter (
@@ -929,6 +945,7 @@ def change_selected_dc_entity(self, selected_dc_entity, **kwargs):
929945 def change_selected_result_description_id (
930946 self , selected_result_description_id , ** kwargs
931947 ):
948+ """Reaction to change of state.selected_result_description_id."""
932949 # update plotter / render objects
933950 self .update_pyvista_render_objects ()
934951
@@ -937,6 +954,7 @@ def change_selected_result_description_id(
937954
938955 @change ("selected_funct" )
939956 def change_selected_funct (self , selected_funct , ** kwargs ):
957+ """Reaction to change of state.selected_funct."""
940958 # set the selected funct item to the first within the newly
941959 # selected funct
942960 self .state .selected_funct_item = next (
@@ -951,6 +969,7 @@ def change_selected_funct(self, selected_funct, **kwargs):
951969
952970 @change ("selected_funct_item" )
953971 def change_selected_funct_item (self , selected_funct_item , ** kwargs ):
972+ """Reaction to change of state.selected_funct_item."""
954973 # update plotly figure
955974 if self .state .funct_section [self .state .selected_funct ][
956975 self .state .selected_funct_item
@@ -962,6 +981,7 @@ def change_selected_funct_item(self, selected_funct_item, **kwargs):
962981 ################################################
963982 @change ("funct_plot" )
964983 def change_funct_plot (self , funct_plot , ** kwargs ):
984+ """Reaction to change of state.funct_plot."""
965985 # update plotly figure
966986 if self .state .funct_section [self .state .selected_funct ][
967987 self .state .selected_funct_item
@@ -970,6 +990,7 @@ def change_funct_plot(self, funct_plot, **kwargs):
970990
971991 @change ("funct_section" )
972992 def change_funct_section (self , funct_section , ** kwargs ):
993+ """Reaction to change of state.funct_section."""
973994 # update plotly figure
974995 if self .state .funct_section [self .state .selected_funct ][
975996 self .state .selected_funct_item
@@ -980,7 +1001,8 @@ def change_funct_section(self, funct_section, **kwargs):
9801001 # MODE CHANGES #################################
9811002 ################################################
9821003 @change ("edit_mode" )
983- def on_edit_mode_changed (self , edit_mode , ** kwargs ):
1004+ def change_edit_mode (self , edit_mode , ** kwargs ):
1005+ """Reaction to change of state.edit_mode."""
9841006 # cast entered string values from VTextField (edit mode) to
9851007 # numbers
9861008 if (
@@ -1004,7 +1026,8 @@ def on_edit_mode_changed(self, edit_mode, **kwargs):
10041026 # self.state.funct_section = convert_string2number(self.state.funct_section)
10051027
10061028 @change ("export_mode" )
1007- def on_export_mode_changed (self , export_mode , ** kwargs ):
1029+ def change_export_mode (self , export_mode , ** kwargs ):
1030+ """Reaction to change of state.export_mode."""
10081031 # revert export status to "INFO"
10091032 self .state .export_status = self .state .all_export_statuses ["info" ]
10101033
@@ -1126,4 +1149,5 @@ def determine_master_mat_ind_for_current_selection(self):
11261149 return master_mat_id
11271150
11281151 def cleanup (self ):
1152+ """Perform cleanup tasks for the webserver."""
11291153 self ._server_vars ["temp_dir_object" ].cleanup ()
0 commit comments