command.py 671 B

12345678910111213141516171819202122232425262728
  1. import ast
  2. # tells LazPaint it is a script, we are going to send commands
  3. print("LazPaint script\t")
  4. # wait for LazPaint response
  5. if input('') != chr(27) + 'LazPaint':
  6. print("Needs to be run from LazPaint.")
  7. exit()
  8. def parse_str(text: str):
  9. if text[:1] == "#":
  10. return text
  11. else:
  12. return ast.literal_eval(text)
  13. # sends a command to LazPaint
  14. def send(command: str, **keywords):
  15. if keywords is None:
  16. print(chr(27) + command)
  17. else:
  18. print(chr(27) + command + chr(29) + repr(keywords))
  19. if command[-1] == '?':
  20. return parse_str(input(''))
  21. else:
  22. return
  23. def get_version(): # (major, minor, revision)
  24. return send("LazPaintGetVersion?")