mapdisp_command.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. """
  2. @package mapdisp.py
  3. @brief Command line useg of GIS map display canvas.view).
  4. Classes:
  5. - Command
  6. (C) 2006-2009 by the GRASS Development Team
  7. This program is free software under the GNU General Public
  8. License (>=v2). Read the file COPYING that comes with GRASS
  9. for details.
  10. @author Jachym Cepicky
  11. """
  12. import sys
  13. import time
  14. from threading import Thread
  15. class Command(Thread):
  16. """
  17. Creates thread which will observe the command file and see, if
  18. there is new command to be executed
  19. """
  20. def __init__ (self, parent, Map, cmdfile):
  21. Thread.__init__(self)
  22. global cmdfilename
  23. self.parent = parent
  24. self.map = Map
  25. self.cmdfile = open(cmdfile, "r")
  26. def run(self):
  27. """
  28. Run this in thread
  29. """
  30. dispcmd = []
  31. while 1:
  32. self.parent.redraw = False
  33. line = self.cmdfile.readline().strip()
  34. if line == "quit":
  35. break
  36. if line:
  37. try:
  38. Debug.msg (3, "Command.run(): cmd=%s" % (line))
  39. self.map.AddLayer(item=None, type="raster",
  40. name='',
  41. command=line,
  42. l_opacity=1)
  43. self.parent.redraw =True
  44. except Exception, e:
  45. print "Command Thread: ",e
  46. time.sleep(0.1)
  47. sys.exit()