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

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Apr 24 18:35:15 EDT 2010


Author: martinl
Date: 2010-04-24 18:35:15 -0400 (Sat, 24 Apr 2010)
New Revision: 42023

Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/globalvar.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/gselect.py
Log:
wxGUI: gselect.FormatSelect class added
(merge from r42022 from trunk)


Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py	2010-04-24 22:27:37 UTC (rev 42022)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py	2010-04-24 22:35:15 UTC (rev 42023)
@@ -1018,119 +1018,28 @@
 
             # format widget
             self.formatText = wx.StaticText(self.panel, id=wx.ID_ANY, label=_("Format:"))
-            self.format = wx.Choice(parent = self.panel, id = wx.ID_ANY, size=(300, -1))
+            self.format = gselect.FormatSelect(parent = self.panel,
+                                               ftype = self.importType)
             self.format.Bind(wx.EVT_CHOICE, self.OnSetFormat)
-
-            if self.importType == 'gdal': 
-                ret = gcmd.RunCommand('r.in.gdal',
-                                      quiet = True, read = True,
-                                      flags = 'f')
-            else: # ogr
-                ret = gcmd.RunCommand('v.in.ogr',
-                                      quiet = True, read = True,
-                                      flags = 'f')
             
             self.input = { 'file' : [_("File:"),
                                      inputFile,
-                                     list()],
+                                     globalvar.formats[self.importType]['file']],
                            'dir'  : [_("Directory:"),
                                      inputDir,
-                                     list()],
+                                     globalvar.formats[self.importType]['file']],
                            'db'   : [_("Database:"),
                                      inputDbFile,
-                                     list()],
+                                     globalvar.formats[self.importType]['database']],
                            'pro'  : [_("Protocol:"),
                                      inputPro,
-                                     list()],
+                                     globalvar.formats[self.importType]['protocol']],
                            'db-win' : { 'file'   : inputDbFile,
                                         'text'   : inputDbText,
                                         'choice' : inputDbChoice },
                            }
             
-            self.formatToExt = {
-                # raster
-                'GeoTIFF' : 'tif',
-                'Erdas Imagine Images (.img)' : '.img',
-                'Ground-based SAR Applications Testbed File Format (.gff)' : '.gff',
-                'Arc/Info Binary Grid' : 'adf',
-                'Portable Network Graphics' : 'png',
-                'JPEG JFIF' : 'jpg',
-                'Japanese DEM (.mem)' : 'mem',
-                'Graphics Interchange Format (.gif)' : 'gif',
-                'X11 PixMap Format' : 'xpm',
-                'MS Windows Device Independent Bitmap' : 'bmp',
-                'SPOT DIMAP' : '.dim',
-                'RadarSat 2 XML Product' : 'xml',
-                'EarthWatch .TIL' : '.til',
-                'ERMapper .ers Labelled' : '.ers',
-                'ERMapper Compressed Wavelets' : 'ecw',
-                'GRIdded Binary (.grb)' : 'grb',
-                'EUMETSAT Archive native (.nat)' : '.nat',
-                'Idrisi Raster A.1' : 'rst',
-                'Golden Software ASCII Grid (.grd)' : '.grd',
-                'Golden Software Binary Grid (.grd)' : 'grd',
-                'Golden Software 7 Binary Grid (.grd)' : 'grd',
-                'R Object Data Store' : 'r',
-                'USGS DOQ (Old Style)' : 'doq',
-                'USGS DOQ (New Style)' : 'doq',
-                'ENVI .hdr Labelled' : 'hdr',
-                'ESRI .hdr Labelled' : 'hdr',
-                'Generic Binary (.hdr Labelled)' : 'hdr',
-                'PCI .aux Labelled' : 'aux',
-                'EOSAT FAST Format' : 'fst',
-                'VTP .bt (Binary Terrain) 1.3 Format' : 'bt',
-                'FARSITE v.4 Landscape File (.lcp)' : 'lcp',
-                'Swedish Grid RIK (.rik)' : 'rik',
-                'USGS Optional ASCII DEM (and CDED)' : '.dem',
-                'Northwood Numeric Grid Format .grd/.tab' : '',
-                'Northwood Classified Grid Format .grc/.tab' : '',
-                'ARC Digitized Raster Graphics' : 'arc',
-                'Magellan topo (.blx)' : 'blx',
-                'SAGA GIS Binary Grid (.sdat)' : 'sdat',
-                # vector
-                'ESRI Shapefile' : 'shp',
-                'UK .NTF'        : 'ntf',
-                'SDTS'           : 'ddf',
-                'DGN'            : 'dgn',
-                'VRT'            : 'vrt',
-                'REC'            : 'rec',
-                'BNA'            : 'bna',
-                'CSV'            : 'csv',
-                'GML'            : 'gml',
-                'GPX'            : 'gpx',
-                'KML'            : 'kml',
-                'GMT'            : 'gmt',
-                'PGeo'           : 'mdb',
-                'XPlane'         : 'dat',
-                'AVCBin'         : 'adf',
-                'AVCE00'         : 'e00',
-                'DXF'            : 'dxf',
-                'Geoconcept'     : 'gxt',
-                'GeoRSS'         : 'xml',
-                'GPSTrackMaker'  : 'gtm',
-                'VFK'            : 'vfk' }
-            
-            if ret:
-                for line in ret.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'):
-                        self.input['db'][2].append(format)
-                    elif format in ('GeoJSON',
-                                    'OGC Web Coverage Service',
-                                    'OGC Web Map Service',
-                                    'HTTP Fetching Wrapper'):
-                        self.input['pro'][2].append(format)
-                    else:
-                        self.input['file'][2].append(format)
-                        self.input['dir'][2].append(format)
-            
             self.inputType = 'file'
