@@ -150,6 +150,9 @@ def __init__(self, halcomp, widgets, paths):
150150 STATUS .connect ('graphics-gcode-properties' , lambda w , d : self .update_gcode_properties (d ))
151151 STATUS .connect ('status-message' , lambda w , d , o : self .add_external_status (d ,o ))
152152 STATUS .connect ('runstop-line-changed' , lambda w , l :self .lastRunLine (l ))
153+ STATUS .connect ('cycle-start-request' , lambda w , state :self .btn_start_clicked (state ))
154+ STATUS .connect ('cycle-pause-request' , lambda w , state : self .btn_pause_clicked (state ))
155+ STATUS .connect ('macro-call-request' , lambda w , name : self .request_macro_call (name ))
153156
154157 self .swoopPath = os .path .join (paths .IMAGEDIR ,'lcnc_swoop.png' )
155158 self .swoopURL = QtCore .QUrl .fromLocalFile (self .swoopPath )
@@ -871,7 +874,34 @@ def add_external_status(self, message, option):
871874 # Log the last run line (in auto mode) if stopped
872875 def lastRunLine (self , line ):
873876 if line > 0 :
874- self .add_status ('last running line before stoppage: {}' .format (line ))
877+ self .add_status (_translate ("HandlerClass" ,'last running line before stoppage: {}' .format (line )))
878+
879+ # called from hal_glib to run macros from external event
880+ def request_macro_call (self , data ):
881+ if not STATUS .is_mdi_mode ():
882+ self .add_status (_translate ("HandlerClass" ,'Machine must be in MDI mode to run macros' ), CRITICAL )
883+ return
884+ flag = True
885+ for b in range (0 ,10 ):
886+ button = self .w ['macrobutton{}' .format (b )]
887+ # prefer named INI MDI commands
888+ key = button .property ('ini_mdi_key' )
889+ code = INFO .get_ini_mdi_command (key )
890+ if key == '' or code is None :
891+ # fallback to legacy nth line
892+ key = button .property ('ini_mdi_number' )
893+ code = INFO .get_ini_mdi_command (key )
894+ try :
895+ if code is None : raise Exception
896+ flag = False
897+ except :
898+ continue
899+ if key == data :
900+ #print('match',button.objectName())
901+ text = button .text ().replace ('\n ' ,' ' )
902+ self .add_status (_translate ("HandlerClass" ,'Running macro: {} {}' .format (key , text )))
903+ button .click ()
904+ break
875905
876906 #######################
877907 # CALLBACKS FROM FORM #
@@ -2029,6 +2059,27 @@ def log_version(self):
20292059 self .add_status (mess , CRITICAL ,noLog = True )
20302060 STATUS .emit ('update-machine-log' , mess , None )
20312061
2062+ def request_macro_call (self , data ):
2063+ flag = True
2064+ for b in range (0 ,10 ):
2065+ button = self .w ['macrobutton{}' .format (b )]
2066+ # prefer named INI MDI commands
2067+ key = button .property ('ini_mdi_key' )
2068+ if key == '' or INFO .get_ini_mdi_command (key ) is None :
2069+ # fallback to legacy nth line
2070+ key = button .property ('ini_mdi_number' )
2071+ try :
2072+ code = INFO .get_ini_mdi_command (key )
2073+ if code is None : raise Exception
2074+ flag = False
2075+ except :
2076+ print ('No macro code' )
2077+ continue
2078+ if key == data :
2079+ #print('match',button.objectName())
2080+ button .click ()
2081+ break
2082+
20322083 #####################
20332084 # KEY BINDING CALLS #
20342085 #####################
0 commit comments