[GRASS-SVN] r64435 - grass/trunk/gui/wxpython/mapdisp
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Feb 3 09:53:40 PST 2015
Author: martinl
Date: 2015-02-03 09:53:40 -0800 (Tue, 03 Feb 2015)
New Revision: 64435
Modified:
grass/trunk/gui/wxpython/mapdisp/main.py
Log:
wxGUI: first steps to fix standalone monitors to work with new architecture
Modified: grass/trunk/gui/wxpython/mapdisp/main.py
===================================================================
--- grass/trunk/gui/wxpython/mapdisp/main.py 2015-02-03 17:02:52 UTC (rev 64434)
+++ grass/trunk/gui/wxpython/mapdisp/main.py 2015-02-03 17:53:40 UTC (rev 64435)
@@ -29,6 +29,7 @@
import os
import sys
import time
+import shutil
from core import globalvar
import wx
@@ -477,30 +478,45 @@
sys.exit(1)
monName = sys.argv[1]
- monFile = { 'map' : sys.argv[2],
- 'cmd' : sys.argv[3],
- 'env' : sys.argv[4],
- }
- if len(sys.argv) >= 6:
- try:
- monSize[0] = int(sys.argv[5])
- except ValueError:
- pass
+ dInfo = grass.parse_command('d.info', flags='s')
+ monPath = dInfo.get('path', None)
+ if not monPath:
+ grass.fatal(_("Unable to open monitor <%s>. No path defined") % monName)
- if len(sys.argv) >= 7:
- try:
- monSize[1] = int(sys.argv[6])
- except ValueError:
- pass
+ monFile = { 'map' : os.path.join(monPath, 'map.ppm'),
+ 'cmd' : dInfo.get('cmd', None),
+ 'env' : dInfo.get('env', None) }
- if len(sys.argv) == 8:
- try:
- monDecor = True if sys.argv[7] == "0" else False
- except ValueError:
- monDecor = True
+ # monitor size
+ monSize = (640, 480)
+ ret = grass.read_command('d.info', flags='d')
+ if not ret:
+ grass.warning(_("Unable to determine size of monitor. Using default %dx%d.") % \
+ monSize[0], monSize[1])
+ else:
+ monSize = map(float, ret.rstrip('\n').split(' ', 1)[1].split(' '))
+
+ monDecor = True
+ # TODO
+ # if len(sys.argv) == 8:
+ # try:
+ # monDecor = True if sys.argv[7] == "0" else False
+ # except ValueError:
+ # monDecor = True
grass.verbose(_("Starting map display <%s>...") % (monName))
+ # create pid file
+ monPath = grass.parse_command('d.info', flags='s').get('path', None)
+ if not monPath:
+ grass.fatal(_("No monitor path defined"))
+ pidFile = os.path.join(monPath, "pid")
+ fd = open(pidFile, 'w')
+ if not fd:
+ grass.fatal(_("Unable to create file <%s>") % pidFile)
+ fd.write("%s\n" % os.getpid())
+ fd.close()
+
RunCommand('g.gisenv',
set = 'MONITOR_%s_PID=%d' % (monName.upper(), os.getpid()))
@@ -516,15 +532,12 @@
grass.verbose(_("Stopping map display <%s>...") % (monName))
# clean up GRASS env variables
- env = grass.gisenv()
- env_name = 'MONITOR_%s' % monName.upper()
- unset = list()
- for key in env.keys():
- if key.find(env_name) == 0 or \
- (key == 'MONITOR' and env[key] == monName):
- unset.append(key)
- if unset:
- RunCommand('g.gisenv',
- unset = '%s' % ','.join(unset))
+ try:
+ shutil.rmtree(monPath)
+ except OSError:
+ pass
+ RunCommand('g.gisenv',
+ unset = 'MONITOR')
+
sys.exit(0)
More information about the grass-commit
mailing list