[GRASS-SVN] r30417 - in grass/trunk/gui/wxpython: . gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Mar 1 20:14:35 EST 2008


Author: martinl
Date: 2008-03-01 20:14:34 -0500 (Sat, 01 Mar 2008)
New Revision: 30417

Modified:
   grass/trunk/gui/wxpython/gis_set.py
   grass/trunk/gui/wxpython/gui_modules/gcmd.py
   grass/trunk/gui/wxpython/gui_modules/globalvar.py
   grass/trunk/gui/wxpython/gui_modules/grassenv.py
   grass/trunk/gui/wxpython/gui_modules/gselect.py
   grass/trunk/gui/wxpython/gui_modules/mapdisp.py
   grass/trunk/gui/wxpython/gui_modules/menuform.py
   grass/trunk/gui/wxpython/gui_modules/render.py
   grass/trunk/gui/wxpython/gui_modules/utils.py
   grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py
   grass/trunk/gui/wxpython/wxgui.py
Log:
wxGUI: initial MS Windows fixes (MSYS), GUI starts, raster layer(s) can displayed

Modified: grass/trunk/gui/wxpython/gis_set.py
===================================================================
--- grass/trunk/gui/wxpython/gis_set.py	2008-03-01 23:51:07 UTC (rev 30416)
+++ grass/trunk/gui/wxpython/gis_set.py	2008-03-02 01:14:34 UTC (rev 30417)
@@ -67,7 +67,7 @@
 
         # labels
         ### crashes when LOCATION doesn't exist
-        # versionCmd = gcmd.Command(['g.version'], log=None)
+        # versionCmd = gcmd.Command(['g.version' + globalvar.EXT_BIN], log=None)
         # grassVersion = versionCmd.ReadStdOutput()[0].replace('GRASS', '').strip()
         versionFile = open(os.path.join(globalvar.ETCDIR, "VERSIONNUMBER"))
         grassVersion = versionFile.readline().replace('%s' % os.linesep, '').strip()
@@ -609,11 +609,11 @@
 
     def OnStart(self, event):
         """'Start GRASS' button clicked"""
