[GRASS-SVN] r32831 - grass/branches/develbranch_6/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Aug 17 01:43:51 EDT 2008


Author: cmbarton
Date: 2008-08-17 01:43:51 -0400 (Sun, 17 Aug 2008)
New Revision: 32831

Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_modules/render.py
Log:
Still trying to fix bug in layering and rendering. Maybe this will do it. Took out multiple temp file creation lines that were overwriting each other. Switched tempfile creation to pure Python secure tempfile. Should work better cross-platform. If this works, maybe we should stop using g.tempfile and can drop the tempfile method in util.py

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/render.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/render.py	2008-08-17 01:44:43 UTC (rev 32830)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/render.py	2008-08-17 05:43:51 UTC (rev 32831)
@@ -30,6 +30,7 @@
     compatPath = os.path.join(globalvar.ETCWXDIR, "compat")
     sys.path.append(compatPath)
     import subprocess
+import tempfile
 
 import wx
 
@@ -80,8 +81,15 @@
                         self.opacity, self.hidden))
 
         # generated file for layer
-        self.gtemp = utils.GetTempfile()
+        #self.gtemp = utils.GetTempfile()
+        #self.gtemp = os.tmpfile()
+        #self.maskfile = self.gtemp + ".pgm"
+        self.gtemp = tempfile.mkstemp()[1]
         self.maskfile = self.gtemp + ".pgm"
+        if self.type == 'overlay':
+            self.mapfile  = self.gtemp + ".png"
+        else:
+            self.mapfile  = self.gtemp + ".ppm"
 
     def __del__(self):
         Debug.msg (3, "Layer.__del__(): layer=%s, cmd='%s'" %
@@ -106,13 +114,14 @@
         #
         # to be sure, set temporary file with layer and mask
         #
-        if not self.gtemp:
-            gtemp = utils.GetTempfile()
-            self.maskfile = gtemp + ".pgm"
-            if self.type == 'overlay':
-                self.mapfile  = gtemp + ".png"
-            else:
-                self.mapfile  = gtemp + ".ppm"
+        #if not self.gtemp:
+        #gtemp = utils.GetTempfile()
+        #gtemp = tempfile.mkstemp()[1]
+        #self.maskfile = gtemp + ".pgm"
+        #if self.type == 'overlay':
+        #    self.mapfile  = gtemp + ".png"
+        #else:
+        #    self.mapfile  = gtemp + ".ppm"
 
         #
         # prepare command for each layer
@@ -138,7 +147,7 @@
         else:
             if self.mapfile:
                 os.environ["GRASS_PNGFILE"] = self.mapfile
-
+                
         #
         # execute command
         #
@@ -274,7 +283,7 @@
         Layer.__init__(self, type, cmd, name,
                        active, hidden, opacity)
 
-        self.mapfile = self.gtemp + ".ppm"
+        #self.mapfile = self.gtemp + ".ppm"
 
     def GetMapset(self):
         """
@@ -308,7 +317,7 @@
                        active, hidden, opacity)
 
         self.id = id
-        self.mapfile = self.gtemp + ".png"
+        #self.mapfile = self.gtemp + ".png"
 
 class Map(object):
     """
@@ -838,31 +847,31 @@
                 
             Debug.msg (3, "Map.Render() type=%s, layer=%s " % (layer.type, layer.name))
 
-	# ugly hack for MSYS
-	if not subprocess.mswindows:
-	    mapstr = ",".join(maps)
-	    maskstr = ",".join(masks)
+        # ugly hack for MSYS
+        if not subprocess.mswindows:
+            mapstr = ",".join(maps)
+            maskstr = ",".join(masks)
             mapoutstr = self.mapfile
-	else:
-	    mapstr = ""
-	    for item in maps:
+        else:
+            mapstr = ""
+            for item in maps:
                 mapstr += item.replace('\\', '/')		
-	    mapstr = mapstr.rstrip(',')
-	    maskstr = ""
+            mapstr = mapstr.rstrip(',')
+            maskstr = ""
             for item in masks:
-		maskstr += item.replace('\\', '/')
-	    maskstr = maskstr.rstrip(',')
-	    mapoutstr = self.mapfile.replace('\\', '/')
+                maskstr += item.replace('\\', '/')
+            maskstr = maskstr.rstrip(',')
+            mapoutstr = self.mapfile.replace('\\', '/')
 
         # compose command
         complist = ["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]
+                    "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



More information about the grass-commit mailing list