[GRASS-SVN] r44805 - in
grass/branches/releasebranch_6_4/gui/wxpython: gui_modules xml
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Dec 30 06:58:35 EST 2010
Author: martinl
Date: 2010-12-30 03:58:35 -0800 (Thu, 30 Dec 2010)
New Revision: 44805
Modified:
grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/gselect.py
grass/branches/releasebranch_6_4/gui/wxpython/xml/menudata.xml
Log:
wxGUI: load/save settings for GdalSelect
menuitem 'link external formats' added to the menu
(merge r44800 from trunk)
Modified: grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/gselect.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/gselect.py 2010-12-30 11:51:42 UTC (rev 44804)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/gselect.py 2010-12-30 11:58:35 UTC (rev 44805)
@@ -1020,6 +1020,9 @@
self.parent = parent
self.ogr = ogr
wx.Panel.__init__(self, parent = panel, id = wx.ID_ANY)
+
+ 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 name"))
@@ -1047,6 +1050,18 @@
sources.append(_("Protocol"))
self.sourceMap['pro'] = idx
+ if self.ogr:
+ self.settingsFile = os.path.join(os.path.expanduser("~"), '.grass7', 'wxOGR')
+ else:
+ self.settingsFile = os.path.join(os.path.expanduser("~"), '.grass7', 'wxGDAL')
+
+ self._settings = self._loadSettings()
+ self.settingsChoice = wx.Choice(parent = self, id = wx.ID_ANY)
+ self.settingsChoice.Bind(wx.EVT_CHOICE, self.OnSettingsLoad)
+ self.settingsChoice.SetItems(self._settings.keys())
+ self.btnSettings = wx.Button(parent = self, id = wx.ID_SAVE)
+ 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,
@@ -1147,6 +1162,20 @@
def _layout(self):
"""!Layout"""
mainSizer = wx.BoxSizer(wx.VERTICAL)
+
+ settingsSizer = wx.StaticBoxSizer(self.settingsBox, wx.HORIZONTAL)
+ settingsSizer.Add(item = wx.StaticText(parent = self,
+ id = wx.ID_ANY,
+ label = _("Load settings:")),
+ flag = wx.ALIGN_CENTER_VERTICAL | wx.RIGHT,
+ border = 5)
+ settingsSizer.Add(item = self.settingsChoice,
+ proportion = 1,
+ flag = wx.EXPAND)
+ settingsSizer.Add(item = self.btnSettings,
+ flag = wx.LEFT,
+ border = 5)
+
inputSizer = wx.StaticBoxSizer(self.inputBox, wx.HORIZONTAL)
self.dsnSizer = wx.GridBagSizer(vgap=3, hgap=3)
@@ -1169,9 +1198,11 @@
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,
- flag=wx.ALL | wx.EXPAND, border=5)
+ flag=wx.LEFT | wx.RIGHT | wx.EXPAND, border=5)
mainSizer.Add(item=inputSizer, proportion=0,
flag=wx.ALL | wx.EXPAND, border=5)
@@ -1186,9 +1217,79 @@
return pattern
- def OnSetType(self, event):
+ def OnSettingsLoad(self, event):
+ """!Load named settings"""
+ name = event.GetString()
+ if not self._settings.has_key(name):
+ gcmd.GError(parent = self,
+ message = _("Settings named '%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])
+
+ def OnSettingsSave(self, event):
+ """!Save settings"""
+ dlg = wx.TextEntryDialog(parent = self,
+ message = _("Name:"),
+ caption = _("Save settings"))
+ if dlg.ShowModal() != wx.ID_OK:
+ return
+
+ if not dlg.GetValue():
+ gcmd.GMessage(parent = self,
+ message = _("Name not given, settings is not saved."))
+ return
+
+ data = self._loadSettings()
+ try:
+ fd = open(self.settingsFile, 'w')
+ fd.write(dlg.GetValue() + ';' + self.dsnType + ';' +
+ self._getDsn() + ';' +
+ self.format.GetStringSelection())
+ fd.write('\n')
+ except IOError:
+ gcmd.GError(parent = self,
+ message = _("Unable to save settings."))
+ return
+ fd.close()
+ dlg.Destroy()
+
+ def _loadSettings(self):
+ """!Load settings from the file
+
+ The file is defined by self.SettingsFile.
+
+ @return parsed dict
+ @return empty dict on error
+ """
+ data = dict()
+ if not os.path.exists(self.settingsFile):
+ return data
+
+ try:
+ fd = open(self.settingsFile, 'r')
+ for line in fd.readlines():
+ try:
+ name, ftype, dsn, format = line.rstrip('\n').split(';')
+ data[name] = (ftype, dsn, format)
+ except ValueError:
+ pass
+ except IOError:
+ return data
+
+ fd.close()
+
+ return data
+
+ def OnSetType(self, event, sel = None):
"""!Datasource type changed"""
- sel = event.GetSelection()
+ if event:
+ sel = event.GetSelection()
+ else:
+ self.source.SetSelection(sel)
+
win = self.input[self.dsnType][1]
self.dsnSizer.Remove(win)
win.Hide()
@@ -1222,7 +1323,7 @@
if self.parent.GetName() == 'MultiImportDialog':
self.parent.list.DeleteAllItems()
self.format.SetItems(self.input[self.dsnType][2])
-
+
if sel in (self.sourceMap['file'],
self.sourceMap['dir']):
win = self.input[self.dsnType][1]
@@ -1246,19 +1347,35 @@
self.dsnSizer.Layout()
- def OnSetDsn(self, event):
+ def _getDsn(self):
+ """!Get datasource name"""
+ if self.format.GetStringSelection() == 'PostgreSQL':
+ return 'PG:dbname=%s' % self.input[self.dsnType][1].GetStringSelection()
+
+ return self.input[self.dsnType][1].GetValue()
+
+ def OnSetDsn(self, event, path = None):
"""!Input DXF file/OGR dsn defined, update list of layer widget"""
- path = event.GetString()
+ if event:
+ path = event.GetString()
+ else:
+ if self.format.GetStringSelection() == 'PostgreSQL':
+ for item in path.split(':', 1)[1].split(','):
+ key, value = item.split('=', 1)
+ if key == 'dbname':
+ self.input[self.dsnType][1].SetStringSelection(value)
+ break
+ else:
+ self.input[self.dsnType][1].SetValue(path)
+
if not path:
return
data = list()
layerId = 1
- if self.format.GetStringSelection() == 'PostgreSQL':
- dsn = 'PG:dbname=%s' % self.input[self.dsnType][1].GetValue()
- else:
- dsn = self.input[self.dsnType][1].GetValue()
+ dsn = self._getDsn()
+
if self.dsnType == 'file':
baseName = os.path.basename(dsn)
grassName = utils.GetValidLayerName(baseName.split('.', -1)[0])
@@ -1302,9 +1419,10 @@
else:
self.parent.btn_run.Enable(False)
- event.Skip()
+ if event:
+ event.Skip()
- def OnSetFormat(self, event):
+ def OnSetFormat(self, event, format = None):
"""!Format changed"""
if self.dsnType not in ['file', 'db']:
return
@@ -1317,7 +1435,10 @@
else: # database
win.Hide()
- format = event.GetString()
+ if event:
+ format = event.GetString()
+ else:
+ self.format.SetStringSelection(format)
if self.dsnType == 'file':
try:
@@ -1374,7 +1495,7 @@
def GetDsn(self):
"""!Get DSN"""
if self.format.GetStringSelection() == 'PostgreSQL':
- return 'PG:dbname=%s' % self.input[self.dsnType][1].GetValue()
+ return 'PG:dbname=%s' % self.input[self.dsnType][1].GetStringSelection()
return self.input[self.dsnType][1].GetValue()
Modified: grass/branches/releasebranch_6_4/gui/wxpython/xml/menudata.xml
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/xml/menudata.xml 2010-12-30 11:51:42 UTC (rev 44804)
+++ grass/branches/releasebranch_6_4/gui/wxpython/xml/menudata.xml 2010-12-30 11:58:35 UTC (rev 44805)
@@ -54,19 +54,12 @@
<label>Import raster data</label>
<items>
<menuitem>
- <label>Import raster data</label>
+ <label>Common import formats</label>
<help>Import raster data into a GRASS map layer using GDAL.</help>
<keywords>raster,import</keywords>
<handler>OnImportGdalLayers</handler>
<command>r.in.gdal</command>
</menuitem>
- <menuitem>
- <label>Link external raster data</label>
- <help>Link GDAL supported raster data as a pseudo GRASS raster map layer.</help>
- <keywords>raster,import</keywords>
- <handler>OnLinkGdalLayers</handler>
- <command>r.external</command>
- </menuitem>
<separator />
<menuitem>
<label>Aggregate ASCII xyz import</label>
@@ -151,19 +144,12 @@
<label>Import vector data</label>
<items>
<menuitem>
- <label>Import vector data</label>
+ <label>Common import formats</label>
<help>Converts vector layers into a GRASS vector map using OGR.</help>
<keywords>vector,import</keywords>
<handler>OnImportOgrLayers</handler>
<command>v.in.ogr</command>
</menuitem>
- <menuitem>
- <label>Link external vector data</label>
- <help>Creates a new pseudo-vector map as a link to an OGR-supported layer.</help>
- <keywords>vector</keywords>
- <handler>OnLinkOgrLayers</handler>
- <command>v.external</command>
- </menuitem>
<separator />
<menuitem>
<label>ASCII points/GRASS ASCII vector import</label>
@@ -495,6 +481,26 @@
</menu>
<separator />
<menu>
+ <label>Link external formats</label>
+ <items>
+ <menuitem>
+ <label>Link external raster data</label>
+ <help>Link GDAL supported raster data as a pseudo GRASS raster map layer.</help>
+ <keywords>raster,import</keywords>
+ <handler>OnLinkGdalLayers</handler>
+ <command>r.external</command>
+ </menuitem>
+ <menuitem>
+ <label>Link external vector data</label>
+ <help>Creates a new pseudo-vector map as a link to an OGR-supported layer.</help>
+ <keywords>vector</keywords>
+ <handler>OnLinkOgrLayers</handler>
+ <command>v.external</command>
+ </menuitem>
+ </items>
+ </menu>
+ <separator />
+ <menu>
<label>Manage maps and volumes</label>
<items>
<menuitem>
@@ -1775,7 +1781,7 @@
</menuitem>
<menuitem>
<label>Linear regression</label>
- <help>Calculates linear regression from two raster maps: y = a + b*x</help>
+ <help>Calculates linear regression from two raster maps: y = a + b*x.</help>
<keywords>raster,statistics</keywords>
<handler>OnMenuCmd</handler>
<command>r.regression.line</command>
@@ -2595,7 +2601,7 @@
</menuitem>
<menuitem>
<label>Principal components</label>
- <help>Principal components analysis (pca) program for image processing.</help>
+ <help>Principal components analysis (PCA) for image processing.</help>
<keywords>imagery,image transformation,PCA</keywords>
<handler>OnMenuCmd</handler>
<command>i.pca</command>
More information about the grass-commit
mailing list