|
@@ -37,10 +37,11 @@ import wx.lib.filebrowsebutton as filebrowse
|
|
|
from grass.script import core as grass
|
|
|
from grass.script import task as gtask
|
|
|
|
|
|
-from core.gcmd import RunCommand, GMessage, GWarning
|
|
|
+from core.gcmd import GError, GMessage, GWarning, RunCommand
|
|
|
from gui_core.forms import CmdPanel
|
|
|
from gui_core.gselect import OgrTypeSelect, GdalSelect, SubGroupSelect
|
|
|
-from gui_core.widgets import LayersList, GListCtrl, GNotebook
|
|
|
+from gui_core.widgets import GListCtrl, GNotebook, LayersList, \
|
|
|
+ LayersListValidator
|
|
|
from gui_core.wrap import Button, StaticText, StaticBox
|
|
|
from core.utils import GetValidLayerName
|
|
|
from core.settings import UserSettings, GetDisplayVectSettings
|
|
@@ -100,6 +101,7 @@ class ImportDialog(wx.Dialog):
|
|
|
group='cmd',
|
|
|
key='overwrite',
|
|
|
subkey='enabled'))
|
|
|
+ self.overwrite.Bind(wx.EVT_CHECKBOX, self.OnCheckOverwrite)
|
|
|
|
|
|
self.add = wx.CheckBox(parent=self.panel, id=wx.ID_ANY)
|
|
|
self.closeOnFinish = wx.CheckBox(parent=self.panel, id=wx.ID_ANY,
|
|
@@ -241,6 +243,36 @@ class ImportDialog(wx.Dialog):
|
|
|
"""Get flags which will not be showed in Settings page"""
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
+ def _nameValidationFailed(self, layers_list):
|
|
|
+ """Output map name validation callback
|
|
|
+
|
|
|
+ :param layers_list: LayersList class instance
|
|
|
+ """
|
|
|
+ if isinstance(layers_list.output_map, list):
|
|
|
+ maps = [
|
|
|
+ '<{}>'.format(m) for m in layers_list.output_map]
|
|
|
+ message = _(
|
|
|
+ "Output map names %(names)s exist. "
|
|
|
+ ) % {
|
|
|
+ 'names': ', '.join(maps)}
|
|
|
+ else:
|
|
|
+ message = _(
|
|
|
+ "Output map name <%(name)s> exist. "
|
|
|
+ ) % {
|
|
|
+ 'name': layers_list.output_map}
|
|
|
+ GError(parent=self, message=message, caption=_("Invalid name"))
|
|
|
+
|
|
|
+ def _validateOutputMapName(self):
|
|
|
+ """Enable/disable output map name validation according the
|
|
|
+ overwrite state"""
|
|
|
+ if not self.overwrite.IsChecked() or \
|
|
|
+ UserSettings.Get(group='cmd', key='overwrite',
|
|
|
+ subkey='enabled'):
|
|
|
+ if not self.list.GetValidator().\
|
|
|
+ Validate(win=self.list, validate_all=True):
|
|
|
+ return False
|
|
|
+ return True
|
|
|
+
|
|
|
def OnClose(self, event=None):
|
|
|
"""Close dialog"""
|
|
|
self.Close()
|
|
@@ -249,6 +281,13 @@ class ImportDialog(wx.Dialog):
|
|
|
"""Import/Link data (each layes as separate vector map)"""
|
|
|
pass
|
|
|
|
|
|
+ def OnCheckOverwrite(self, event):
|
|
|
+ """Check/uncheck overwrite checkbox widget"""
|
|
|
+ if self.overwrite.IsChecked():
|
|
|
+ self.list.validate = False
|
|
|
+ else:
|
|
|
+ self.list.validate = True
|
|
|
+
|
|
|
def AddLayers(self, returncode, cmd=None, userData=None):
|
|
|
"""Add imported/linked layers into layer tree"""
|
|
|
if not self.add.IsChecked() or returncode != 0:
|
|
@@ -387,6 +426,12 @@ class GdalImportDialog(ImportDialog):
|
|
|
self.layersData = []
|
|
|
|
|
|
ImportDialog.__init__(self, parent, giface=giface, itype='gdal')
|
|
|
+
|
|
|
+ self.list.SetValidator(
|
|
|
+ LayersListValidator(
|
|
|
+ condition='raster',
|
|
|
+ callback=self._nameValidationFailed))
|
|
|
+
|
|
|
if link:
|
|
|
self.SetTitle(_("Link external raster data"))
|
|
|
else:
|
|
@@ -437,6 +482,9 @@ class GdalImportDialog(ImportDialog):
|
|
|
parent=self)
|
|
|
return
|
|
|
|
|
|
+ if not self._validateOutputMapName():
|
|
|
+ return
|
|
|
+
|
|
|
dsn = self.dsnInput.GetDsn()
|
|
|
ext = self.dsnInput.GetFormatExt()
|
|
|
|
|
@@ -528,6 +576,12 @@ class OgrImportDialog(ImportDialog):
|
|
|
self.layersData = []
|
|
|
|
|
|
ImportDialog.__init__(self, parent, giface=giface, itype='ogr')
|
|
|
+
|
|
|
+ self.list.SetValidator(
|
|
|
+ LayersListValidator(
|
|
|
+ condition='vector',
|
|
|
+ callback=self._nameValidationFailed))
|
|
|
+
|
|
|
if link:
|
|
|
self.SetTitle(_("Link external vector data"))
|
|
|
else:
|
|
@@ -578,6 +632,9 @@ class OgrImportDialog(ImportDialog):
|
|
|
parent=self)
|
|
|
return
|
|
|
|
|
|
+ if not self._validateOutputMapName():
|
|
|
+ return
|
|
|
+
|
|
|
dsn = self.dsnInput.GetDsn()
|
|
|
ext = self.dsnInput.GetFormatExt()
|
|
|
|
|
@@ -757,6 +814,12 @@ class DxfImportDialog(ImportDialog):
|
|
|
def __init__(self, parent, giface):
|
|
|
ImportDialog.__init__(self, parent, giface=giface, itype='dxf',
|
|
|
title=_("Import DXF layers"))
|
|
|
+
|
|
|
+ self.list.SetValidator(
|
|
|
+ LayersListValidator(
|
|
|
+ condition='vector',
|
|
|
+ callback=self._nameValidationFailed))
|
|
|
+
|
|
|
self._giface = giface
|
|
|
self.dsnInput = filebrowse.FileBrowseButton(
|
|
|
parent=self.panel,
|
|
@@ -787,6 +850,9 @@ class DxfImportDialog(ImportDialog):
|
|
|
GMessage(_("No layers selected."), parent=self)
|
|
|
return
|
|
|
|
|
|
+ if not self._validateOutputMapName():
|
|
|
+ return
|
|
|
+
|
|
|
# hide dialog
|
|
|
self.Hide()
|
|
|
|