d.redraw.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/env python
  2. ############################################################################
  3. #
  4. # MODULE: d.redraw
  5. # AUTHOR(S): Martin Landa <landa.martin gmail.com>
  6. # PURPOSE: Redraws the content of currently selected monitor
  7. # COPYRIGHT: (C) 2011-2015 by the GRASS Development Team
  8. #
  9. # This program is free software under the GNU General
  10. # Public License (>=v2). Read the file COPYING that
  11. # comes with GRASS for details.
  12. #
  13. #############################################################################
  14. #%module
  15. #% description: Redraws the content of currently selected monitor.
  16. #% keyword: display
  17. #% keyword: graphics
  18. #% keyword: monitors
  19. #%end
  20. import os
  21. import sys
  22. from grass.script import core as grass
  23. from grass.script.utils import split
  24. def main():
  25. mon = grass.gisenv().get('MONITOR', None)
  26. if not mon:
  27. grass.fatal(_("No graphics device selected. Use d.mon to select graphics device."))
  28. monCmd = grass.parse_command('d.mon', flags='g').get('cmd', None)
  29. if not monCmd or not os.path.isfile(monCmd):
  30. grass.fatal(_("Unable to open file '%s'") % monCmd)
  31. try:
  32. fd = open(monCmd, 'r')
  33. cmdList = fd.readlines()
  34. grass.run_command('d.erase')
  35. for cmd in cmdList:
  36. grass.call(split(cmd))
  37. except IOError as e:
  38. grass.fatal(_("Unable to open file '%s' for reading. Details: %s") % \
  39. (monCmd, e))
  40. fd.close()
  41. # restore cmd file
  42. try:
  43. fd = open(monCmd, "w")
  44. fd.writelines(cmdList)
  45. except IOError as e:
  46. grass.fatal(_("Unable to open file '%s' for writing. Details: %s") % \
  47. (monCmd, e))
  48. return 0
  49. if __name__ == "__main__":
  50. options, flags = grass.parser()
  51. sys.exit(main())