d.out.file.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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-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. #%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. # i18N
  40. import os
  41. import gettext
  42. gettext.install('grassmods', os.path.join(os.getenv("GISBASE"), 'locale'))
  43. def main():
  44. options, flags = gcore.parser()
  45. gisenv = gcore.gisenv()
  46. if 'MONITOR' in gisenv:
  47. cmd_file = gcore.parse_command('d.mon', flags='g')['cmd']
  48. dout_cmd = 'd.out.file'
  49. for param, val in options.items():
  50. if val:
  51. dout_cmd += " {param}={val}".format(param=param, val=val)
  52. with open(cmd_file, "a") as file_:
  53. file_.write(dout_cmd)
  54. else:
  55. gcore.fatal(_("No graphics device selected. Use d.mon to select graphics device."))
  56. if __name__ == "__main__":
  57. main()