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

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Apr 21 11:27:36 EDT 2010


Author: martinl
Date: 2010-04-21 11:27:36 -0400 (Wed, 21 Apr 2010)
New Revision: 41953

Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py
Log:
wxGUI: import/link - support for sqlite
(merge r41952 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-21 15:20:06 UTC (rev 41952)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py	2010-04-21 15:27:36 UTC (rev 41953)
@@ -993,11 +993,23 @@
                                                   startDirectory=os.getcwd(),
                                                   changeCallback=self.OnSetInput)
             inputDir.Hide()
+
+            inputDbFile = filebrowse.FileBrowseButton(parent=self.panel, id=wx.ID_ANY, 
+                                                      size=globalvar.DIALOG_GSELECT_SIZE, labelText='',
+                                                      dialogTitle=_('Choose file'),
+                                                      buttonText=_('Browse'),
+                                                      startDirectory=os.getcwd(),
+                                                      changeCallback=self.OnSetInput)
+            inputDbFile.Hide()
             
-            inputDb = wx.TextCtrl(parent = self.panel, id = wx.ID_ANY)
-            inputDb.Hide()
-            inputDb.Bind(wx.EVT_TEXT, self.OnSetInput)
+            inputDbText = wx.TextCtrl(parent = self.panel, id = wx.ID_ANY)
+            inputDbText.Hide()
+            inputDbText.Bind(wx.EVT_TEXT, self.OnSetInput)
 
+            inputDbChoice = wx.Choice(parent = self.panel, id = wx.ID_ANY)
+            inputDbChoice.Hide()
+            inputDbChoice.Bind(wx.EVT_CHOICE, self.OnSetInput)
+            
             inputPro = wx.TextCtrl(parent = self.panel, id = wx.ID_ANY)
             inputPro.Hide()
             inputPro.Bind(wx.EVT_TEXT, self.OnSetInput)
@@ -1023,11 +1035,16 @@
                                      inputDir,
                                      list()],
                            'db'   : [_("Database:"),
-                                     inputDb,
+                                     inputDbFile,
                                      list()],
                            'pro'  : [_("Protocol:"),
                                      inputPro,
-                                     list()] }
+                                     list()],
+                           'db-win' : { 'file'   : inputDbFile,
+                                        'text'   : inputDbText,
+                                        'choice' : inputDbChoice },
+                           }
+            
             self.formatToExt = {
                 # raster
                 'GeoTIFF' : 'tif',
@@ -1244,7 +1261,9 @@
         
         self.Layout()
         # auto-layout seems not work here - FIXME
-        self.SetMinSize((globalvar.DIALOG_GSELECT_SIZE[0] + 175, 400))
+        size = wx.Size(globalvar.DIALOG_GSELECT_SIZE[0] + 175, 400)
+        self.SetMinSize(size)
+        self.SetSize((size.width, size.height + 100))
         width = self.GetSize()[0]
         self.list.SetColumnWidth(col=1, width=width/2 - 50)
         
@@ -1280,7 +1299,7 @@
             self.inputType = 'db'
         elif sel == 3: # protocol
             self.inputType = 'pro'
-            
+        
         win = self.input[self.inputType][1]
         self.inputTypeSizer.Add(item = win, proportion = 1,
                                 flag = wx.ALIGN_CENTER_VERTICAL)
@@ -1312,7 +1331,10 @@
                 dsn = os.path.dirname(self.input[self.inputType][1].GetValue())
             else:
                 dsn = self.input[self.inputType][1].GetValue()
-            ext = self.formatToExt[self.format.GetStringSelection()]
+            try:
+                ext = '.' + self.formatToExt[self.format.GetStringSelection()]
+            except KeyError:
+                ext = ''
         
         for layer, output in data:
             if self.importType == 'dxf':
@@ -1325,10 +1347,11 @@
                     cmd = ['v.external',
                            'dsn=%s' % dsn,
                            'output=%s' % output,
-                           'layer=%s' % layer.rstrip('.' + ext)]
+                           'layer=%s' % layer.rstrip(ext)]
                 else:
                     cmd = ['v.in.ogr',
-                           'dsn=%s' % (os.path.join(dsn, layer)),
+                           'dsn=%s' % dsn,
+                           'layer=%s' % layer.rstrip(ext),
                            'output=%s' % output]
             else: # gdal
                 if self.link:
