File: d.out.file.py

package info (click to toggle)
grass 8.4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 277,040 kB
  • sloc: ansic: 460,798; python: 227,732; cpp: 42,026; sh: 11,262; makefile: 7,007; xml: 3,637; sql: 968; lex: 520; javascript: 484; yacc: 450; asm: 387; perl: 157; sed: 25; objc: 6; ruby: 4
file content (63 lines) | stat: -rw-r--r-- 1,706 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python3

############################################################################
#
# MODULE: d.out.file
# AUTHOR(S): Anna Petrasova <kratochanna gmail.com>
# PURPOSE:	Script for exporting content of monitor to graphic file
# COPYRIGHT: (C) 2014-2015 by the GRASS Development Team
#
# 		This program is free software under the GNU General
# 		Public License (>=v2). Read the file COPYING that
# 		comes with GRASS for details.
#
#############################################################################

# %module
# % description: Saves the contents of the active display monitor to a graphics file.
# % keyword: display
# % keyword: export
# % keyword: output
# %end
# %option G_OPT_F_OUTPUT
# % description: Name for output file
# % required: yes
# %end
# %option
# % key: format
# % description: Graphics file format
# % required: yes
# % options: png,jpg,bmp,gif,tif
# % answer: png
# %end
# %option
# % key: size
# % type: integer
# % key_desc: width,height
# % description: Width and height of output image
# % guisection: Images
# % required : no
# %end

from grass.script import core as gcore


def main():
    options, flags = gcore.parser()
    gisenv = gcore.gisenv()
    if "MONITOR" in gisenv:
        cmd_file = gcore.parse_command("d.mon", flags="g")["cmd"]
        dout_cmd = "d.out.file"
        for param, val in options.items():
            if val:
                dout_cmd += " {param}={val}".format(param=param, val=val)
        with open(cmd_file, "a") as file_:
            file_.write(dout_cmd)
    else:
        gcore.fatal(
            _("No graphics device selected. Use d.mon to select graphics device.")
        )


if __name__ == "__main__":
    main()