mapdisp_command.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 debug import Debug
  15. from threading import Thread
  16. class Command(Thread):
  17. """
  18. Creates thread which will observe the command file and see, if
  19. there is new command to be executed
  20. """
  21. def __init__ (self, parent, Map, cmdfile):
  22. Thread.__init__(self)
  23. global cmdfilename
  24. self.parent = parent
  25. self.map = Map
  26. self.cmdfile = open(cmdfile, "r")
  27. def run(self):
  28. """
  29. Run this in thread
  30. """
  31. dispcmd = []
  32. while 1:
  33. self.parent.redraw = False
  34. line = self.cmdfile.readline().strip()
  35. if line == "quit":
  36. break
  37. if line:
  38. try:
  39. Debug.msg (3, "Command.run(): cmd=%s" % (line))
  40. cmd = line.split(" ")
  41. opacity = 1
  42. if " opacity=" in line:
  43. cmd2 = cmd
  44. cmd = []
  45. for c in cmd2:
  46. if c.find("opacity=") == 0:
  47. opacity = float(c.split("=")[1]) / 100
  48. else:
  49. cmd.append(c)
  50. self.map.AddLayer(type="raster",
  51. name='',
  52. command=cmd,
  53. l_opacity=opacity)
  54. self.parent.redraw =True
  55. except Exception, e:
  56. print "Command Thread: ",e
  57. time.sleep(0.1)
  58. sys.exit()