[GRASS-SVN] r44800 - in grass/trunk/gui/wxpython: gui_modules xml
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Dec 30 06:36:13 EST 2010
Author: martinl
Date: 2010-12-30 03:36:13 -0800 (Thu, 30 Dec 2010)
New Revision: 44800
Modified:
grass/trunk/gui/wxpython/gui_modules/gselect.py
grass/trunk/gui/wxpython/xml/menudata.xml
Log:
wxGUI: load/save settings for GdalSelect
menuitem 'link external formats' added to the menu
Modified: grass/trunk/gui/wxpython/gui_modules/gselect.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gselect.py 2010-12-30 09:56:06 UTC (rev 44799)
+++ grass/trunk/gui/wxpython/gui_modules/gselect.py 2010-12-30 11:36:13 UTC (rev 44800)
@@ -1061,6 +1061,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"))
@@ -1088,6 +1091,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,
@@ -1188,6 +1203,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)
@@ -1210,9 +1239,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)
@@ -1227,9 +1258,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()
@@ -1263,7 +1364,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]
@@ -1287,19 +1388,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])
@@ -1343,9 +1460,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
@@ -1358,7 +1476,10 @@
else: # database
win.Hide()
- format = event.GetString()
+ if event:
+ format = event.GetString()
+ else:
+ self.format.SetStringSelection(format)
if self.dsnType == 'file':
try:
@@ -1415,7 +1536,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/trunk/gui/wxpython/xml/menudata.xml
===================================================================
--- grass/trunk/gui/wxpython/xml/menudata.xml 2010-12-30 09:56:06 UTC (rev 44799)
+++ grass/trunk/gui/wxpython/xml/menudata.xml 2010-12-30 11:36:13 UTC (rev 44800)
@@ -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>ASCII x,y,z point import and gridding</label>
@@ -158,19 +151,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,external,ogr</keywords>
- <handler>OnLinkOgrLayers</handler>
- <command>v.external</command>
- </menuitem>
<separator />
<menuitem>
<label>ASCII points or GRASS ASCII format</label>
@@ -502,6 +488,41 @@
</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,external</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,external,ogr</keywords>
+ <handler>OnLinkOgrLayers</handler>
+ <command>v.external</command>
+ </menuitem>
+ <separator />
+ <menuitem>
+ <label>Output format for raster data</label>
+ <help>Defines raster output format utilizing GDAL library.</help>
+ <keywords>raster,export,external</keywords>
+ <handler>OnMenuCmd</handler>
+ <command>r.external.out</command>
+ </menuitem>
+ <menuitem>
+ <label>Output format for vector data</label>
+ <help>Defines vector output format utilizing OGR library.</help>
+ <keywords>vector,output,external</keywords>
+ <handler>OnMenuCmd</handler>
+ <command>v.external.out</command>
+ </menuitem>
+ </items>
+ </menu>
+ <separator />
+ <menu>
<label>Manage maps and volumes</label>
<items>
<menuitem>
@@ -2336,7 +2357,7 @@
<separator />
<menuitem>
<label>Update area attributes from raster</label>
- <help>Calculates univariate statistics from a GRASS raster map based on vector polygons and uploads statistics to new attribute columns.</help>
+ <help>Calculates univariate statistics from a raster map based on vector polygon map and uploads statistics to new attribute columns.</help>
<keywords>vector,raster,statistics</keywords>
<handler>OnMenuCmd</handler>
<command>v.rast.stats</command>
@@ -2595,7 +2616,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>
@@ -2622,8 +2643,8 @@
<items>
<menuitem>
<label>Aster DN to radiance/reflectance</label>
- <help>Calculates top-of-atmosphere radiance or reflectance and temperature for Aster.</help>
- <keywords>imagery,Terra-ASTER,top-of-atmosphere reflectance</keywords>
+ <help>Calculates Top of Atmosphere Radiance/Reflectance/Brightness Temperature from ASTER DN.</help>
+ <keywords>imagery,Terra-ASTER,DN,radiance,reflectance,brightness temperature</keywords>
<handler>OnMenuCmd</handler>
<command>i.aster.toar</command>
</menuitem>
More information about the grass-commit
mailing list