p.cmd.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #%Module
  22. #% description: Wrapper for display commands and pX monitors
  23. #% keywords: display
  24. #%End
  25. #%Option
  26. #% key: cmd
  27. #% type: string
  28. #% required: yes
  29. #% multiple: no
  30. #% label: Command to be performed
  31. #% description: Example: "d.rast map=elevation.dem@PERMANENT catlist=1300-1400 -i"
  32. #%End
  33. #%Option
  34. #% key: opacity
  35. #% type: string
  36. #% required: no
  37. #% multiple: no
  38. #% key_desc: val
  39. #% description: Opacity level in percentage
  40. #% answer: 100
  41. #%End
  42. import os
  43. import grass.script as grass
  44. def main():
  45. cmd_file = grass.gisenv()["GRASS_PYCMDFILE"]
  46. if cmd_file == "" or os.path.exists(cmd_file) == False:
  47. grass.message(_("GRASS_PYCMDFILE - File not found. Run p.mon."), "e")
  48. return
  49. cmd = options["cmd"]
  50. opacity = options["opacity"]
  51. fp = open(cmd_file, "a")
  52. fp.write("%s opacity=%s\n" % (cmd, opacity))
  53. fp.close()
  54. if __name__ == "__main__":
  55. options, flags = grass.parser()
  56. main()