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

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Aug 31 12:12:18 EDT 2011


Author: martinl
Date: 2011-08-31 09:12:18 -0700 (Wed, 31 Aug 2011)
New Revision: 48002

Modified:
   grass/trunk/gui/wxpython/gui_modules/gdialogs.py
   grass/trunk/gui/wxpython/gui_modules/gselect.py
Log:
wxGUI/OGR: fix 'create new empty vector map' dialog for OGR output
	   (currently without attribute table)


Modified: grass/trunk/gui/wxpython/gui_modules/gdialogs.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gdialogs.py	2011-08-31 15:37:39 UTC (rev 48001)
+++ grass/trunk/gui/wxpython/gui_modules/gdialogs.py	2011-08-31 16:12:18 UTC (rev 48002)
@@ -218,8 +218,8 @@
     
 class NewVectorDialog(ElementDialog):
     def __init__(self, parent, id = wx.ID_ANY, title = _('Create new vector map'),
-                 disableAdd = False, disableTable = False,
-                 style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, *kwargs):
+                 disableAdd = False, disableTable = False, showType = False,
+                 style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, *kwargs):
         """!Dialog for creating new vector map
 
         @param parent parent window
@@ -227,6 +227,7 @@
         @param title window title
         @param disableAdd disable 'add layer' checkbox
         @param disableTable disable 'create table' checkbox
+        @param showType True to show feature type selector (used for creating new empty OGR layers)
         @param style window style
         @param kwargs other argumentes for ElementDialog
         
@@ -237,6 +238,12 @@
         self.element = gselect.Select(parent = self.panel, id = wx.ID_ANY, size = globalvar.DIALOG_GSELECT_SIZE,
                                       type = 'vector', mapsets = [grass.gisenv()['MAPSET'],])
         
+        # determine output format
+        if showType:
+            self.ftype = gselect.OgrTypeSelect(parent = self, panel = self.panel)
+        else:
+            self.ftype = None
+        
         self.table = wx.CheckBox(parent = self.panel, id = wx.ID_ANY,
                                  label = _("Create attribute table"))
         self.table.SetValue(True)
@@ -262,10 +269,14 @@
         
     def _layout(self):
         """!Do layout"""
-        self.dataSizer.Add(self.element, proportion = 0,
+        self.dataSizer.Add(item = self.element, proportion = 0,
                       flag = wx.EXPAND | wx.ALL, border = 1)
+        if self.ftype:
+            self.dataSizer.AddSpacer(1)
+            self.dataSizer.Add(item = self.ftype, proportion = 0,
+                               flag = wx.EXPAND | wx.ALL, border = 1)
         
-        self.dataSizer.Add(self.table, proportion = 0,
+        self.dataSizer.Add(item = self.table, proportion = 0,
                       flag = wx.EXPAND | wx.ALL, border = 1)
         
         self.dataSizer.AddSpacer(5)
@@ -305,8 +316,20 @@
         
         return None
     
+    def GetFeatureType(self):
+        """!Get feature type for OGR
+
+        @return feature type as string
+        @return None for native format
+        """
+        if self.ftype:
+            return self.ftype.GetType()
+        
+        return None
+
 def CreateNewVector(parent, cmd, title = _('Create new vector map'),
-                    exceptMap = None, log = None, disableAdd = False, disableTable = False):
+                    exceptMap = None, log = None,
+                    disableAdd = False, disableTable = False):
     """!Create new vector map layer
     
     @param cmd (prog, **kwargs)
@@ -315,12 +338,19 @@
     @param log
     @param disableAdd disable 'add layer' checkbox
     @param disableTable disable 'create table' checkbox