@@ -1388,31 +1411,46 @@
         
     def OnSetFormat(self, event):
         """!Format changed"""
-        if self.inputType != 'file':
+        if self.inputType not in ['file', 'db']:
             return
         
         win = self.input[self.inputType][1]
         self.inputTypeSizer.Remove(win)
-        win.Destroy()
         
+        if self.inputType == 'file':
+            win.Destroy()
+        else: # database
+            win.Hide()
+        
         format = event.GetString()
-        try:
-            ext = self.formatToExt[format]
-            if not ext:
-                raise KeyError
-            format += ' (*.%s)|*.%s' % (ext, ext)
-        except KeyError:
-            format += ' (*.*)|*.*'
+        
+        if self.inputType == 'file':
+            try:
+                ext = self.formatToExt[format]
+                if not ext:
+                    raise KeyError
+                format += ' (*.%s)|*.%s' % (ext, ext)
+            except KeyError:
+                format += ' (*.*)|*.*'
             
-        win = filebrowse.FileBrowseButton(parent=self.panel, id=wx.ID_ANY, 
-                                          size=globalvar.DIALOG_GSELECT_SIZE, labelText='',
-                                          dialogTitle=_('Choose file'),
-                                          buttonText=_('Browse'),
-                                          startDirectory=os.getcwd(),
-                                          changeCallback=self.OnSetInput,
-                                          fileMask = format)
+            win = filebrowse.FileBrowseButton(parent=self.panel, id=wx.ID_ANY, 
+                                              size=globalvar.DIALOG_GSELECT_SIZE, labelText='',
+                                              dialogTitle=_('Choose file'),
+                                              buttonText=_('Browse'),
+                                              startDirectory=os.getcwd(),
+                                              changeCallback=self.OnSetInput,
+                                              fileMask = format)
+        else: # database
+            if format == 'SQLite':
+                win = self.input['db-win']['file']
+            elif format == 'PostgreSQL':
+                win = self.input['db-win']['choice']
+            else:
+                win = self.input['db-win']['text']
         
         self.input[self.inputType][1] = win
+        if not win.IsShown():
+            win.Show()
         self.inputTypeSizer.Add(item = win, proportion = 1,
                                 flag = wx.ALIGN_CENTER_VERTICAL)
         self.inputTypeSizer.Layout()
@@ -1422,7 +1460,8 @@
         path = event.GetString()
         if not path:
             return 
-        
+
+        data = list()        
         if self.importType == 'dxf':
             ret = gcmd.RunCommand('v.in.dxf',
                                   quiet = True,
@@ -1434,15 +1473,13 @@
                 self.list.LoadData()
                 self.btn_run.Enable(False)
                 return
-
-        data = list()
-        if self.importType == 'dxf':
+            
             for line in ret.splitlines():
                 layerId = line.split(':')[0].split(' ')[1]
                 layerName = line.split(':')[1].strip()
                 grassName = utils.GetValidLayerName(layerName)
                 data.append((layerId, layerName.strip(), grassName.strip()))
-                
+        
         else: # gdal/ogr (for ogr maybe to use v.in.ogr -l)
             layerId = 1
             dsn = self.input[self.inputType][1].GetValue()
@@ -1460,6 +1497,25 @@
                     grassName = utils.GetValidLayerName(baseName.split('.', -1)[0])
                     data.append((layerId, baseName, grassName))
                     layerId += 1
+            elif self.inputType == 'db':
+                format = self.format.GetStringSelection()
+                if format == 'SQLite':
+                    ret = gcmd.RunCommand('v.in.ogr',
+                                          quiet = True,
+                                          parent = self,
+                                          read = True,
+                                          flags = 'l',
+                                          dsn = dsn)
+                    if not ret:
+                        self.list.LoadData()
+                        self.btn_run.Enable(False)
+                        return
+                    layerId = 1
+                    for line in ret.splitlines():
+                        layerName = line.strip()
+                        grassName = utils.GetValidLayerName(layerName)
+                        data.append((layerId, layerName.strip(), grassName.strip()))
+                        layerId += 1
         
         self.list.LoadData(data)
         if len(data) > 0:



More information about the grass-commit mailing list