d.out.file.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env python
  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 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. #% keywords: display
  17. #% keywords: export
  18. #%end
  19. #%option G_OPT_F_OUTPUT
  20. #% description: Name for output file
  21. #% required: yes
  22. #%end
  23. #%option
  24. #% key: format
  25. #% description: Graphics file format
  26. #% required: yes
  27. #% options: png,jpg,bmp,gif,tif
  28. #% answer: png
  29. #%end
  30. #%option
  31. #% key: size
  32. #% type: integer
  33. #% key_desc: width,height
  34. #% description: Width and height of output image
  35. #% guisection: Images
  36. #% required : no
  37. #%end
  38. from grass.script import core as gcore
  39. def main():
  40. options, flags = gcore.parser()
  41. gisenv = gcore.gisenv()
  42. if 'MONITOR' in gisenv:
  43. cmd_file = gisenv['MONITOR_{monitor}_CMDFILE'.format(monitor=gisenv['MONITOR'].upper())]
  44. dout_cmd = 'd.out.file'
  45. for param, val in options.iteritems():
  46. if val:
  47. dout_cmd += " {param}={val}".format(param=param, val=val)
  48. with open(cmd_file, "a") as file_:
  49. file_.write(dout_cmd)
  50. else:
  51. gcore.fatal(_("No graphics device selected. Use d.mon to select graphics device."))
  52. if __name__ == "__main__":
  53. main()