-            
             self.format.SetItems(self.input[self.inputType][2])
             
             if self.importType == 'gdal':
@@ -1280,7 +1189,7 @@
             self.inputType = 'file'
             format = self.input[self.inputType][2][0]
             try:
-                ext = self.formatToExt[format]
+                ext = self.format.GetExtension(format)
                 if not ext:
                     raise KeyError
                 format += ' (*.%s)|*.%s' % (ext, ext)
@@ -1337,7 +1246,7 @@
                 else:
                     dsn = self.input[self.inputType][1].GetValue()
             try:
-                ext = '.' + self.formatToExt[self.format.GetStringSelection()]
+                ext = '.' + self.format.GetExtension(self.format.GetStringSelection())
             except KeyError:
                 ext = ''
         
@@ -1441,7 +1350,7 @@
         
         if self.inputType == 'file':
             try:
-                ext = self.formatToExt[format]
+                ext = self.format.GetExtension(format)
                 if not ext:
                     raise KeyError
                 format += ' (*.%s)|*.%s' % (ext, ext)
@@ -1523,7 +1432,7 @@
                 data.append((layerId, baseName, grassName))
             elif self.inputType == 'dir':
                 try:
-                    ext = self.formatToExt[self.format.GetStringSelection()]
+                    ext = self.format.GetExtension(self.format.GetStringSelection())
                 except KeyError:
                     ext = ''
                 for file in glob.glob(os.path.join(dsn, "*.%s") % ext):

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/globalvar.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/globalvar.py	2010-04-24 22:27:37 UTC (rev 42022)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/globalvar.py	2010-04-24 22:35:15 UTC (rev 42023)
@@ -6,11 +6,10 @@
 This module provide the space for global variables
 used in the code.
 
-(C) 2007-2009 by the GRASS Development Team
+(C) 2007-2010 by the GRASS Development Team
 
