@@ -671,7 +671,7 @@ def save_state(self):
671671 ), f , indent = 4 )
672672
673673 def load_state (self ):
674- if not bool (eval (self .config .get ("State" , "Load State " ))) and \
674+ if not bool (eval (self .config .get ("State" , "load state " ))) or \
675675 not os .path .isfile (SLAVES_FILE ):
676676 return
677677
@@ -680,16 +680,15 @@ def load_state(self):
680680 data = load (f )
681681 except ValueError as e :
682682 self .show_error (
683- "LoadError: Failed to Load : %s "
684- "\n Save Your Config File it will be overwritten"
683+ "LoadError: Failed to Load State : %s "
685684 % e .message
686685 )
687686 return
688687
689688 if 'active_server' not in data or 'port' not in data \
690689 or 'slaves_list' not in data or 'slaves_memory' not in data :
691- self .show_error ("LoadError: Failed to Load Config Error "
692- "\n Save Your Config File it will be overwritten " )
690+ self .show_error ("LoadError: Failed to Load State : JSON Key "
691+ "Missing " )
693692 return
694693
695694 slaves_list = data ['slaves_list' ]
@@ -942,7 +941,7 @@ def load_state(self):
942941 "title": "Load State",
943942 "desc": "Whether the previous state should be loaded or not, if not the original state is loaded",
944943 "section": "State",
945- "key": "Load State "
944+ "key": "load state "
946945 }
947946
948947]
@@ -969,17 +968,14 @@ def on_pause(self):
969968 return True
970969
971970 def on_stop (self ):
972- # will write to the default App config file modbussimu.ini
973- self .config .write ()
974- if self .gui .server_running :
975- self .gui ._stop_server ()
976- self .gui .save_state ()
977971 if self .gui .server_running :
978972 if self .gui .simulating :
979973 self .gui .simulating = False
980974 self .gui ._simulate ()
981975 self .gui .modbus_device .stop ()
982976 self .gui .sync_modbus_thread .cancel ()
977+ self .config .write ()
978+ self .gui .save_state ()
983979
984980 def show_settings (self , btn ):
985981 self .open_settings ()
@@ -1019,7 +1015,7 @@ def build_config(self, config):
10191015 config .set ('Simulation' , 'time interval' , 1 )
10201016
10211017 config .add_section ('State' )
1022- config .set ('State' , 'Load State ' , 1 )
1018+ config .set ('State' , 'load state ' , 1 )
10231019
10241020 def build_settings (self , settings ):
10251021 settings .register_type ("numeric_range" , SettingIntegerWithRange )
0 commit comments