def on_scan_pressed(self, event): # Clear output areas self.output.Clear() self.source.Clear() parser = Parser_Class() try: ret_code = parser.parse_file(self.edit.GetValue()) self.source.AppendText(parser.source()) # Output file if self.out_file.GetValue() != '': try: file = open(self.out_file.GetValue(), 'w') if self.opt_verbose.GetValue(): for line in parser.output(): file.write(str(line)+"\n") else: for line in parser.matches(): file.write(str(line)+"\n") file.close() except Exception as strerror: self.show_error('Error: '+str(strerror)) # Verbose output if self.opt_verbose.GetValue(): for line in parser.output(): self.output.AppendText(str(line+"\n")) # Match-only output else: for line in parser.matches(): self.output.AppendText(str(line+"\n")) # Show errors if len(parser.error()) > 0: err_str = "There are errors in this source!\n\n" for error in parser.error(): err_str += error+"\n" self.show_error(err_str) # Show status of parse if ret_code == 0 and len(parser.error()) == 0: self.show_message("Parse completed successfully!") elif ret_code == 0 and len(parser.error()) > 0: self.show_message("Parse completed with errors!") else: self.show_error("Parse failed!") except Exception as strerror: self.source.AppendText(scanner.source()) for line in scanner.output(): self.output.AppendText(str(line+"\n")) self.show_error('Error: '+str(strerror))
except IndexError: if nogui: sys.stderr.write('Error: Input file required') sys.exit(1) # GUI mode if __name__ == "__main__" and not nogui: app = wxParserApp() app.MainLoop() # Command line mode else: parser = Parser_Class() try: parser.parse_file(in_file) except Exception as strerror: sys.stderr.write('Error: '+str(strerror)) sys.exit(1) # Verbose if verbose: for line in parser.output(): print line # Not Verbose else: for line in parser.matches(): print line # End Large Parser Client