-This program is free software under the GNU General Public
-License (>=v2). Read the file COPYING that comes with GRASS
-for details.
+This program is free software under the GNU General Public License
+(>=v2). Read the file COPYING that comes with GRASS for details.
 
 @author Martin Landa <landa.martin gmail.com>
 """
@@ -23,6 +22,8 @@
 import gettext
 gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode=True)
 
+import grass.script as grass
+
 # wxversion.select() called once at the beginning
 check = True
 
@@ -156,3 +157,53 @@
     have_mlist = True
 else:
     have_mlist = False
+
+def _getGDALFormats():
+    """!Get dictionary of avaialble GDAL drivers"""
+    ret = grass.read_command('r.in.gdal',
+                             quiet = True,
+                             flags = 'f')
+    
+    return _parseFormats(ret)
+
+def _getOGRFormats():
+    """!Get dictionary of avaialble OGR drivers"""
+    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/branches/develbranch_6/gui/wxpython/gui_modules/gselect.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/gselect.py	2010-04-24 22:27:37 UTC (rev 42022)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/gselect.py	2010-04-24 22:35:15 UTC (rev 42023)
@@ -15,6 +15,7 @@
  - LocationSelect
  - MapsetSelect
  - SubGroupSelect
+ - FormatSelect
 
 (C) 2007-2010 by the GRASS Development Team This program is free
 software under the GNU General Public License (>=v2). Read the file
@@ -762,3 +763,93 @@
         except OSError:
             self.SetItems([])
         self.SetValue('')
+
+class FormatSelect(wx.Choice):
+    def __init__(self, parent, ftype, sourceType = None, id = wx.ID_ANY, size = globalvar.DIALOG_COMBOBOX_SIZE, 
+                 **kwargs):
+        """!Widget for selecting external (GDAL/OGR) format
+
+        @param parent parent window
+        @param sourceType source type ('file', 'directory', 'database', 'protocol') or None
+        @param dataType data type ('gdal' or 'ogr')
+        """
+        super(FormatSelect, self).__init__(parent, id, size = size, 
+                                           style = wx.CB_READONLY, **kwargs)
+        self.SetName("FormatSelect")
+
+        formats = list()
+        for f in globalvar.formats[ftype].values():
+            formats += f
+        self.SetItems(formats)
+        
+    def GetExtension(self, name):
+        """!Get file extension by format name"""
+        formatToExt = {
+            # raster
+            'GeoTIFF' : 'tif',
+            'Erdas Imagine Images (.img)' : '.img',
+            'Ground-based SAR Applications Testbed File Format (.gff)' : '.gff',
+            'Arc/Info Binary Grid' : 'adf',
+            'Portable Network Graphics' : 'png',
+            'JPEG JFIF' : 'jpg',
+            'Japanese DEM (.mem)' : 'mem',
+            'Graphics Interchange Format (.gif)' : 'gif',
+            'X11 PixMap Format' : 'xpm',
+            'MS Windows Device Independent Bitmap' : 'bmp',
+            'SPOT DIMAP' : '.dim',
+            'RadarSat 2 XML Product' : 'xml',
+            'EarthWatch .TIL' : '.til',
+            'ERMapper .ers Labelled' : '.ers',
+            'ERMapper Compressed Wavelets' : 'ecw',
+            'GRIdded Binary (.grb)' : 'grb',
+            'EUMETSAT Archive native (.nat)' : '.nat',
+            'Idrisi Raster A.1' : 'rst',
+            'Golden Software ASCII Grid (.grd)' : '.grd',
+            'Golden Software Binary Grid (.grd)' : 'grd',
+            'Golden Software 7 Binary Grid (.grd)' : 'grd',
+            'R Object Data Store' : 'r',
+            'USGS DOQ (Old Style)' : 'doq',
+            'USGS DOQ (New Style)' : 'doq',
+            'ENVI .hdr Labelled' : 'hdr',
+            'ESRI .hdr Labelled' : 'hdr',
+            'Generic Binary (.hdr Labelled)' : 'hdr',
+            'PCI .aux Labelled' : 'aux',
+            'EOSAT FAST Format' : 'fst',
+            'VTP .bt (Binary Terrain) 1.3 Format' : 'bt',
+            'FARSITE v.4 Landscape File (.lcp)' : 'lcp',
+            'Swedish Grid RIK (.rik)' : 'rik',
+            'USGS Optional ASCII DEM (and CDED)' : '.dem',
+            'Northwood Numeric Grid Format .grd/.tab' : '',
+            'Northwood Classified Grid Format .grc/.tab' : '',
+            'ARC Digitized Raster Graphics' : 'arc',
+            'Magellan topo (.blx)' : 'blx',
+            'SAGA GIS Binary Grid (.sdat)' : 'sdat',
+            # vector
+            'ESRI Shapefile' : 'shp',
+            'UK .NTF'        : 'ntf',
+            'SDTS'           : 'ddf',
+            'DGN'            : 'dgn',
+            'VRT'            : 'vrt',
+            'REC'            : 'rec',
+            'BNA'            : 'bna',
+            'CSV'            : 'csv',
+            'GML'            : 'gml',
+            'GPX'            : 'gpx',
+            'KML'            : 'kml',
+            'GMT'            : 'gmt',
+            'PGeo'           : 'mdb',
+            'XPlane'         : 'dat',
+            'AVCBin'         : 'adf',
+            'AVCE00'         : 'e00',
+            'DXF'            : 'dxf',
+            'Geoconcept'     : 'gxt',
+            'GeoRSS'         : 'xml',
+            'GPSTrackMaker'  : 'gtm',
+            'VFK'            : 'vfk'
+            }
+        
+        try:
+            return formatToExt[name]
+        except KeyError:
+            return ''
+        



More information about the grass-commit mailing list