-
+    
     @return dialog instance
     @return None on error
     """
+    vExternalOut = grass.parse_command('v.external.out', flags = 'g')
+    isNative = vExternalOut['format'] == 'native'
+    if cmd[0] == 'v.edit' and not isNative:
+        showType = True
+    else:
+        showType = False
     dlg = NewVectorDialog(parent, title = title,
-                          disableAdd = disableAdd, disableTable = disableTable)
+                          disableAdd = disableAdd, disableTable = disableTable,
+                          showType = showType)
     
     if dlg.ShowModal() == wx.ID_OK:
         outmap = dlg.GetName()
@@ -333,13 +363,21 @@
         if outmap == '': # should not happen
             dlg.Destroy()
             return None
-        
+
+        # update cmd -> output name defined
         cmd[1][cmd[2]] = outmap
+        if showType:
+            cmd[1]['type'] = dlg.GetFeatureType()
         
-        try:
+        if isNative:
             listOfVectors = grass.list_grouped('vect')[grass.gisenv()['MAPSET']]
-        except KeyError:
-            listOfVectors = []
+        else:
+            listOfVectors = gcmd.RunCommand('v.external',
+                                            quiet = True,
+                                            parent = parent,
+                                            read = True,
+                                            flags = 'l',
+                                            dsn = vExternalOut['dsn'])
         
         overwrite = False
         if not UserSettings.Get(group = 'cmd', key = 'overwrite', subkey = 'enabled') and \
@@ -359,16 +397,21 @@
         if UserSettings.Get(group = 'cmd', key = 'overwrite', subkey = 'enabled'):
             overwrite = True
         
-        try:
-            gcmd.RunCommand(prog = cmd[0],
-                            overwrite = overwrite,
-                            **cmd[1])
-        except gcmd.GException, e:
-            gcmd.GError(parent = self,
-                        message = e.value)
+        ret = gcmd.RunCommand(prog = cmd[0],
+                              parent = parent,
+                              overwrite = overwrite,
+                              **cmd[1])
+        if ret != 0:
             dlg.Destroy()
             return None
         
+        # create link for OGR layers
+        if not isNative:
+            gcmd.RunCommand('v.external',
+                            parent = parent,
+                            dsn = vExternalOut['dsn'],
+                            layer = outmap)
+        
         # create attribute table
         if dlg.table.IsEnabled() and dlg.table.IsChecked():
             key = UserSettings.Get(group = 'atm', key = 'keycolumn', subkey = 'value')

Modified: grass/trunk/gui/wxpython/gui_modules/gselect.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gselect.py	2011-08-31 15:37:39 UTC (rev 48001)
+++ grass/trunk/gui/wxpython/gui_modules/gselect.py	2011-08-31 16:12:18 UTC (rev 48002)
@@ -20,6 +20,7 @@
  - GdalSelect
  - ProjSelect
  - ElementSelect
+ - OgrTypeSelect
 
 (C) 2007-2011 by the GRASS Development Team This program is free
 software under the GNU General Public License (>=v2). Read the file
@@ -1060,9 +1061,7 @@
         
 class GdalSelect(wx.Panel):
     def __init__(self, parent, panel, ogr = False,
-                 default = 'file',
-                 exclude = [],
-                 envHandler = None):
+                 default = 'file', exclude = [], envHandler = None):
         """!Widget for selecting GDAL/OGR datasource, format
         
         @param parent parent window
@@ -1211,7 +1210,7 @@
         self.formatText = wx.StaticText(parent = self, id = wx.ID_ANY,
                                         label = _("Format:"))
         self._layout()
-        
+
     def _layout(self):
         """!Layout"""
         mainSizer = wx.BoxSizer(wx.VERTICAL)
@@ -1634,3 +1633,46 @@
         if idx > -1:
             return self.values[idx]
         return ''
+
+class OgrTypeSelect(wx.Panel):
+    def __init__(self, parent, panel, **kwargs):
+        """!Widget to choose OGR feature type
+
+        @param parent parent window
+        @param panel wx.Panel instance used as parent window
+        """
+        wx.Panel.__init__(self, parent = panel, id = wx.ID_ANY)
+        
+        self.ftype = wx.Choice(parent = self, id = wx.ID_ANY,
+                               size = (200, -1),
+                               choices = (_("Point"), _("LineString"), _("Polygon")))
+        self._layout()
+
+    def _layout(self):
+        """!Do layout"""
+        sizer = wx.BoxSizer(wx.HORIZONTAL)
+        sizer.Add(item = wx.StaticText(parent = self,
+                                       id = wx.ID_ANY,
+                                       label = _("Feature type:")),
+                  proportion = 1,
+                  flag = wx.ALIGN_CENTER_VERTICAL,
+                  border  = 5)
+        sizer.Add(item = self.ftype,
+                  proportion = 0,
+                  flag = wx.EXPAND | wx.ALIGN_RIGHT)
+        
+        self.SetSizer(sizer)
+        sizer.Fit(self)
+
+    def GetType(self):
+        """!Get selected type as string
+
+        @return feature type as string
+        """
+        sel = self.ftype.GetSelection()
+        if sel == 0:
+            return 'point'
+        elif sel == 1:
+            return 'line'
+        elif sel == 2:
+            return 'area'



More information about the grass-commit mailing list