[GRASS-SVN] r42165 - grass/trunk/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Sat May 8 14:48:10 EDT 2010


Author: martinl
Date: 2010-05-08 14:48:09 -0400 (Sat, 08 May 2010)
New Revision: 42165

Modified:
   grass/trunk/gui/wxpython/gui_modules/globalvar.py
   grass/trunk/gui/wxpython/gui_modules/gselect.py
   grass/trunk/gui/wxpython/gui_modules/utils.py
Log:
wxGUI: get gdal formats on request


Modified: grass/trunk/gui/wxpython/gui_modules/globalvar.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/globalvar.py	2010-05-08 17:41:19 UTC (rev 42164)
+++ grass/trunk/gui/wxpython/gui_modules/globalvar.py	2010-05-08 18:48:09 UTC (rev 42165)
@@ -158,59 +158,3 @@
     have_mlist = True
 else:
     have_mlist = False
-
-def _getGDALFormats():
-    """!Get dictionary of avaialble GDAL drivers"""
-    if not grass.find_program('r.in.gdal'):
-        return _parseFormats(None)
-    
-    ret = grass.read_command('r.in.gdal',
-                             quiet = True,
-                             flags = 'f')
-    
-    return _parseFormats(ret)
-
-def _getOGRFormats():
-    """!Get dictionary of avaialble OGR drivers"""
-    if not grass.find_program('v.in.ogr'):
-        return _parseFormats(None)
-    
-    ret = grass.read_command('v.in.ogr',
-                             quiet = True,
-                             flags = 'f')
-    
-    return _parseFormats(ret)
-
-def _parseFormats(output):
-    """!Parse r.in.gdal/v.in.ogr -f output"""
-    formats = { 'file'     : list(),
-                'database' : list(),
-                'protocol' : list()
-                }
-    
-    if not output:
-        return formats
-    
-    for line in output.splitlines():
-        format = line.strip().rsplit(':', -1)[1].strip()
-        if format in ('Memory', 'Virtual Raster', 'In Memory Raster'):
-            continue
-        if format in ('PostgreSQL', 'SQLite',
-                      'ODBC', 'ESRI Personal GeoDatabase',
-                      'Rasterlite',
-                      'PostGIS WKT Raster driver'):
-            formats['database'].append(format)
-        elif format in ('GeoJSON',
-                        'OGC Web Coverage Service',
-                        'OGC Web Map Service',
-                        'HTTP Fetching Wrapper'):
-            formats['protocol'].append(format)
-        else:
-            formats['file'].append(format)
-
-    return formats
-
-formats = {
-    'gdal' : _getGDALFormats(),
-    'ogr' : _getOGRFormats()
-    }

Modified: grass/trunk/gui/wxpython/gui_modules/gselect.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gselect.py	2010-05-08 17:41:19 UTC (rev 42164)
+++ grass/trunk/gui/wxpython/gui_modules/gselect.py	2010-05-08 18:48:09 UTC (rev 42165)
@@ -831,7 +831,7 @@
             ftype = 'gdal'
         
         formats = list()
-        for f in globalvar.formats[ftype].values():
+        for f in utils.GetFormats()[ftype].values():
             formats += f
         self.SetItems(formats)
         
@@ -1011,16 +1011,16 @@
             fType = 'gdal'
         self.input = { 'file' : [_("File:"),
                                  dsnFile,
-                                 globalvar.formats[fType]['file']],
+                                 utils.GetFormats()[fType]['file']],
                        'dir'  : [_("Directory:"),
                                  dsnDir,
-                                 globalvar.formats[fType]['file']],
+                                 utils.GetFormats()[fType]['file']],
                        'db'   : [_("Database:"),
                                  dsnDbFile,
-                                 globalvar.formats[fType]['database']],
+                                 utils.GetFormats()[fType]['database']],
                        'pro'  : [_("Protocol:"),
                                  dsnPro,
-                                 globalvar.formats[fType]['protocol']],
+                                 utils.GetFormats()[fType]['protocol']],
                        'db-win' : { 'file'   : dsnDbFile,
                                     'text'   : dsnDbText,
                                     'choice' : dsnDbChoice },

Modified: grass/trunk/gui/wxpython/gui_modules/utils.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/utils.py	2010-05-08 17:41:19 UTC (rev 42164)
+++ grass/trunk/gui/wxpython/gui_modules/utils.py	2010-05-08 18:48:09 UTC (rev 42165)
@@ -648,3 +648,67 @@
         return unicode(string, enc)
     
     return string
+
+def _getGDALFormats():
+    """!Get dictionary of avaialble GDAL drivers"""
+    if not grass.find_program('r.in.gdal'):
+        return _parseFormats(None)
+    
+    ret = grass.read_command('r.in.gdal',
+                             quiet = True,
+                             flags = 'f')
+    
+    return _parseFormats(ret)
+
+def _getOGRFormats():
+    """!Get dictionary of avaialble OGR drivers"""
+    if not grass.find_program('v.in.ogr'):
+        return _parseFormats(None)
+    
+    ret = grass.read_command('v.in.ogr',
+                             quiet = True,
+                             flags = 'f')
+    
+    return _parseFormats(ret)
+
+def _parseFormats(output):
+    """!Parse r.in.gdal/v.in.ogr -f output"""
+    formats = { 'file'     : list(),
+                'database' : list(),
+                'protocol' : list()
+                }
+    
+    if not output:
+        return formats
+    
+    for line in output.splitlines():
+        format = line.strip().rsplit(':', -1)[1].strip()
+        if format in ('Memory', 'Virtual Raster', 'In Memory Raster'):
+            continue
+        if format in ('PostgreSQL', 'SQLite',
+                      'ODBC', 'ESRI Personal GeoDatabase',
+                      'Rasterlite',
+                      'PostGIS WKT Raster driver'):
+            formats['database'].append(format)
+        elif format in ('GeoJSON',
+                        'OGC Web Coverage Service',
+                        'OGC Web Map Service',
+                        'HTTP Fetching Wrapper'):
+            formats['protocol'].append(format)
+        else:
+            formats['file'].append(format)
+
+    return formats
+
+formats = None
+
+def GetFormats():
+    """!Get GDAL/OGR formats"""
+    global formats
+    if not formats:
+        formats = {
+            'gdal' : _getGDALFormats(),
+            'ogr' : _getOGRFormats()
+            }
+    
+    return formats



More information about the grass-commit mailing list