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