mapdisp_command.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. from threading import Thread
  13. class Command(Thread):
  14. """
  15. Creates thread which will observe the command file and see, if
  16. there is new command to be executed
  17. """
  18. def __init__ (self, parent, Map):
  19. Thread.__init__(self)
  20. global cmdfilename
  21. self.parent = parent
  22. self.map = Map
  23. self.cmdfile = open(cmdfilename, "r")
  24. def run(self):
  25. """
  26. Run this in thread
  27. """
  28. dispcmd = []
  29. while 1:
  30. self.parent.redraw = False
  31. line = self.cmdfile.readline().strip()
  32. if line == "quit":
  33. break
  34. if line:
  35. try:
  36. Debug.msg (3, "Command.run(): cmd=%s" % (line))
  37. self.map.AddLayer(item=None, type="raster",
  38. name='',
  39. command=line,
  40. l_opacity=1)
  41. self.parent.redraw =True
  42. except Exception, e:
  43. print "Command Thread: ",e
  44. time.sleep(0.1)
  45. sys.exit()