@@ -1069,6 +1069,15 @@ def __init__(self, widget, text, linecount, progress, arcdivision):
10691069 self .progress = progress
10701070 self .aborted = False
10711071 self .arcdivision = arcdivision
1072+ self .timeout_time = None
1073+
1074+ def set_timeout (self , timeout ):
1075+ '''Abort loading of G-code if it takes more than timeout seconds from
1076+ the time this method was called. Set timeout to None to disable.'''
1077+ if timeout is None or timeout <= 0 :
1078+ self .timeout_time = None
1079+ else :
1080+ self .timeout_time = time .time () + timeout
10721081
10731082 def change_tool (self , pocket ):
10741083 GLCanon .change_tool (self , pocket )
@@ -1081,6 +1090,11 @@ def do_cancel(self, event):
10811090
10821091 def check_abort (self ):
10831092 root_window .update ()
1093+
1094+ if self .timeout_time is not None and self .timeout_time < time .time ():
1095+ notifications .add ("info" , _ ("G-code preview loading timed out" ))
1096+ self .aborted = True
1097+
10841098 if self .aborted : raise KeyboardInterrupt
10851099
10861100 def next_line (self , st ):
@@ -1217,6 +1231,10 @@ def open_file_guts(f, filtered=False, addrecent=True):
12171231 shutil .copy (parameter , temp_parameter )
12181232 canon .parameter_file = temp_parameter
12191233
1234+ timeout = inifile .find ("DISPLAY" , "PREVIEW_TIMEOUT" ) or ""
1235+ if timeout :
1236+ canon .set_timeout (float (timeout ))
1237+
12201238 initcode = inifile .find ("EMC" , "RS274NGC_STARTUP_CODE" ) or ""
12211239 if initcode == "" :
12221240 initcode = inifile .find ("RS274NGC" , "RS274NGC_STARTUP_CODE" ) or ""
0 commit comments