-        gcmd.Command(["g.gisenv",
+        gcmd.Command(["g.gisenv" + globalvar.EXT_BIN,
                       "set=GISDBASE=%s" % self.tgisdbase.GetValue()])
-        gcmd.Command(["g.gisenv",
+        gcmd.Command(["g.gisenv" + globalvar.EXT_BIN,
                       "set=LOCATION_NAME=%s" % self.listOfLocations[self.lblocations.GetSelection()]])
-        gcmd.Command(["g.gisenv",
+        gcmd.Command(["g.gisenv" + globalvar.EXT_BIN,
                       "set=MAPSET=%s" % self.listOfMapsets[self.lbmapsets.GetSelection()]])
 
         self.Destroy()

Modified: grass/trunk/gui/wxpython/gui_modules/gcmd.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gcmd.py	2008-03-01 23:51:07 UTC (rev 30416)
+++ grass/trunk/gui/wxpython/gui_modules/gcmd.py	2008-03-02 01:14:34 UTC (rev 30417)
@@ -457,16 +457,18 @@
             # make module stdout/stderr non-blocking
             out_fileno = self.module.stdout.fileno()
             # FIXME (MS Windows)
-            flags = fcntl.fcntl(out_fileno, fcntl.F_GETFL)
-            fcntl.fcntl(out_fileno, fcntl.F_SETFL, flags| os.O_NONBLOCK)
-            
+	    if not subprocess.mswindows:
+                flags = fcntl.fcntl(out_fileno, fcntl.F_GETFL)
+                fcntl.fcntl(out_fileno, fcntl.F_SETFL, flags| os.O_NONBLOCK)
+                
         if self.stderr:
             # make module stdout/stderr non-blocking
             out_fileno = self.module.stderr.fileno()
             # FIXME (MS Windows)
-            flags = fcntl.fcntl(out_fileno, fcntl.F_GETFL)
-            fcntl.fcntl(out_fileno, fcntl.F_SETFL, flags| os.O_NONBLOCK)
-
+	    if not subprocess.mswindows:
+                flags = fcntl.fcntl(out_fileno, fcntl.F_GETFL)
+                fcntl.fcntl(out_fileno, fcntl.F_SETFL, flags| os.O_NONBLOCK)
+                
         # wait for the process to end, sucking in stuff until it does end
         while self.module.poll() is None:
             time.sleep(.1)

Modified: grass/trunk/gui/wxpython/gui_modules/globalvar.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/globalvar.py	2008-03-01 23:51:07 UTC (rev 30416)
+++ grass/trunk/gui/wxpython/gui_modules/globalvar.py	2008-03-02 01:14:34 UTC (rev 30417)
@@ -18,11 +18,19 @@
 
 import os
 
-import utils
-utils.CheckForWx()
+### recursive import problem 
+# import utils
+# utils.CheckForWx()
 import wx
 import wx.lib.flatnotebook as FN
 
+try:
+    import subprocess
+except:
+    compatPath = os.path.join(globalvar.ETCWXDIR, "compat")
+    sys.path.append(compatPath)
+    import subprocess
+
 """
 Query layer (generated for example by selecting item in the Attribute Table Manager)
 Deleted automatically on re-render action
@@ -40,3 +48,10 @@
     FN.FNB_NODRAG | \
     FN.FNB_TABS_BORDER_SIMPLE 
 FNPageColor = wx.Colour(125,200,175)
+
+if subprocess.mswindows:
+    EXT_BIN = '.exe'
+    EXT_SCT = '.bat'
+else:
+    EXT_BIN = ''
+    EXT_SCT = ''

Modified: grass/trunk/gui/wxpython/gui_modules/grassenv.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/grassenv.py	2008-03-01 23:51:07 UTC (rev 30416)
+++ grass/trunk/gui/wxpython/gui_modules/grassenv.py	2008-03-02 01:14:34 UTC (rev 30417)
@@ -32,11 +32,10 @@
     """Return GRASS variable or '' if variable is not defined"""
     # gisEnv = gcmd.Command(['g.gisenv'])
 
-    gisEnv = subprocess.Popen(['g.gisenv'],
+    gisEnv = subprocess.Popen(['g.gisenv' + globalvar.EXT_BIN],
                               stdin=None,
                               stdout=subprocess.PIPE,
-                              stderr=None,
-                              close_fds=True)
+                              stderr=None)
 
     for item in gisEnv.stdout.readlines():
         if var in item:

Modified: grass/trunk/gui/wxpython/gui_modules/gselect.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gselect.py	2008-03-01 23:51:07 UTC (rev 30416)
+++ grass/trunk/gui/wxpython/gui_modules/gselect.py	2008-03-02 01:14:34 UTC (rev 30417)
@@ -21,6 +21,7 @@
 import wx
 import wx.combo
 
+import globalvar
 import gcmd
 from preferences import globalSettings as UserSettings
 
@@ -156,7 +157,7 @@
         with all relevant elements displayed beneath each mapset branch
         """
         #set environmental variables
-        cmdlist = ['g.gisenv', 'get=MAPSET']
+        cmdlist = ['g.gisenv' + globalvar.EXT_BIN, 'get=MAPSET']
         curr_mapset = gcmd.Command(cmdlist).ReadStdOutput()[0]
 
         #mapsets in current location
@@ -221,7 +222,7 @@
             dir_node = self.AddItem('Mapset: '+dir)
             self.seltree.SetItemTextColour(dir_node,wx.Colour(50,50,200))
             try:
-                cmdlist = ['g.mlist', 'type=%s' % elementdict[element], 'mapset=%s' % dir]
+                cmdlist = ['g.mlist' + globalvar.EXT_SCT, 'type=%s' % elementdict[element], 'mapset=%s' % dir]
                 elem_list = gcmd.Command(cmdlist).ReadStdOutput()
                 elem_list.sort()
                 for elem in elem_list:

Modified: grass/trunk/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/mapdisp.py	2008-03-01 23:51:07 UTC (rev 30416)
+++ grass/trunk/gui/wxpython/gui_modules/mapdisp.py	2008-03-02 01:14:34 UTC (rev 30417)
@@ -1983,7 +1983,7 @@
         # for user to set explicitly with g.region
         new = self.Map.AlignResolution()
 
-        cmdRegion = ["g.region", "--o",
+        cmdRegion = ["g.region" + globalvar.EXT_BIN, "--o",
                      "n=%f"    % new['n'],
                      "s=%f"    % new['s'],
                      "e=%f"    % new['e'],
@@ -2015,7 +2015,8 @@
 
         wind = dlg.wind
 
-        p = gcmd.Command (["g.region", "-ugp", "region=%s" % wind])
+        p = gcmd.Command (["g.region" + globalvar.EXT_BIN,
+	                   "-ugp", "region=%s" % wind])
 
         if p.returncode == 0:
             output = p.ReadStdOutput()
@@ -2067,7 +2068,7 @@
         """Save region settings"""
         new = self.Map.AlignResolution()
 
-        cmdRegion = ["g.region",
+        cmdRegion = ["g.region" + globalvar.EXT_BIN,
                      "-u",
                      "n=%f" % new['n'],
                      "s=%f" % new['s'],
@@ -2794,13 +2795,13 @@
 
         # build query commands for any selected rasters and vectors
         if raststr != '':
-            rcmd = ['r.what', '--q',
+            rcmd = ['r.what' + globalvar.EXT_BIN, '--q',
                     '-f',
                     'input=%s' % raststr.rstrip(','),
                     'east_north=%f,%f' % (float(east), float(north))]
 
         if vectstr != '':
-            vcmd = ['v.what', '--q',
+            vcmd = ['v.what' + globalvar.EXT_BIN, '--q',
                     '-a',
                     'map=%s' % vectstr.rstrip(','),
                     'east_north=%f,%f' % (float(east), float(north)),

Modified: grass/trunk/gui/wxpython/gui_modules/menuform.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/menuform.py	2008-03-01 23:51:07 UTC (rev 30416)
+++ grass/trunk/gui/wxpython/gui_modules/menuform.py	2008-03-02 01:14:34 UTC (rev 30417)
@@ -243,7 +243,7 @@
         built so far, even though it would not be a correct command
         for GRASS.
         """
-        cmd = [self.name]
+        cmd = [self.name + globalvar.EXT_BIN]
         errors = 0
         errStr = ""
 

Modified: grass/trunk/gui/wxpython/gui_modules/render.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/render.py	2008-03-01 23:51:07 UTC (rev 30416)
+++ grass/trunk/gui/wxpython/gui_modules/render.py	2008-03-02 01:14:34 UTC (rev 30417)
@@ -17,11 +17,21 @@
 @date 2006-2008
 """
 
-import os, sys, glob, math
-import utils
+import os
+import sys
+import glob
+import math
+try:
+    import subprocess
+except:
+    compatPath = os.path.join(globalvar.ETCWXDIR, "compat")
+    sys.path.append(compatPath)
+    import subprocess
 
 import wx
 
+import globalvar
+import utils
 import gcmd
 from debug import Debug as Debug
 
@@ -104,7 +114,7 @@
         # start monitor
         #
         os.environ["GRASS_PNGFILE"] = self.mapfile
-
+        
         #
         # execute command
         #
@@ -237,7 +247,7 @@
                                    "in GRASS GIS to run this program")
             sys.exit(1)
 
-        gisenvCmd = gcmd.Command(["g.gisenv"])
+        gisenvCmd = gcmd.Command(["g.gisenv" + globalvar.EXT_BIN])
 
         for line in gisenvCmd.ReadStdOutput():
             line = line.strip()
@@ -385,7 +395,7 @@
         os.unsetenv("GRASS_REGION")
 
         # do not update & shell style output
-        cmdList = ["g.region", "-u", "-g", "-p", "-c"]
+        cmdList = ["g.region" + globalvar.EXT_BIN, "-u", "-g", "-p", "-c"]
 
         if rast:
             cmdList.append('rast=%s' % rast)
@@ -483,7 +493,7 @@
 
         projinfo = {}
 
-        p = gcmd.Command(['g.proj', '-p'])
+        p = gcmd.Command(['g.proj' + globalvar.EXT_BIN, '-p'])
 
         if p.returncode == 0:
             for line in p.ReadStdOutput():
@@ -604,24 +614,42 @@
                 
             Debug.msg (3, "Map.Render() type=%s, layer=%s " % (layer.type, layer.name))
 
-        # compose command
-        #         compcmd = ["g.pnmcomp",
-        #                    "in='%s'" % ",".join(maps),
-        #                    "mask=%s" % ",".join(masks),
-        #                    "opacity=%s" % ",".join(opacities),
-        #                    "background=255:255:255",
-        #                    "width=%s" % str(self.width),
-        #                    "height=%s" % str(self.height),
-        #                    "output=%s" % self.mapfile]
-        
-        compcmd = "g.pnmcomp in='" + ",".join(maps) + \
-            "' mask='" + ",".join(masks) + \
-            "' opacity=" + ",".join(opacities)+ \
+	# ugly hack for MSYS
+	if not subprocess.mswindows:
+	    mapstr = ",".join(maps)
+	    maskstr = ",".join(masks)
+            mapoutstr = self.mapfile
+	else:
+	    mapstr = ""
+	    for item in maps:
+                mapstr += item.replace('\\', '/')		
+	    mapstr = mapstr.rstrip(',')
+	    maskstr = ""
+            for item in masks:
+		maskstr += item.replace('\\', '/')
+	    maskstr = maskstr.rstrip(',')
+	    mapoutstr = self.mapfile.replace('\\', '/')
+
+        compstring = "g.pnmcomp" + globalvar.EXT_BIN + \
+            " in=" + mapstr + \
+            " mask=" + maskstr + \
+            " opacity=" + ",".join(opacities)+ \
             " background=255:255:255" + \
             " width=" + str(self.width) + \
             " height=" + str(self.height) + \
-            " output='" + self.mapfile + "'"
+            " output=" + mapoutstr
 
+        # compose command
+        complist = ["g.pnmcomp" + globalvar.EXT_BIN,
+                   "in=%s" % ",".join(maps),
+	           "mask=%s" % ",".join(masks),
+                   "opacity=%s" % ",".join(opacities),
+                   "background=255:255:255",
+                   "width=%s" % str(self.width),
+                   "height=%s" % str(self.height),
+                   "output=%s" % self.mapfile]
+
+
         # render overlays
 
         os.unsetenv("GRASS_REGION")
@@ -629,10 +657,10 @@
         if tmp_region:
             os.environ["GRASS_REGION"] = tmp_region
 
-        # run g.composite to get composite image
+        # run g.pngcomp to get composite image
         try:
-            # gcmd.Command(compcmd)
-            os.system(compcmd)
+            gcmd.Command(complist)
+	    # os.system(compstring)
         except gcmd.CmdError, e:
             print e
             return None

Modified: grass/trunk/gui/wxpython/gui_modules/utils.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/utils.py	2008-03-01 23:51:07 UTC (rev 30416)
+++ grass/trunk/gui/wxpython/gui_modules/utils.py	2008-03-02 01:14:34 UTC (rev 30417)
@@ -17,6 +17,7 @@
 import os
 import sys
 
+import globalvar
 try:
     import subprocess
 except:
@@ -28,24 +29,31 @@
     """
     Creates GRASS temporary file using defined prefix.
 
+    @todo Fix path on MS Windows/MSYS
+
     @param pref prefer the given path
 
     @return Path to file name (string) or None
     """
     import gcmd
-    tempfileCmd = gcmd.Command(["g.tempfile",
-                                "pid=%d" %
-                                os.getpid()])
 
+    tempfileCmd = gcmd.Command(["g.tempfile" + globalvar.EXT_BIN,
+                                "pid=%d" % os.getpid()])
+
     tempfile = tempfileCmd.ReadStdOutput()[0].strip()
 
+    # FIXME
+    # ugly hack for MSYS (MS Windows)
+    if subprocess.mswindows:
+	tempfile = tempfile.replace("/", "\\")
     try:
         path, file = os.path.split(tempfile)
         if pref:
-            file = "%s%s" % (pref, file)
-        return os.path.join(path, file)
+            return os.path.join(pref, file)
+	else:
+	    return tempfile
     except:
-        return Node
+        return None
 
 def GetLayerNameFromCmd(dcmd):
     """Get layer name from GRASS command
@@ -150,7 +158,7 @@
     ### FIXME
     # problem using Command here (see preferences.py)
     # cmd = gcmd.Command(['g.mapsets', '-l'])
-    cmd = subprocess.Popen(['g.mapsets', '-l'],
+    cmd = subprocess.Popen(['g.mapsets' + globalvar.EXT_BIN, '-l'],
                            stdout=subprocess.PIPE)
     
     try:
@@ -164,7 +172,7 @@
         raise gcmd.CmdError('Unable to get list of available mapsets.')
     
     # cmd = gcmd.Command(['g.mapsets', '-p'])
-    cmd = subprocess.Popen(['g.mapsets', '-p'],
+    cmd = subprocess.Popen(['g.mapsets' + globalvar.EXT_BIN, '-p'],
                            stdout=subprocess.PIPE)
     try:
         # for mset in cmd.ReadStdOutput()[0].split(' '):

Modified: grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py	2008-03-01 23:51:07 UTC (rev 30416)
+++ grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py	2008-03-02 01:14:34 UTC (rev 30417)
@@ -37,6 +37,7 @@
 import wx.stc
 import wx.lib.newevent
 
+import globalvar
 import menuform
 import mapdisp
 import render

Modified: grass/trunk/gui/wxpython/wxgui.py
===================================================================
--- grass/trunk/gui/wxpython/wxgui.py	2008-03-01 23:51:07 UTC (rev 30416)
+++ grass/trunk/gui/wxpython/wxgui.py	2008-03-02 01:14:34 UTC (rev 30417)
@@ -41,7 +41,10 @@
 from xml.sax import make_parser
 ### i18N
 import gettext
-gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode=True)
+try:
+    gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode=True)
+except:
+    print >> sys.stderr, 'WARNING: Unable to load locale'
 
 import gui_modules
 gmpath = gui_modules.__path__[0]
@@ -1256,7 +1259,7 @@
         self.workspaceFile = workspace
         
         # call parent class initializer
-        wx.App.__init__(self)
+        wx.App.__init__(self, False)
         
     def OnInit(self):
         # initialize all available image handlers



More information about the grass-commit mailing list