d.redraw.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. env = grass.gisenv()
  26. mon = env.get('MONITOR', None)
  27. if not mon:
  28. grass.fatal(_("No graphics device selected. Use d.mon to select graphics device."))
  29. monCmd = os.sep.join(grass.tempfile().split(os.sep)[:-1] + ['MONITORS', mon, 'cmd'])
  30. if not monCmd or not os.path.isfile(monCmd):
  31. grass.fatal(_("Unable to open file '%s'") % monCmd)
  32. try:
  33. fd = open(monCmd, 'r')
  34. cmdList = fd.readlines()
  35. grass.run_command('d.erase')
  36. for cmd in cmdList:
  37. grass.call(split(cmd))
  38. except IOError as e:
  39. grass.fatal(_("Unable to open file '%s' for reading. Details: %s") % \
  40. (monCmd, e))
  41. fd.close()
  42. # restore cmd file
  43. try:
  44. fd = open(monCmd, "w")
  45. fd.writelines(cmdList)
  46. except IOError as e:
  47. grass.fatal(_("Unable to open file '%s' for writing. Details: %s") % \
  48. (monCmd, e))
  49. return 0
  50. if __name__ == "__main__":
  51. options, flags = grass.parser()
  52. sys.exit(main())