[GRASS-dev] making py.monitor listen to external commands
Jachym Cepicky
jachym.cepicky at centrum.cz
Mon Jun 12 14:30:52 EDT 2006
Hallo,
I'm trying to script something, which could be in the future called
py.mon(itor) using wxpython together with xrc.
The basic is here - I can display ppm file
Now, I would like to make it "listen" to command line commands and I
have been thinking of approach like this:
The idea is, you would tip just normal py.* commands in the command line,
but there would be process running in background, which would pick up
the last line from history file (e.g. .monitor_x0_history) and add it to stack of
commands for the monitor.
We would have to create set of py.* commands, which would replace the
d.* commands and general structure of this py.* commands would look like
this:
---------------------------
# py.rast
# get the selected monitor
monitor = os.getenv("GRASS_MONITOR")
# get the file name
command_file = os.path.join(GISBASE,LOCATION,MAPSET,".monitor_"+monitor+"_history)
# write d.rast to commands
file = open(command_file,"a")
file.write("d.rast "+sys.arg[1:])
file.close()
---------------------------
Then there should be loop in py.monitor:
1) watcher(), which would take care on the .monitor_x0_history file just like tail -f does
if there would be some change, it would add command to the
monitor commands stack and redraw the monitor with new set of
commands
2) pymonitor.MainLoop(), which displays the gui and sets the
variables
So, I have monitor (see screenshot [1]), I can tip commands in some
"terminal" under the window. I have "watcher" which takes care on the
command file and if there is some change, it should set the "monitor
terminal" to the value of the command(s) to new command.
But it does not because the processes do not "see" each other. I'm also
not able to kill the processes while closing the monitor, because of I'm
not able to get their PIDs.
So my question: how to perform task like this? I know, this is task for
"reall" programmers, maybe I choosed completly wrong approach.
I took the code from
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66012 and
modified it like this:
-------------------------------
class Monitor(wx.App):
"""
py.monitor gui
"""
def OnInit(self):
"""
Init the gui
"""
try:
pid = os.fork()
if pid > 0:
# exit first parent
sys.exit(0)
except OSError, e:
print >>sys.stderr, "fork #1 failed: %d (%s)" % (e.errno,
e.strerror)
sys.exit(1)
# decouple from parent environment
os.setsid()
os.umask(0)
# initialize the GUI
self.initFrame()
self.rast = map.raster.Raster()
self.initToolBar()
self.initCommands()
self.initDrawArea()
self.frame.Show()
# do second fork
try:
pid = os.fork()
if pid > 0:
# exit from second parent, print eventual PID before
#print "Daemon PID %d" % pid
# OnInit should return boolean value
return True
#sys.exit(0)
except OSError, e:
print >>sys.stderr, "fork #2 failed: %d (%s)" % (e.errno,
e.strerror)
sys.exit(1)
# start the daemon watcher
self.watcher()
[....]
# startin the gui
def main():
pymonitor = Monitor(0)
pymonitor.MainLoop()
-------------------------------
Thanks for hints I hope, one can understand, what I wanted to say.
Jachym
[1] http://les-ejk.cz/tmp/py.monitor.png
--
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/7ca3e3da/attachment.bin
More information about the grass-dev
mailing list