[GRASS-dev] making py.monitor listen to external commands

Jachym Cepicky jachym.cepicky at centrum.cz
Mon Jun 12 15:47:22 EDT 2006


On Mon, Jun 12, 2006 at 12:36:32PM -0700, David Finlayson wrote:
> One thing that might be helpful is to have a file which lists the
> currently displayed ppm images (in the monitor) in the order that they
> are displayed. Then a command line program could replace the list with
> new data (d.erase) or append to the list (d.rast -o). The monitor
> would need to check if the list had been changed and then update
> itself (maybe after receiving an update yourself signal via a socket)
> 
> Ideally, the monitor list would contain enough information to update
> the gis.m widgets as well.
> 
> In other words, d.erase would erase the monitor and (optionally) also
> remove all the drawing "widgets" from gis.m. Issuing a d.rast command
> would, in addition to updating the monitor, replace or append to the
> gis.m widgets as appropriate.
> 

yes, yes, that is no question about what it should do

def watcher(self):
    commands_file = "py.commands"
    commands = open(commands_file,"r")
    st_results = os.stat(commands_file)
    st_size = st_results[6]
    commands.seek(st_size)

    while 1:
        where = commands.tell()
        line = commands.readline()
        if not line:
            time.sleep(1)
            commands.seek(where)
        else:
            line = line.strip()

            if line == "d.erase":
                self.commandsCtrl.SetValue('') 
            else:
                self.commandsCtrl.SetValue(
                    self.commandsCtrl.GetValue()+"\n"+line+"\n")

But how?

I have rewritten the code a bit, but it does not seem, that both
processes would have same space in memory :-(

class Monitor(wx.App):
    def OnInit(self):
        ...
        
        try: 
            pid = os.fork() 
            if pid == 0:
                self.watcher()
            else:
                print self.semafor
                print "otec"
        except OSError, e: 
            # no fork
            sys.exit(1)
        return True

It would be maybe better, do it in MainLoop, but I did not found the
approach, how to smuggle watcher() in the MainLoop :-(

Jachym

-- 
Jachym Cepicky
e-mail: jachym.cepicky at centrum.cz
URL: http://les-ejk.cz
GPG: http://les-ejk.cz/gnupg_public_key/jachym_cepicky-gpg_public_key.asc
-----------------------------------------   
OFFICE:                                     
GDF-Hannover
Mengendamm 16d
30177 Hannover
Germany
e-mail: cepicky at gdf-hannover.de
URL:    http://gdf-hannover.de
Tel.:   +49 511-39088507
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.osgeo.org/pipermail/grass-dev/attachments/20060612/6e39c911/attachment.bin


More information about the grass-dev mailing list