GRASS Programmer's Manual  6.4.2(2012)
mapdisp_command.py
Go to the documentation of this file.
00001 """
00002 @package mapdisp.py
00003 
00004 @brief Command line useg of GIS map display canvas.view).
00005 
00006 Classes:
00007  - Command
00008 
00009 (C) 2006-2009 by the GRASS Development Team
00010 This program is free software under the GNU General Public
00011 License (>=v2). Read the file COPYING that comes with GRASS
00012 for details.
00013 
00014 @author Jachym Cepicky
00015 """
00016 
00017 import sys
00018 import time
00019 
00020 from threading import Thread
00021 
00022 class Command(Thread):
00023     """
00024     Creates thread which will observe the command file and see, if
00025     there is new command to be executed
00026     """
00027     def __init__ (self, parent, Map, cmdfile):
00028         Thread.__init__(self)
00029 
00030         global cmdfilename
00031 
00032         self.parent = parent
00033         self.map = Map
00034         self.cmdfile = open(cmdfile, "r")
00035 
00036     def run(self):
00037         """
00038         Run this in thread
00039         """
00040         dispcmd = []
00041         while 1:
00042             self.parent.redraw = False
00043             line = self.cmdfile.readline().strip()
00044             if line == "quit":
00045                 break
00046 
00047             if line:
00048                 try:
00049                     Debug.msg (3, "Command.run(): cmd=%s" % (line))
00050 
00051                     self.map.AddLayer(item=None, type="raster",
00052                                       name='',
00053                                       command=line,
00054                                       l_opacity=1)
00055 
00056                     self.parent.redraw =True
00057 
00058                 except Exception, e:
00059                     print "Command Thread: ",e
00060 
00061             time.sleep(0.1)
00062 
00063         sys.exit()
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines