Browse Source

wxGUI: direct OGR read access fixes

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@42056 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 15 years ago
parent
commit
884a58edf8

+ 20 - 12
gui/wxpython/gui_modules/gcmd.py

@@ -79,19 +79,27 @@ class GMessage:
                           caption = caption,
                           caption = caption,
                           style = style)
                           style = style)
         else:
         else:
-            exception = traceback.format_exc()
-            reason = exception.split('\n')[-2].split(':', 1)[-1].strip()
-        
-            if Debug.get_level() > 0:
+            exc_type, exc_value, exc_traceback = sys.exc_info()
+            if exc_traceback:
+                exception = traceback.format_exc()
+                reason = exception.splitlines()[-2].split(':', 1)[-1].strip()
+            
+            if Debug.get_level() > 0 and exc_traceback:
                 sys.stderr.write(exception)
                 sys.stderr.write(exception)
-        
-            wx.MessageBox(parent = parent,
-                          message = message + '\n\n%s: %s\n\n%s' % \
-                              (_('Reason'),
-                               reason, exception),
-                          caption = caption,
-                          style = style)
-
+            
+            if exc_traceback:
+                wx.MessageBox(parent = parent,
+                              message = message + '\n\n%s: %s\n\n%s' % \
+                                  (_('Reason'),
+                                   reason, exception),
+                              caption = caption,
+                              style = style)
+            else:
+                wx.MessageBox(parent = parent,
+                              message = message,
+                              caption = caption,
+                              style = style)
+    
 class GError(Exception):
 class GError(Exception):
     def __init__(self, value):
     def __init__(self, value):
         self.value = value
         self.value = value

+ 16 - 6
gui/wxpython/gui_modules/gselect.py

@@ -983,18 +983,22 @@ class GdalSelect(wx.Panel):
                                                 startDirectory=os.getcwd(),
                                                 startDirectory=os.getcwd(),
                                                 changeCallback=self.OnSetDsn)
                                                 changeCallback=self.OnSetDsn)
         dsnDbFile.Hide()
         dsnDbFile.Hide()
-        
+        dsnDbFile.SetName('GdalSelect')
+
         dsnDbText = wx.TextCtrl(parent = self, id = wx.ID_ANY)
         dsnDbText = wx.TextCtrl(parent = self, id = wx.ID_ANY)
         dsnDbText.Hide()
         dsnDbText.Hide()
         dsnDbText.Bind(wx.EVT_TEXT, self.OnSetDsn)
         dsnDbText.Bind(wx.EVT_TEXT, self.OnSetDsn)
-        
+        dsnDbText.SetName('GdalSelect')
+
         dsnDbChoice = wx.Choice(parent = self, id = wx.ID_ANY)
         dsnDbChoice = wx.Choice(parent = self, id = wx.ID_ANY)
         dsnDbChoice.Hide()
         dsnDbChoice.Hide()
         dsnDbChoice.Bind(wx.EVT_CHOICE, self.OnSetDsn)
         dsnDbChoice.Bind(wx.EVT_CHOICE, self.OnSetDsn)
-        
+        dsnDbChoice.SetName('GdalSelect')
+
         dsnPro = wx.TextCtrl(parent = self, id = wx.ID_ANY)
         dsnPro = wx.TextCtrl(parent = self, id = wx.ID_ANY)
         dsnPro.Hide()
         dsnPro.Hide()
         dsnPro.Bind(wx.EVT_TEXT, self.OnSetDsn)
         dsnPro.Bind(wx.EVT_TEXT, self.OnSetDsn)
+        dsnPro.SetName('GdalSelect')
 
 
         # format
         # format
         self.format = FormatSelect(parent = self,
         self.format = FormatSelect(parent = self,
@@ -1163,7 +1167,7 @@ class GdalSelect(wx.Panel):
                 data.append((layerId, layerName.strip(), grassName.strip()))
                 data.append((layerId, layerName.strip(), grassName.strip()))
                 layerId += 1
                 layerId += 1
         
         
-        evt = wxGdalSelect(dsn = dsn)
+        evt = wxGdalSelect(dsn = dsn + '@OGR')
         evt.SetId(self.input[self.dsnType][1].GetId())
         evt.SetId(self.input[self.dsnType][1].GetId())
         wx.PostEvent(self.parent, evt)
         wx.PostEvent(self.parent, evt)
         
         
@@ -1251,8 +1255,14 @@ class GdalSelect(wx.Panel):
         return self.input[self.dsnType][1].GetValue()
         return self.input[self.dsnType][1].GetValue()
 
 
     def GetDsnWin(self):
     def GetDsnWin(self):
-        """!Get DSN windows"""
-        return self.input[self.dsnType][1]
+        """!Get list of DSN windows"""
+        win = list()
+        for stype in ('file', 'dir', 'pro'):
+            win.append(self.input[stype][1])
+        for stype in ('file', 'text', 'choice'):
+            win.append(self.input['db-win'][stype])
+        
+        return win
     
     
     def GetFormatExt(self):
     def GetFormatExt(self):
         """!Get format extension"""
         """!Get format extension"""

+ 3 - 5
gui/wxpython/gui_modules/layertree.py

@@ -46,6 +46,7 @@ from debug import Debug as Debug
 from icon import Icons as Icons
 from icon import Icons as Icons
 from preferences import globalSettings as UserSettings
 from preferences import globalSettings as UserSettings
 from vdigit import haveVDigit
 from vdigit import haveVDigit
+from gcmd import GMessage
 try:
 try:
     import subprocess
     import subprocess
 except:
 except:
@@ -1293,11 +1294,8 @@ class LayerTree(treemixin.DragAndDrop, CT.CustomTreeCtrl):
             mapname = utils.GetLayerNameFromCmd(dcmd, layerType=mapLayer.type,
             mapname = utils.GetLayerNameFromCmd(dcmd, layerType=mapLayer.type,
                                                 fullyQualified=True)
                                                 fullyQualified=True)
             if not mapname:
             if not mapname:
-                wx.MessageBox(parent=self,
-                              message=_("Map <%s> not found.") % utils.GetLayerNameFromCmd(dcmd),
-                              caption=_("Error"),
-                              style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
-
+                GMessage(parent=self,
+                         message=_("Map <%s> not found.") % utils.GetLayerNameFromCmd(dcmd))
                 return
                 return
             
             
             self.SetItemText(layer, mapname + ' (opacity: ' + str(opacity) + '%)')
             self.SetItemText(layer, mapname + ' (opacity: ' + str(opacity) + '%)')

+ 4 - 3
gui/wxpython/gui_modules/menuform.py

@@ -1431,7 +1431,8 @@ class cmdPanel(wx.Panel):
                             
                             
                             p['wxId'].append(rbox.GetId())
                             p['wxId'].append(rbox.GetId())
                             p['wxId'].append(ogrSelection.GetId())
                             p['wxId'].append(ogrSelection.GetId())
-                            p['wxId'].append(ogrSelection.GetDsnWin().GetId())
+                            for win in ogrSelection.GetDsnWin():
+                                p['wxId'].append(win.GetId())
                         else:
                         else:
                             which_sizer.Add(item=selection, proportion=0,
                             which_sizer.Add(item=selection, proportion=0,
                                             flag=wx.ADJUST_MINSIZE | wx.BOTTOM | wx.LEFT | wx.RIGHT | wx.TOP | wx.ALIGN_CENTER_VERTICAL,
                                             flag=wx.ADJUST_MINSIZE | wx.BOTTOM | wx.LEFT | wx.RIGHT | wx.TOP | wx.ALIGN_CENTER_VERTICAL,
@@ -1889,11 +1890,11 @@ class cmdPanel(wx.Panel):
                 if found:
                 if found:
                     if name in ('LayerSelect', 'DriverSelect', 'TableSelect'):
                     if name in ('LayerSelect', 'DriverSelect', 'TableSelect'):
                         porf['value'] = me.GetStringSelection()
                         porf['value'] = me.GetStringSelection()
+                    elif name == 'GdalSelect':
+                        porf['value'] = event.dsn
                     else:
                     else:
                         porf['value'] = me.GetValue()
                         porf['value'] = me.GetValue()
                     
                     
-                    if name == 'GdalSelect':
-                        porf['value'] += '@OGR'
                   
                   
         self.OnUpdateValues()
         self.OnUpdateValues()
         
         

+ 3 - 3
gui/wxpython/gui_modules/utils.py

@@ -98,7 +98,7 @@ def GetLayerNameFromCmd(dcmd, fullyQualified=False, param=None,
         params = list()
         params = list()
         for idx in range(len(dcmd)):
         for idx in range(len(dcmd)):
             try:
             try:
-                p, v = dcmd[idx].split('=')
+                p, v = dcmd[idx].split('=', 1)
             except ValueError:
             except ValueError:
                 continue
                 continue
             
             
@@ -111,7 +111,7 @@ def GetLayerNameFromCmd(dcmd, fullyQualified=False, param=None,
                      'h_map', 's_map', 'i_map',
                      'h_map', 's_map', 'i_map',
                      'reliefmap'):
                      'reliefmap'):
                 params.append((idx, p, v))
                 params.append((idx, p, v))
-            
+        
         if len(params) < 1:
         if len(params) < 1:
             return mapname
             return mapname
             
             
@@ -147,7 +147,7 @@ def GetLayerNameFromCmd(dcmd, fullyQualified=False, param=None,
                 ogr = True
                 ogr = True
             if p == 'layer' and not ogr:
             if p == 'layer' and not ogr:
                 continue
                 continue
-            maps.append(dcmd[i].split('=')[1])
+            maps.append(dcmd[i].split('=', 1)[1])
         mapname = '\n'.join(maps)
         mapname = '\n'.join(maps)
     
     
     return mapname
     return mapname