d.redraw.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. # i18N
  25. import gettext
  26. gettext.install('grassmods', os.path.join(os.getenv("GISBASE"), 'locale'))
  27. def main():
  28. mon = grass.gisenv().get('MONITOR', None)
  29. if not mon:
  30. grass.fatal(_("No graphics device selected. Use d.mon to select graphics device."))
  31. monCmd = grass.parse_command('d.mon', flags='g').get('cmd', None)
  32. if not monCmd or not os.path.isfile(monCmd):
  33. grass.fatal(_("Unable to open file '%s'") % monCmd)
  34. try:
  35. fd = open(monCmd, 'r')
  36. cmdList = fd.readlines()
  37. grass.run_command('d.erase')
  38. for cmd in cmdList:
  39. if cmd.startswith('#'):
  40. continue
  41. grass.call(split(cmd))
  42. except IOError as e:
  43. grass.fatal(_("Unable to open file '%s' for reading. Details: %s") %
  44. (monCmd, e))
  45. fd.close()
  46. # restore cmd file
  47. try:
  48. fd = open(monCmd, "w")
  49. fd.writelines(cmdList)
  50. except IOError as e:
  51. grass.fatal(_("Unable to open file '%s' for writing. Details: %s") %
  52. (monCmd, e))
  53. return 0
  54. if __name__ == "__main__":
  55. options, flags = grass.parser()
  56. sys.exit(main())