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

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Apr 21 11:20:07 EDT 2010


Author: martinl
Date: 2010-04-21 11:20:06 -0400 (Wed, 21 Apr 2010)
New Revision: 41952

Modified:
   grass/trunk/gui/wxpython/gui_modules/gdialogs.py
Log:
wxGUI: import/link - support for sqlite


Modified: grass/trunk/gui/wxpython/gui_modules/gdialogs.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gdialogs.py	2010-04-21 13:46:02 UTC (rev 41951)
+++ grass/trunk/gui/wxpython/gui_modules/gdialogs.py	2010-04-21 15:20:06 UTC (rev 41952)
@@ -994,11 +994,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)
@@ -1024,11 +1036,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',
@@ -1245,7 +1262,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)
         
@@ -1281,7 +1300,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)
@@ -1313,7 +1332,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':
@@ -1326,10 +1348,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:
@@ -1389,31 +1412,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()
@@ -1423,7 +1461,8 @@
         path = event.GetString()
         if not path:
             return 
-        
+
+        data = list()        
         if self.importType == 'dxf':
             ret = gcmd.RunCommand('v.in.dxf',
                                   quiet = True,
@@ -1435,15 +1474,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()
@@ -1461,6 +1498,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