code: def OnApply(self, event):
          
  
          # See if we have valid python
          try:
              ast.parse(self.macros)
          except:
              # Grab the traceback and print it for the user
              s = StringIO()
              e = exc_info()
              # usr_tb will more than likely be none because ast throws
              #   SytnaxErrorsas occurring outside of the current
              #   execution frame
              usr_tb = get_user_codeframe(e[2]) or None
              print_exception(e[0], e[1], usr_tb, None, s)
              post_command_event(self.parent, self.MacroErrorMsg,
                                 err=s.getvalue())
              success = False
          else:
              self.result_ctrl.SetValue('')
              post_command_event(self.parent, self.MacroReplaceMsg,
                                 macros=self.macros)
              post_command_event(self.parent, self.MacroExecuteMsg)
              success = True
  
          event.Skip()
          return success
docs: Event handler for Apply button