@@ -2059,25 +2059,31 @@ def log_version(self):
20592059 self .add_status (mess , CRITICAL ,noLog = True )
20602060 STATUS .emit ('update-machine-log' , mess , None )
20612061
2062+ # called from hal_glib to run macros from external event
20622063 def request_macro_call (self , data ):
2063- flag = True
2064+ if not STATUS .is_mdi_mode ():
2065+ self .add_status (_translate ("HandlerClass" ,'Machine must be in MDI mode to run macros' ), CRITICAL )
2066+ return
2067+
20642068 for b in range (0 ,10 ):
20652069 button = self .w ['macrobutton{}' .format (b )]
20662070 # prefer named INI MDI commands
20672071 key = button .property ('ini_mdi_key' )
2068- if key == '' or INFO .get_ini_mdi_command (key ) is None :
2072+ code = INFO .get_ini_mdi_command (key )
2073+ if key == '' or code is None :
20692074 # fallback to legacy nth line
20702075 key = button .property ('ini_mdi_number' )
2071- try :
20722076 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 :
2077+ if code is None :
2078+ continue
2079+ if str (key ) == data :
20792080 #print('match',button.objectName())
2080- button .click ()
2081+ text = button .text ().replace ('\n ' ,' ' )
2082+ self .add_status (_translate ("HandlerClass" ,'Running macro: {} {}' .format (key , text )))
2083+ try :
2084+ button .click ()
2085+ except Exception as e :
2086+ self .add_status (_translate ("HandlerClass" ,'Running macro: {} {}\n {}' .format (key , text , e )))
20812087 break
20822088
20832089 #####################
0 commit comments