|
@@ -970,7 +970,7 @@ class SubGroupSelect(wx.ComboBox):
|
|
|
|
|
|
class FormatSelect(wx.Choice):
|
|
|
def __init__(self, parent, ogr = False,
|
|
|
- sourceType = None, id = wx.ID_ANY, size = globalvar.DIALOG_COMBOBOX_SIZE,
|
|
|
+ sourceType = None, id = wx.ID_ANY, size = globalvar.DIALOG_SPIN_SIZE,
|
|
|
**kwargs):
|
|
|
"""!Widget for selecting external (GDAL/OGR) format
|
|
|
|
|
@@ -1064,30 +1064,42 @@ class FormatSelect(wx.Choice):
|
|
|
return ''
|
|
|
|
|
|
class GdalSelect(wx.Panel):
|
|
|
- def __init__(self, parent, panel, ogr = False,
|
|
|
+ def __init__(self, parent, panel, ogr = False, dest = False,
|
|
|
default = 'file', exclude = [], envHandler = None):
|
|
|
"""!Widget for selecting GDAL/OGR datasource, format
|
|
|
|
|
|
@param parent parent window
|
|
|
@param ogr use OGR selector instead of GDAL
|
|
|
+ @param dest True for output (destination)
|
|
|
+ @param default deafult type (ignored when dest == True)
|
|
|
+ @param exclude list of types to be excluded
|
|
|
"""
|
|
|
self.parent = parent
|
|
|
self.ogr = ogr
|
|
|
+ self.dest = dest
|
|
|
wx.Panel.__init__(self, parent = panel, id = wx.ID_ANY)
|
|
|
|
|
|
- self.settingsBox = wx.StaticBox(parent = self, id=wx.ID_ANY,
|
|
|
- label=" %s " % _("Settings"))
|
|
|
+ self.settingsBox = wx.StaticBox(parent = self, id = wx.ID_ANY,
|
|
|
+ label = " %s " % _("Settings"))
|
|
|
|
|
|
- self.inputBox = wx.StaticBox(parent = self, id=wx.ID_ANY,
|
|
|
- label=" %s " % _("Source"))
|
|
|
+ self.inputBox = wx.StaticBox(parent = self, id = wx.ID_ANY)
|
|
|
+ if dest:
|
|
|
+ self.inputBox.SetLabel(" %s " % _("Output settings"))
|
|
|
+ else:
|
|
|
+ self.inputBox.SetLabel(" %s " % _("Source settings"))
|
|
|
|
|
|
# source type
|
|
|
sources = list()
|
|
|
self.sourceMap = { 'file' : -1,
|
|
|
'dir' : -1,
|
|
|
'db' : -1,
|
|
|
- 'pro' : -1 }
|
|
|
+ 'pro' : -1,
|
|
|
+ 'native' : -1 }
|
|
|
idx = 0
|
|
|
+ if dest:
|
|
|
+ sources.append(_("Native"))
|
|
|
+ self.sourceMap['native'] = idx
|
|
|
+ idx += 1
|
|
|
if 'file' not in exclude:
|
|
|
sources.append(_("File"))
|
|
|
self.sourceMap['file'] = idx
|
|
@@ -1117,9 +1129,13 @@ class GdalSelect(wx.Panel):
|
|
|
self.btnSettings.Bind(wx.EVT_BUTTON, self.OnSettingsSave)
|
|
|
|
|
|
self.source = wx.RadioBox(parent = self, id = wx.ID_ANY,
|
|
|
- label = _('Source type'),
|
|
|
style = wx.RA_SPECIFY_COLS,
|
|
|
choices = sources)
|
|
|
+ if dest:
|
|
|
+ self.source.SetLabel(" %s " % _('Output type'))
|
|
|
+ else:
|
|
|
+ self.source.SetLabel(" %s " % _('Source type'))
|
|
|
+
|
|
|
self.source.SetSelection(0)
|
|
|
self.source.Bind(wx.EVT_RADIOBOX, self.OnSetType)
|
|
|
|
|
@@ -1187,24 +1203,35 @@ class GdalSelect(wx.Panel):
|
|
|
fType = 'gdal'
|
|
|
self.input = { 'file' : [_("File:"),
|
|
|
dsnFile,
|
|
|
- utils.GetFormats()[fType]['file']],
|
|
|
- 'dir' : [_("Directory:"),
|
|
|
+ utils.GetFormats(writableOnly = dest)[fType]['file']],
|
|
|
+ 'dir' : [_("Name:"),
|
|
|
dsnDir,
|
|
|
- utils.GetFormats()[fType]['file']],
|
|
|
- 'db' : [_("Database:"),
|
|
|
- dsnDbFile,
|
|
|
- utils.GetFormats()[fType]['database']],
|
|
|
+ utils.GetFormats(writableOnly = dest)[fType]['file']],
|
|
|
+ 'db' : [_("Name:"),
|
|
|
+ dsnDbText,
|
|
|
+ utils.GetFormats(writableOnly = dest)[fType]['database']],
|
|
|
'pro' : [_("Protocol:"),
|
|
|
dsnPro,
|
|
|
- utils.GetFormats()[fType]['protocol']],
|
|
|
+ utils.GetFormats(writableOnly = dest)[fType]['protocol']],
|
|
|
'db-win' : { 'file' : dsnDbFile,
|
|
|
'text' : dsnDbText,
|
|
|
'choice' : dsnDbChoice },
|
|
|
+ 'native' : [_("Name:"), dsnDir, ''],
|
|
|
}
|
|
|
|
|
|
- self.dsnType = default
|
|
|
- self.input[self.dsnType][1].Show()
|
|
|
- self.format.SetItems(self.input[self.dsnType][2])
|
|
|
+ if self.dest:
|
|
|
+ current = gcmd.RunCommand('v.external.out',
|
|
|
+ parent = self,
|
|
|
+ read = True, parse = grass.parse_key_val,
|
|
|
+ flags = 'g')
|
|
|
+ if current['format'] == 'native':
|
|
|
+ self.dsnType = 'native'
|
|
|
+ elif current['format'] in utils.GetFormats()['ogr']['database']:
|
|
|
+ self.dsnType = 'db'
|
|
|
+ else:
|
|
|
+ self.dsnType = 'dir'
|
|
|
+ else:
|
|
|
+ self.dsnType = default
|
|
|
|
|
|
self.dsnText = wx.StaticText(parent = self, id = wx.ID_ANY,
|
|
|
label = self.input[self.dsnType][0],
|
|
@@ -1213,12 +1240,23 @@ class GdalSelect(wx.Panel):
|
|
|
label = _("Extension:"))
|
|
|
self.extensionText.Hide()
|
|
|
|
|
|
+ self.creationOpt = wx.TextCtrl(parent = self, id = wx.ID_ANY)
|
|
|
+ if not self.dest:
|
|
|
+ self.creationOpt.Hide()
|
|
|
+
|
|
|
self._layout()
|
|
|
-
|
|
|
- if not ogr:
|
|
|
- self.OnSetFormat(event = None, format = 'GeoTIFF')
|
|
|
+
|
|
|
+ self.OnSetType(event = None, sel = self.sourceMap[self.dsnType])
|
|
|
+ if self.dest:
|
|
|
+ if current['format'] != 'native':
|
|
|
+ self.OnSetFormat(event = None, format = current['format'])
|
|
|
+ self.OnSetDsn(event = None, path = current['dsn'])
|
|
|
+ self.creationOpt.SetValue(current['options'])
|
|
|
else:
|
|
|
- self.OnSetFormat(event = None, format = 'ESRI Shapefile')
|
|
|
+ if not ogr:
|
|
|
+ self.OnSetFormat(event = None, format = 'GeoTIFF')
|
|
|
+ else:
|
|
|
+ self.OnSetFormat(event = None, format = 'ESRI Shapefile')
|
|
|
|
|
|
def _layout(self):
|
|
|
"""!Layout"""
|
|
@@ -1240,33 +1278,44 @@ class GdalSelect(wx.Panel):
|
|
|
inputSizer = wx.StaticBoxSizer(self.inputBox, wx.HORIZONTAL)
|
|
|
|
|
|
self.dsnSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
|
|
|
- self.dsnSizer.AddGrowableRow(1)
|
|
|
+ #self.dsnSizer.AddGrowableRow(0)
|
|
|
self.dsnSizer.AddGrowableCol(3)
|
|
|
|
|
|
- self.dsnSizer.Add(item=self.dsnText,
|
|
|
- flag=wx.ALIGN_CENTER_VERTICAL,
|
|
|
- pos = (0, 0))
|
|
|
- self.dsnSizer.Add(item=self.input[self.dsnType][1],
|
|
|
- flag = wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
|
|
|
- pos = (0, 1), span = (1, 3))
|
|
|
-
|
|
|
+ row = 0
|
|
|
self.dsnSizer.Add(item = wx.StaticText(parent = self, id = wx.ID_ANY,
|
|
|
label = _("Format:")),
|
|
|
flag = wx.ALIGN_CENTER_VERTICAL,
|
|
|
- pos = (1, 0))
|
|
|
+ pos = (row, 0))
|
|
|
self.dsnSizer.Add(item=self.format,
|
|
|
flag = wx.ALIGN_CENTER_VERTICAL,
|
|
|
- pos = (1, 1))
|
|
|
+ pos = (row, 1))
|
|
|
self.dsnSizer.Add(item = self.extensionText,
|
|
|
flag=wx.ALIGN_CENTER_VERTICAL,
|
|
|
- pos = (1, 2))
|
|
|
+ pos = (row, 2))
|
|
|
self.dsnSizer.Add(item=self.extension,
|
|
|
flag = wx.ALIGN_CENTER_VERTICAL,
|
|
|
- pos = (1, 3))
|
|
|
+ pos = (row, 3))
|
|
|
+ row += 1
|
|
|
+ self.dsnSizer.Add(item = self.dsnText,
|
|
|
+ flag = wx.ALIGN_CENTER_VERTICAL,
|
|
|
+ pos = (row, 0))
|
|
|
+ self.dsnSizer.Add(item = self.input[self.dsnType][1],
|
|
|
+ flag = wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
|
|
|
+ pos = (row, 1), span = (1, 3))
|
|
|
+ row += 1
|
|
|
+ if self.creationOpt.IsShown():
|
|
|
+ self.dsnSizer.Add(item = wx.StaticText(parent = self, id = wx.ID_ANY,
|
|
|
+ label = _("Creation options:")),
|
|
|
+ flag = wx.ALIGN_CENTER_VERTICAL,
|
|
|
+ pos = (row, 0))
|
|
|
+ self.dsnSizer.Add(item = self.creationOpt,
|
|
|
+ flag = wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
|
|
|
+ pos = (row, 1), span = (1, 3))
|
|
|
+ row += 1
|
|
|
+
|
|
|
+ inputSizer.Add(item=self.dsnSizer, proportion = 1,
|
|
|
+ flag=wx.EXPAND | wx.BOTTOM, border = 10)
|
|
|
|
|
|
- inputSizer.Add(item=self.dsnSizer, proportion=1,
|
|
|
- flag=wx.EXPAND | wx.ALL)
|
|
|
-
|
|
|
mainSizer.Add(item=settingsSizer, proportion=0,
|
|
|
flag=wx.ALL | wx.EXPAND, border=5)
|
|
|
mainSizer.Add(item=self.source, proportion=0,
|
|
@@ -1293,12 +1342,13 @@ class GdalSelect(wx.Panel):
|
|
|
name = event.GetString()
|
|
|
if name not in self._settings:
|
|
|
gcmd.GError(parent = self,
|
|
|
- message = _("Settings named '%s' not found") % name)
|
|
|
+ message = _("Settings <%s> not found") % name)
|
|
|
return
|
|
|
data = self._settings[name]
|
|
|
self.OnSetType(event = None, sel = self.sourceMap[data[0]])
|
|
|
self.OnSetFormat(event = None, format = data[2])
|
|
|
self.OnSetDsn(event = None, path = data[1])
|
|
|
+ self.creationOpt.SetValue(data[3])
|
|
|
|
|
|
def OnSettingsSave(self, event):
|
|
|
"""!Save settings"""
|
|
@@ -1317,7 +1367,7 @@ class GdalSelect(wx.Panel):
|
|
|
try:
|
|
|
fd = open(self.settingsFile, 'a')
|
|
|
fd.write(name + ';' + self.dsnType + ';' +
|
|
|
- self._getDsn() + ';' +
|
|
|
+ self.GetDsn() + ';' +
|
|
|
self.format.GetStringSelection())
|
|
|
fd.write('\n')
|
|
|
except IOError:
|
|
@@ -1348,8 +1398,12 @@ class GdalSelect(wx.Panel):
|
|
|
fd = open(self.settingsFile, 'r')
|
|
|
for line in fd.readlines():
|
|
|
try:
|
|
|
- name, ftype, dsn, format = line.rstrip('\n').split(';')
|
|
|
- data[name] = (ftype, dsn, format)
|
|
|
+ lineData = line.rstrip('\n').split(';')
|
|
|
+ if len(lineData) > 4:
|
|
|
+ # type, dsn, format, options
|
|
|
+ data[lineData[0]] = (lineData[1], lineData[2], lineData[3], lineData[4])
|
|
|
+ else:
|
|
|
+ data[lineData[0]] = (lineData[1], lineData[2], lineData[3], '')
|
|
|
except ValueError:
|
|
|
pass
|
|
|
except IOError:
|
|
@@ -1365,10 +1419,11 @@ class GdalSelect(wx.Panel):
|
|
|
sel = event.GetSelection()
|
|
|
else:
|
|
|
self.source.SetSelection(sel)
|
|
|
-
|
|
|
win = self.input[self.dsnType][1]
|
|
|
- self.dsnSizer.Remove(win)
|
|
|
- win.Hide()
|
|
|
+ if win:
|
|
|
+ self.dsnSizer.Remove(win)
|
|
|
+ win.Hide()
|
|
|
+
|
|
|
if sel == self.sourceMap['file']: # file
|
|
|
self.dsnType = 'file'
|
|
|
format = self.input[self.dsnType][2][0]
|
|
@@ -1392,39 +1447,46 @@ class GdalSelect(wx.Panel):
|
|
|
|
|
|
elif sel == self.sourceMap['dir']: # directory
|
|
|
self.dsnType = 'dir'
|
|
|
- elif sel == self.sourceMap['db']: # database
|
|
|
+ elif sel == self.sourceMap['db']: # database
|
|
|
self.dsnType = 'db'
|
|
|
elif sel == self.sourceMap['pro']: # protocol
|
|
|
self.dsnType = 'pro'
|
|
|
+ elif sel == self.sourceMap['native']:
|
|
|
+ self.dsnType = 'native'
|
|
|
|
|
|
- self.dsnText.SetLabel(self.input[self.dsnType][0])
|
|
|
- if self.parent.GetName() == 'MultiImportDialog':
|
|
|
- self.parent.list.DeleteAllItems()
|
|
|
- self.format.SetItems(self.input[self.dsnType][2])
|
|
|
+ if self.dsnType == 'db':
|
|
|
+ self.input[self.dsnType][1] = self.input['db-win']['text']
|
|
|
+ win = self.input[self.dsnType][1]
|
|
|
+
|
|
|
+ self.dsnSizer.Add(item = self.input[self.dsnType][1],
|
|
|
+ flag = wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
|
|
|
+ pos = (1, 1), span = (1, 3))
|
|
|
+ win.SetValue('')
|
|
|
+ win.Show()
|
|
|
|
|
|
if sel in (self.sourceMap['file'],
|
|
|
self.sourceMap['dir']):
|
|
|
- win = self.input[self.dsnType][1]
|
|
|
- self.dsnSizer.Add(item=self.input[self.dsnType][1],
|
|
|
- flag = wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
|
|
|
- pos = (0, 1))
|
|
|
- win.SetValue('')
|
|
|
- win.Show()
|
|
|
-
|
|
|
if not self.ogr:
|
|
|
self.OnSetFormat(event = None, format = 'GeoTIFF')
|
|
|
else:
|
|
|
self.OnSetFormat(event = None, format = 'ESRI Shapefile')
|
|
|
+
|
|
|
+ if sel == self.sourceMap['native']: # native
|
|
|
+ win.Enable(False)
|
|
|
+ self.format.Enable(False)
|
|
|
+ self.creationOpt.Enable(False)
|
|
|
+ self.parent.btnOk.Enable(True)
|
|
|
else:
|
|
|
- if sel == self.sourceMap['pro']:
|
|
|
- win = self.input[self.dsnType][1]
|
|
|
- self.dsnSizer.Add(item=self.input[self.dsnType][1],
|
|
|
- flag = wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
|
|
|
- pos = (0, 1))
|
|
|
- win.SetValue('')
|
|
|
- win.Show()
|
|
|
-
|
|
|
- if sel == self.sourceMap['dir']:
|
|
|
+ if not self.format.IsEnabled():
|
|
|
+ win.Enable(True)
|
|
|
+ self.format.Enable(True)
|
|
|
+ self.creationOpt.Enable(True)
|
|
|
+ self.dsnText.SetLabel(self.input[self.dsnType][0])
|
|
|
+ self.format.SetItems(self.input[self.dsnType][2])
|
|
|
+ if self.parent.GetName() == 'MultiImportDialog':
|
|
|
+ self.parent.list.DeleteAllItems()
|
|
|
+
|
|
|
+ if sel == self.sourceMap['dir'] and not self.dest:
|
|
|
if not self.extension.IsShown():
|
|
|
self.extensionText.Show()
|
|
|
self.extension.Show()
|
|
@@ -1432,10 +1494,10 @@ class GdalSelect(wx.Panel):
|
|
|
if self.extension.IsShown():
|
|
|
self.extensionText.Hide()
|
|
|
self.extension.Hide()
|
|
|
-
|
|
|
+
|
|
|
self.dsnSizer.Layout()
|
|
|
|
|
|
- def _getDsn(self):
|
|
|
+ def GetDsn(self):
|
|
|
"""!Get datasource name"""
|
|
|
if self.format.GetStringSelection() == 'PostgreSQL':
|
|
|
return 'PG:dbname=%s' % self.input[self.dsnType][1].GetStringSelection()
|
|
@@ -1456,18 +1518,23 @@ class GdalSelect(wx.Panel):
|
|
|
break
|
|
|
else:
|
|
|
self.input[self.dsnType][1].SetValue(path)
|
|
|
-
|
|
|
- if not path:
|
|
|
- return
|
|
|
|
|
|
- self._reloadLayers()
|
|
|
+ if not path:
|
|
|
+ if self.dest:
|
|
|
+ self.parent.btnOk.Enable(False)
|
|
|
+ return
|
|
|
+
|
|
|
+ if self.dest:
|
|
|
+ self.parent.btnOk.Enable(True)
|
|
|
+ else:
|
|
|
+ self._reloadLayers()
|
|
|
|
|
|
if event:
|
|
|
event.Skip()
|
|
|
|
|
|
def _reloadLayers(self):
|
|
|
"""!Reload list of layers"""
|
|
|
- dsn = self._getDsn()
|
|
|
+ dsn = self.GetDsn()
|
|
|
if not dsn:
|
|
|
return
|
|
|
|
|
@@ -1521,8 +1588,9 @@ class GdalSelect(wx.Panel):
|
|
|
|
|
|
def OnSetExtension(self, event):
|
|
|
"""!Extension changed"""
|
|
|
- # reload layers
|
|
|
- self._reloadLayers()
|
|
|
+ if not self.dest:
|
|
|
+ # reload layers
|
|
|
+ self._reloadLayers()
|
|
|
|
|
|
def OnSetFormat(self, event, format = None):
|
|
|
"""!Format changed"""
|
|
@@ -1582,24 +1650,27 @@ class GdalSelect(wx.Panel):
|
|
|
if dbname:
|
|
|
db.append(dbname)
|
|
|
win.SetItems(db)
|
|
|
+ if self.dest and win.GetStringSelection():
|
|
|
+ self.parent.btnOk.Enable(True)
|
|
|
else:
|
|
|
win = self.input['db-win']['text']
|
|
|
else:
|
|
|
win = self.input['db-win']['text']
|
|
|
-
|
|
|
+
|
|
|
self.input[self.dsnType][1] = win
|
|
|
if not win.IsShown():
|
|
|
win.Show()
|
|
|
self.dsnSizer.Add(item = self.input[self.dsnType][1],
|
|
|
flag = wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
|
|
|
- pos = (0, 1), span = (1, 3))
|
|
|
+ pos = (1, 1), span = (1, 3))
|
|
|
self.dsnSizer.Layout()
|
|
|
|
|
|
# update extension
|
|
|
self.extension.SetValue(self.GetFormatExt())
|
|
|
|
|
|
- # reload layers
|
|
|
- self._reloadLayers()
|
|
|
+ if not self.dest:
|
|
|
+ # reload layers
|
|
|
+ self._reloadLayers()
|
|
|
|
|
|
def GetType(self):
|
|
|
"""!Get source type"""
|
|
@@ -1622,10 +1693,21 @@ class GdalSelect(wx.Panel):
|
|
|
|
|
|
return win
|
|
|
|
|
|
+ def GetFormat(self):
|
|
|
+ """!Get format as string"""
|
|
|
+ return self.format.GetStringSelection().replace(' ', '_')
|
|
|
+
|
|
|
def GetFormatExt(self):
|
|
|
"""!Get format extension"""
|
|
|
return self.format.GetExtension(self.format.GetStringSelection())
|
|
|
|
|
|
+ def GetOptions(self):
|
|
|
+ """!Get creation options"""
|
|
|
+ if not self.creationOpt.IsShown():
|
|
|
+ return ''
|
|
|
+
|
|
|
+ return self.creationOpt.GetValue()
|
|
|
+
|
|
|
class ProjSelect(wx.ComboBox):
|
|
|
"""!Widget for selecting input raster/vector map used by
|
|
|
r.proj/v.proj modules."""
|