d.out.file.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env python3
  2. ############################################################################
  3. #
  4. # MODULE: d.out.file
  5. # AUTHOR(S): Anna Petrasova <kratochanna gmail.com>
  6. # PURPOSE: Script for exporting content of monitor to graphic file
  7. # COPYRIGHT: (C) 2014-2015 by the GRASS Development Team
  8. #
  9. # This program is free software under the GNU General
  10. # Public License (>=v2). Read the file COPYING that
  11. # comes with GRASS for details.
  12. #
  13. #############################################################################
  14. # %module
  15. # % description: Saves the contents of the active display monitor to a graphics file.
  16. # % keyword: display
  17. # % keyword: export
  18. # % keyword: output
  19. # %end
  20. # %option G_OPT_F_OUTPUT
  21. # % description: Name for output file
  22. # % required: yes
  23. # %end
  24. # %option
  25. # % key: format
  26. # % description: Graphics file format
  27. # % required: yes
  28. # % options: png,jpg,bmp,gif,tif
  29. # % answer: png
  30. # %end
  31. # %option
  32. # % key: size
  33. # % type: integer
  34. # % key_desc: width,height
  35. # % description: Width and height of output image
  36. # % guisection: Images
  37. # % required : no
  38. # %end
  39. from grass.script import core as gcore
  40. def main():
  41. options, flags = gcore.parser()
  42. gisenv = gcore.gisenv()
  43. if "MONITOR" in gisenv:
  44. cmd_file = gcore.parse_command("d.mon", flags="g")["cmd"]
  45. dout_cmd = "d.out.file"
  46. for param, val in options.items():
  47. if val:
  48. dout_cmd += " {param}={val}".format(param=param, val=val)
  49. with open(cmd_file, "a") as file_:
  50. file_.write(dout_cmd)
  51. else:
  52. gcore.fatal(
  53. _("No graphics device selected. Use d.mon to select graphics device.")
  54. )
  55. if __name__ == "__main__":
  56. main()