GRASS Programmer's Manual  6.4.2(2012)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
p.cmd.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 ############################################################################
3 #
4 # MODULE: p.cmd
5 # AUTHOR(S): Martin Landa, Hamish Bowman
6 # Converted to Python by Huidae Cho
7 # PURPOSE: Wrapper for display commands and pX monitors
8 # COPYRIGHT: (C) 2009 by The GRASS Development Team
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 #
20 ############################################################################
21 
22 #%Module
23 #% description: Wrapper for display commands and pX monitors
24 #% keywords: display
25 #%End
26 
27 #%Option
28 #% key: cmd
29 #% type: string
30 #% required: yes
31 #% multiple: no
32 #% label: Command to be performed
33 #% description: Example: "d.rast map=elevation.dem@PERMANENT catlist=1300-1400 -i"
34 #%End
35 
36 #%Option
37 #% key: opacity
38 #% type: string
39 #% required: no
40 #% multiple: no
41 #% key_desc: val
42 #% description: Opacity level in percentage
43 #% answer: 100
44 #%End
45 
46 import os
47 import grass.script as grass
48 
49 def main():
50  cmd_file = grass.gisenv()["GRASS_PYCMDFILE"]
51 
52  if cmd_file == "" or os.path.exists(cmd_file) == False:
53  grass.message(_("GRASS_PYCMDFILE - File not found. Run p.mon."), "e")
54  return
55 
56  cmd = options["cmd"]
57  opacity = options["opacity"]
58 
59  fp = open(cmd_file, "a")
60  fp.write("%s opacity=%s\n" % (cmd, opacity))
61  fp.close()
62 
63 if __name__ == "__main__":
64  options, flags = grass.parser()
65  main()