__init__.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. from ._anvil_designer import ParserTemplate
  2. from anvil import *
  3. import anvil.server
  4. import anvil.tables as tables
  5. import anvil.tables.query as q
  6. from anvil.tables import app_tables
  7. class Parser(ParserTemplate):
  8. def __init__(self, **properties):
  9. # Set Form properties and Data Bindings.
  10. self.init_components(**properties)
  11. # Any code you write here will run when the form opens.
  12. def check_yaml_click(self, **event_args):
  13. """This method is called when the button is clicked"""
  14. status, parsed_data, msg, lineno, colno = anvil.server.call('parse_yaml',self.input.text)
  15. output_text = parsed_data
  16. self.output.foreground = 'green'
  17. if status==1:
  18. self.output.foreground = 'red'
  19. output_text = ""
  20. index = 1
  21. for line in self.input.text.splitlines():
  22. output_text = output_text + line + '\n'
  23. index+= 1
  24. if index == lineno:
  25. output_text = output_text + ' '*colno + '^' '\n'
  26. output_text = output_text + ' '*colno + 'MESSAGE: ' + msg + '\n'
  27. self.output.text = output_text
  28. def check_json_click(self, **event_args):
  29. """This method is called when the button is clicked"""
  30. status, parsed_data, msg, lineno, colno = anvil.server.call('parse_json',self.input.text)
  31. output_text = parsed_data
  32. self.output.foreground = 'green'
  33. if status==1:
  34. self.output.foreground = 'red'
  35. output_text = ""
  36. index = 1
  37. for line in self.input.text.splitlines():
  38. output_text = output_text + line + '\n'
  39. index+= 1
  40. if index == lineno:
  41. output_text = output_text + ' '*colno + '^' '\n'
  42. output_text = output_text + ' '*colno + 'MESSAGE: ' + msg + '\n'
  43. self.output.text = output_text