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