GRASS Programmer's Manual
6.4.2(2012)
|
00001 #!/usr/bin/env python 00002 ############################################################################ 00003 # 00004 # MODULE: p.cmd 00005 # AUTHOR(S): Martin Landa, Hamish Bowman 00006 # Converted to Python by Huidae Cho 00007 # PURPOSE: Wrapper for display commands and pX monitors 00008 # COPYRIGHT: (C) 2009 by The GRASS Development Team 00009 # 00010 # This program is free software; you can redistribute it and/or modify 00011 # it under the terms of the GNU General Public License as published by 00012 # the Free Software Foundation; either version 2 of the License, or 00013 # (at your option) any later version. 00014 # 00015 # This program is distributed in the hope that it will be useful, 00016 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 # GNU General Public License for more details. 00019 # 00020 ############################################################################ 00021 00022 #%Module 00023 #% description: Wrapper for display commands and pX monitors 00024 #% keywords: display 00025 #%End 00026 00027 #%Option 00028 #% key: cmd 00029 #% type: string 00030 #% required: yes 00031 #% multiple: no 00032 #% label: Command to be performed 00033 #% description: Example: "d.rast map=elevation.dem@PERMANENT catlist=1300-1400 -i" 00034 #%End 00035 00036 #%Option 00037 #% key: opacity 00038 #% type: string 00039 #% required: no 00040 #% multiple: no 00041 #% key_desc: val 00042 #% description: Opacity level in percentage 00043 #% answer: 100 00044 #%End 00045 00046 import os 00047 import grass.script as grass 00048 00049 def main(): 00050 cmd_file = grass.gisenv()["GRASS_PYCMDFILE"] 00051 00052 if cmd_file == "" or os.path.exists(cmd_file) == False: 00053 grass.message(_("GRASS_PYCMDFILE - File not found. Run p.mon."), "e") 00054 return 00055 00056 cmd = options["cmd"] 00057 opacity = options["opacity"] 00058 00059 fp = open(cmd_file, "a") 00060 fp.write("%s opacity=%s\n" % (cmd, opacity)) 00061 fp.close() 00062 00063 if __name__ == "__main__": 00064 options, flags = grass.parser() 00065 main()