[GRASS-dev] making py.monitor listen to external commands
Jáchym Čepický
jachym.cepicky at centrum.cz
Fri Jun 16 07:42:43 EDT 2006
Hallo,
I just tryed the py.mon stuff on win xp box and it nearly worked :-) the window appears, but I did not manage to display any map.
this just means, that used approach (python + wxwidget) seem really to work on windows and that it can use at least some commands from grass via os.system()
screenshot on les-ejk.cz/tmp/pymon-win.png [0.5 MB]
Have a nice weekend
Jachym
P.S. I used Wingrass (qgis+grass) precompiled package from Radim, started qgis, started GRASS-Shell and run. Maybe in commandline.exe it would work better?
--
Jachym Cepicky
e-mail: jachym.cepicky at centrum.cz
URL: http://les-ejk.cz
GPG: http://les-ejk.cz/gnupg_public_key/
-----------------------------------------
OFFICE:
Department of Geoinformation Technologies
LDF MZLU v Brně
Zemědělská 3
613 00 Brno
e-mail: xcepicky at node.mendelu.cz
URL: http://mapserver.mendelu.cz
Tel.: +420 545 134 514
______________________________________________________________
> Od: jachym.cepicky at centrum.cz
> Komu: grass-dev at grass.itc.it
> Datum: 12.06.2006 20:32
> Předmět: [GRASS-dev] making py.monitor listen to external commands
>
>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
>
>_______________________________________________
>grass-dev mailing list
>grass-dev at grass.itc.it
>http://grass.itc.it/mailman/listinfo/grass-dev
>
More information about the grass-dev
mailing list