__init__.py 1.8 KB

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