[GRASS-SVN] r44184 - in grass/trunk: gui/wxpython/gui_modules
raster/r.proj vector/v.proj
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Nov 6 09:15:24 EDT 2010
Author: martinl
Date: 2010-11-06 06:15:24 -0700 (Sat, 06 Nov 2010)
New Revision: 44184
Modified:
grass/trunk/gui/wxpython/gui_modules/gselect.py
grass/trunk/gui/wxpython/gui_modules/menuform.py
grass/trunk/raster/r.proj/main.c
grass/trunk/vector/v.proj/main.c
Log:
r.proj/v.proj: wxGUI interactivity improved (select input map from location)
Modified: grass/trunk/gui/wxpython/gui_modules/gselect.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gselect.py 2010-11-06 13:13:35 UTC (rev 44183)
+++ grass/trunk/gui/wxpython/gui_modules/gselect.py 2010-11-06 13:15:24 UTC (rev 44184)
@@ -13,11 +13,13 @@
- DriverSelect
- DatabaseSelect
- ColumnSelect
+ - DbaseSelect
- LocationSelect
- MapsetSelect
- SubGroupSelect
- FormatSelect
- GdalSelect
+ - ProjSelect
(C) 2007-2010 by the GRASS Development Team This program is free
software under the GNU General Public License (>=v2). Read the file
@@ -93,7 +95,7 @@
"""!Custom to create a ComboBox with a tree control to display and
select vector maps. Control allows to filter vector maps. If you
don't need this feature use Select class instead
-
+
@ftype filter vector maps based on feature type
"""
Select.__init__(self, parent = parent, id = wx.ID_ANY,
@@ -763,6 +765,16 @@
if self.param:
self.param['value'] = ''
+
+class DbaseSelect(wx.lib.filebrowsebutton.DirBrowseButton):
+ """!Widget for selecting GRASS Database"""
+ def __init__(self, parent, **kwargs):
+ super(DbaseSelect, self).__init__(parent, id = wx.ID_ANY,
+ size = globalvar.DIALOG_GSELECT_SIZE, labelText = '',
+ dialogTitle = _('Choose GIS Data Directory'),
+ buttonText = _('Browse'),
+ startDirectory = grass.gisenv()['GISDBASE'],
+ **kwargs)
class LocationSelect(wx.ComboBox):
"""!Widget for selecting GRASS location"""
@@ -770,16 +782,26 @@
gisdbase = None, **kwargs):
super(LocationSelect, self).__init__(parent, id, size = size,
style = wx.CB_READONLY, **kwargs)
-
self.SetName("LocationSelect")
if not gisdbase:
self.gisdbase = grass.gisenv()['GISDBASE']
else:
self.gisdbase = gisdbase
-
+
self.SetItems(utils.GetListOfLocations(self.gisdbase))
+ def UpdateItems(self, dbase):
+ """!Update list of locations
+
+ @param dbase path to GIS database
+ """
+ self.gisdbase = dbase
+ if dbase:
+ self.SetItems(utils.GetListOfLocations(self.gisdbase))
+ else:
+ self.SetItems([])
+
class MapsetSelect(wx.ComboBox):
"""!Widget for selecting GRASS mapset"""
def __init__(self, parent, id = wx.ID_ANY, size = globalvar.DIALOG_COMBOBOX_SIZE,
@@ -788,7 +810,6 @@
style = wx.CB_READONLY, **kwargs)
self.SetName("MapsetSelect")
-
if not gisdbase:
self.gisdbase = grass.gisenv()['GISDBASE']
else:
@@ -802,6 +823,20 @@
if setItems:
self.SetItems(utils.GetListOfMapsets(self.gisdbase, self.location, selectable = True)) # selectable
+ def UpdateItems(self, location, dbase = None):
+ """!Update list of mapsets for given location
+
+ @param dbase path to GIS database (None to use currently selected)
+ @param location name of location
+ """
+ if dbase:
+ self.gisdbase = dbase
+ self.location = location
+ if location:
+ self.SetItems(utils.GetListOfMapsets(self.gisdbase, self.location, selectable = True))
+ else:
+ self.SetItems([])
+
class SubGroupSelect(wx.ComboBox):
"""!Widget for selecting subgroups"""
def __init__(self, parent, id = wx.ID_ANY, size = globalvar.DIALOG_GSELECT_SIZE,
@@ -978,7 +1013,7 @@
filemask = 'ESRI Shapefile (*.shp)|*.shp'
dsnFile = filebrowse.FileBrowseButton(parent=self, id=wx.ID_ANY,
- size=globalvar.DIALOG_GSELECT_SIZE, labelText='',
+ size=globalvar.DIALOG_GSELECT_SIZE, labelText = '',
dialogTitle=_('Choose input file'),
buttonText=_('Browse'),
startDirectory=os.getcwd(),
@@ -997,7 +1032,7 @@
dsnDbFile = filebrowse.FileBrowseButton(parent=self, id=wx.ID_ANY,
size=globalvar.DIALOG_GSELECT_SIZE, labelText='',
- dialogTitle=_('Choose file'),
+ dialogTitle=_('Choose file'),
buttonText=_('Browse'),
startDirectory=os.getcwd(),
changeCallback=self.OnSetDsn)
@@ -1302,3 +1337,44 @@
"""!Get format extension"""
return self.format.GetExtension(self.format.GetStringSelection())
+class ProjSelect(wx.ComboBox):
+ """!Widget for selecting input raster/vector map used by
+ r.proj/v.proj modules."""
+ def __init__(self, parent, isRaster, id = wx.ID_ANY, size = globalvar.DIALOG_COMBOBOX_SIZE,
+ **kwargs):
+ super(ProjSelect, self).__init__(parent, id, size = size,
+ style = wx.CB_READONLY, **kwargs)
+ self.SetName("ProjSelect")
+ self.isRaster = isRaster
+
+ def UpdateItems(self, dbase, location, mapset):
+ """!Update list of maps
+
+ """
+ if not dbase:
+ dbase = grass.gisenv()['GISDBASE']
+ if not mapset:
+ mapset = grass.gisenv()['MAPSET']
+ if self.isRaster:
+ ret = gcmd.RunCommand('r.proj',
+ quiet = True,
+ read = True,
+ flags = 'l',
+ dbase = dbase,
+ location = location,
+ mapset = mapset)
+ else:
+ ret = gcmd.RunCommand('v.proj',
+ quiet = True,
+ read = True,
+ flags = 'l',
+ dbase = dbase,
+ location = location,
+ mapset = mapset)
+ listMaps = list()
+ if ret:
+ for line in ret.splitlines():
+ listMaps.append(line.strip())
+
+ self.SetItems(listMaps)
+ self.SetValue('')
Modified: grass/trunk/gui/wxpython/gui_modules/menuform.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/menuform.py 2010-11-06 13:13:35 UTC (rev 44183)
+++ grass/trunk/gui/wxpython/gui_modules/menuform.py 2010-11-06 13:15:24 UTC (rev 44184)
@@ -313,6 +313,27 @@
if pGroup:
self.data[win.Insert] = { 'group' : pGroup.get('value', '')}
+ elif name == 'LocationSelect':
+ pDbase = self.task.get_param('dbase', element='element', raiseError=False)
+ if pDbase:
+ self.data[win.UpdateItems] = { 'dbase' : pDbase.get('value', '')}
+
+ elif name == 'MapsetSelect':
+ pDbase = self.task.get_param('dbase', element='element', raiseError=False)
+ pLocation = self.task.get_param('location', element='element', raiseError=False)
+ if pDbase and pLocation:
+ self.data[win.UpdateItems] = { 'dbase' : pDbase.get('value', ''),
+ 'location' : pLocation.get('value', '')}
+
+ elif name == 'ProjSelect':
+ pDbase = self.task.get_param('dbase', element='element', raiseError=False)
+ pLocation = self.task.get_param('location', element='element', raiseError=False)
+ pMapset = self.task.get_param('mapset', element='element', raiseError=False)
+ if pDbase and pLocation and pMapset:
+ self.data[win.UpdateItems] = { 'dbase' : pDbase.get('value', ''),
+ 'location' : pLocation.get('value', ''),
+ 'mapset' : pMapset.get('value', '')}
+
def UpdateDialog(parent, event, eventId, task):
return UpdateThread(parent, event, eventId, task)
@@ -1378,7 +1399,10 @@
'dbtable',
'dbcolumn',
'layer',
- 'layer_all') and \
+ 'layer_all',
+ 'location',
+ 'mapset',
+ 'dbase') and \
p.get('element', '') != 'file':
if p.get('multiple', 'no') == 'yes':
multiple = True
@@ -1388,21 +1412,36 @@
mapsets = [grass.gisenv()['MAPSET'],]
else:
mapsets = None
- selection = gselect.Select(parent=which_panel, id=wx.ID_ANY,
- size=globalvar.DIALOG_GSELECT_SIZE,
- type=p.get('element', ''),
- multiple=multiple, mapsets=mapsets)
+ if self.task.name in ('r.proj', 'v.proj') \
+ and p.get('name', '') == 'input':
+ if self.task.name == 'r.proj':
+ isRaster = True
+ else:
+ isRaster = False
+ selection = gselect.ProjSelect(parent=which_panel,
+ isRaster = isRaster)
+ p['wxId'] = [ selection.GetId(), ]
+ selection.Bind(wx.EVT_COMBOBOX, self.OnSetValue)
+ formatSelector = False
+ selection.Bind(wx.EVT_TEXT, self.OnUpdateSelection)
+ else:
+ selection = gselect.Select(parent=which_panel, id=wx.ID_ANY,
+ size=globalvar.DIALOG_GSELECT_SIZE,
+ type=p.get('element', ''),
+ multiple=multiple, mapsets=mapsets)
+ formatSelector = True
+ # A select.Select is a combobox with two children: a textctl and a popupwindow;
+ # we target the textctl here
+ p['wxId'] = [selection.GetChildren()[0].GetId(), ]
+ selection.GetChildren()[0].Bind(wx.EVT_TEXT, self.OnSetValue)
+
if p.get('value','') != '':
selection.SetValue(p['value']) # parameter previously set
- # A select.Select is a combobox with two children: a textctl and a popupwindow;
- # we target the textctl here
- p['wxId'] = [selection.GetChildren()[0].GetId(), ]
- selection.GetChildren()[0].Bind(wx.EVT_TEXT, self.OnSetValue)
if p.get('prompt', '') == 'vector':
selection.Bind(wx.EVT_TEXT, self.OnUpdateSelection)
- if p.get('age', '') == 'old':
+ if formatSelector and p.get('age', '') == 'old':
# OGR supported (read-only)
self.hsizer = wx.BoxSizer(wx.HORIZONTAL)
@@ -1468,12 +1507,19 @@
'dbtable',
'dbcolumn',
'layer',
- 'layer_all'):
+ 'layer_all',
+ 'location',
+ 'mapset',
+ 'dbase'):
if p.get('multiple', 'no') == 'yes':
win = wx.TextCtrl(parent=which_panel, value = p.get('default',''),
size=globalvar.DIALOG_TEXTCTRL_SIZE)
win.Bind(wx.EVT_TEXT, self.OnSetValue)
else:
+ value = p.get('value', '')
+ if not value:
+ value = p.get('default', '')
+
if p.get('prompt', '') in ('layer',
'layer_all'):
if p.get('prompt', '') == 'layer_all':
@@ -1504,18 +1550,12 @@
border = 5)
elif p.get('prompt', '') == 'dbdriver':
- value = p.get('value', '')
- if not value:
- value = p.get('default', '')
win = gselect.DriverSelect(parent = which_panel,
choices = p.get('values', []),
value = value)
win.Bind(wx.EVT_COMBOBOX, self.OnUpdateSelection)
win.Bind(wx.EVT_COMBOBOX, self.OnSetValue)
elif p.get('prompt', '') == 'dbname':
- value = p.get('value', '')
- if not value:
- value = p.get('default', '')
win = gselect.DatabaseSelect(parent = which_panel,
value = value)
win.Bind(wx.EVT_TEXT, self.OnUpdateSelection)
@@ -1530,19 +1570,35 @@
size=globalvar.DIALOG_TEXTCTRL_SIZE)
win.Bind(wx.EVT_TEXT, self.OnSetValue)
elif p.get('prompt', '') == 'dbcolumn':
- value = p.get('value', '')
- if not value:
- value = p.get('default', '')
win = gselect.ColumnSelect(parent = which_panel,
value = value,
param = p)
win.Bind(wx.EVT_COMBOBOX, self.OnSetValue)
win.Bind(wx.EVT_TEXT, self.OnSetValue)
- try:
- p['wxId'] = [ win.GetId(), ]
- except AttributeError:
- pass
+ elif p.get('prompt', '') == 'location':
+ win = gselect.LocationSelect(parent = which_panel,
+ value = value)
+ win.Bind(wx.EVT_COMBOBOX, self.OnUpdateSelection)
+ win.Bind(wx.EVT_COMBOBOX, self.OnSetValue)
+
+ elif p.get('prompt', '') == 'mapset':
+ win = gselect.MapsetSelect(parent = which_panel,
+ value = value)
+ win.Bind(wx.EVT_COMBOBOX, self.OnUpdateSelection)
+ win.Bind(wx.EVT_COMBOBOX, self.OnSetValue)
+
+ elif p.get('prompt', '') == 'dbase':
+ win = gselect.DbaseSelect(parent = which_panel,
+ changeCallback=self.OnSetValue)
+ win.Bind(wx.EVT_TEXT, self.OnUpdateSelection)
+ p['wxId'] = [ win.GetChildren()[1].GetId() ]
+
+ if not p.has_key('wxId'):
+ try:
+ p['wxId'] = [ win.GetId(), ]
+ except AttributeError:
+ pass
which_sizer.Add(item=win, proportion=0,
flag=wx.ADJUST_MINSIZE | wx.BOTTOM | wx.LEFT, border=5)
@@ -1661,6 +1717,9 @@
pColumn = []
pGroup = None
pSubGroup = None
+ pDbase = None
+ pLocation = None
+ pMapset = None
for p in self.task.params:
if p.get('gisprompt', False) == False:
continue
@@ -1679,7 +1738,7 @@
continue
prompt = p.get('element', '')
- if prompt == 'vector':
+ if prompt in ('cell', 'vector'):
name = p.get('name', '')
if name in ('map', 'input'):
pMap = p
@@ -1697,6 +1756,12 @@
pGroup = p
elif prompt == 'subgroup':
pSubGroup = p
+ elif prompt == 'dbase':
+ pDbase = p
+ elif prompt == 'location':
+ pLocation = p
+ elif prompt == 'mapset':
+ pMapset = p
# collect ids
pColumnIds = []
@@ -1726,14 +1791,22 @@
if pGroup and pSubGroup:
pGroup['wxId-bind'] = pSubGroup['wxId']
+
+ if pDbase and pLocation:
+ pDbase['wxId-bind'] = pLocation['wxId']
+
+ if pLocation and pMapset:
+ pLocation['wxId-bind'] = pMapset['wxId']
+ if pLocation and pMapset and pMap:
+ pLocation['wxId-bind'] = pMap['wxId']
+ pMapset['wxId-bind'] = pMap['wxId']
+
#
# determine panel size
#
maxsizes = (0,0)
for section in sections:
- # tabsizer[section].SetSizeHints( tab[section] )
- #tab[section].SetAutoLayout(True)
tab[section].SetSizer( tabsizer[section] )
tabsizer[section].Fit( tab[section] )
tab[section].Layout()
@@ -1745,16 +1818,13 @@
self.constrained_size = (min(600, maxsizes[0]) + 25, min(400, maxsizes[1]) + 25)
for section in sections:
tab[section].SetMinSize( (self.constrained_size[0], self.panelMinHeight) )
- # tab[section].SetMinSize( constrained_size )
-
+
if self.manual_tab.IsLoaded():
self.manual_tab.SetMinSize( (self.constrained_size[0], self.panelMinHeight) )
self.SetSizer( panelsizer )
panelsizer.Fit(self.notebook)
-
- self.hasMain = tab.has_key( _('Required') ) # publish, to enclosing Frame for instance
-
+
self.Bind(EVT_DIALOG_UPDATE, self.OnUpdateDialog)
def OnFileText(self, event):
@@ -1957,7 +2027,8 @@
break
if found:
- if name in ('LayerSelect', 'DriverSelect', 'TableSelect'):
+ if name in ('LayerSelect', 'DriverSelect', 'TableSelect',
+ 'LocationSelect', 'MapsetSelect'):
porf['value'] = me.GetStringSelection()
elif name == 'GdalSelect':
porf['value'] = event.dsn
@@ -1965,7 +2036,7 @@
porf['parameterized'] = me.IsChecked()
else:
porf['value'] = me.GetValue()
-
+
self.OnUpdateValues(event)
event.Skip()
Modified: grass/trunk/raster/r.proj/main.c
===================================================================
--- grass/trunk/raster/r.proj/main.c 2010-11-06 13:13:35 UTC (rev 44183)
+++ grass/trunk/raster/r.proj/main.c 2010-11-06 13:15:24 UTC (rev 44184)
@@ -144,34 +144,45 @@
module = G_define_module();
G_add_keyword(_("raster"));
G_add_keyword(_("projection"));
+ G_add_keyword(_("transformation"));
module->description =
_("Re-projects a raster map from one location to the current location.");
inmap = G_define_standard_option(G_OPT_R_INPUT);
inmap->description = _("Name of input raster map to re-project");
inmap->required = NO;
+ inmap->guisection = _("Input");
inlocation = G_define_option();
inlocation->key = "location";
inlocation->type = TYPE_STRING;
inlocation->required = YES;
- inlocation->description = _("Location of input raster map");
+ inlocation->description = _("Location containing input raster map");
+ inlocation->gisprompt = "old,location,location";
+ inlocation->key_desc = "name";
imapset = G_define_option();
imapset->key = "mapset";
imapset->type = TYPE_STRING;
imapset->required = NO;
- imapset->description = _("Mapset of input raster map");
+ imapset->description = _("Mapset containing input raster map");
+ imapset->gisprompt = "old,mapset,mapset";
+ imapset->key_desc = "name";
+ imapset->guisection = _("Input");
indbase = G_define_option();
indbase->key = "dbase";
indbase->type = TYPE_STRING;
indbase->required = NO;
indbase->description = _("Path to GRASS database of input location");
+ indbase->gisprompt = "old,dbase,dbase";
+ indbase->key_desc = "path";
+ indbase->guisection = _("Input");
outmap = G_define_standard_option(G_OPT_R_OUTPUT);
outmap->required = NO;
outmap->description = _("Name for output raster map (default: input)");
+ outmap->guisection = _("Output");
ipolname = make_ipol_list();
@@ -276,11 +287,17 @@
/* if requested, list the raster maps in source location - MN 5/2001 */
if (list->answer) {
- if (isatty(0)) /* check if on command line */
- G_message(_("Checking location <%s>, mapset <%s>..."),
- inlocation->answer, setname);
- G_list_element("cell", "raster", setname, 0);
- exit(EXIT_SUCCESS); /* leave r.proj after listing */
+ int i;
+ char **list;
+ G_verbose_message(_("Checking location <%s> mapset <%s>"),
+ inlocation->answer, imapset->answer);
+ list = G_list(G_ELEMENT_RASTER, G__getenv("GISDBASE"),
+ G__getenv("LOCATION_NAME"), imapset->answer);
+ for (i = 0; list[i]; i++) {
+ fprintf(stdout, "%s\n", list[i]);
+ }
+ fflush(stdout);
+ exit(EXIT_SUCCESS); /* leave v.proj after listing */
}
if (!inmap->answer)
@@ -422,7 +439,7 @@
G_adjust_Cell_head(&outcellhd, 0, 0);
Rast_set_output_window(&outcellhd);
- G_message("");
+ G_message(" ");
G_message(_("Input:"));
G_message(_("Cols: %d (%d)"), incellhd.cols, icols);
G_message(_("Rows: %d (%d)"), incellhd.rows, irows);
@@ -432,7 +449,7 @@
G_message(_("East: %f (%f)"), incellhd.east, ieast);
G_message(_("EW-res: %f"), incellhd.ew_res);
G_message(_("NS-res: %f"), incellhd.ns_res);
- G_message("");
+ G_message(" ");
G_message(_("Output:"));
G_message(_("Cols: %d (%d)"), outcellhd.cols, ocols);
@@ -443,7 +460,7 @@
G_message(_("East: %f (%f)"), outcellhd.east, oeast);
G_message(_("EW-res: %f"), outcellhd.ew_res);
G_message(_("NS-res: %f"), outcellhd.ns_res);
- G_message("");
+ G_message(" ");
/* open and read the relevant parts of the input map and close it */
G__switch_env();
@@ -516,7 +533,7 @@
Rast_command_history(&history);
Rast_write_history(mapname, &history);
- G_done_msg("");
+ G_done_msg(" ");
exit(EXIT_SUCCESS);
}
Modified: grass/trunk/vector/v.proj/main.c
===================================================================
--- grass/trunk/vector/v.proj/main.c 2010-11-06 13:13:35 UTC (rev 44183)
+++ grass/trunk/vector/v.proj/main.c 2010-11-06 13:15:24 UTC (rev 44184)
@@ -62,34 +62,45 @@
module = G_define_module();
G_add_keyword(_("vector"));
G_add_keyword(_("projection"));
- module->description = _("Allows projection conversion of vector maps.");
+ G_add_keyword(_("transformation"));
+ module->description = _("Re-projects a vector map from one location to the current location.");
/* set up the options and flags for the command line parser */
mapopt = G_define_standard_option(G_OPT_V_INPUT);
- mapopt->gisprompt = NULL;
mapopt->required = NO;
-
+ mapopt->guisection = _("Input");
+
ilocopt = G_define_option();
ilocopt->key = "location";
ilocopt->type = TYPE_STRING;
ilocopt->required = YES;
ilocopt->description = _("Location containing input vector map");
-
+ ilocopt->gisprompt = "old,location,location";
+ ilocopt->key_desc = "name";
+
isetopt = G_define_option();
isetopt->key = "mapset";
isetopt->type = TYPE_STRING;
isetopt->required = NO;
isetopt->description = _("Mapset containing input vector map");
+ isetopt->gisprompt = "old,mapset,mapset";
+ isetopt->key_desc = "name";
+ isetopt->guisection = _("Input");
ibaseopt = G_define_option();
ibaseopt->key = "dbase";
ibaseopt->type = TYPE_STRING;
ibaseopt->required = NO;
ibaseopt->description = _("Path to GRASS database of input location");
+ ibaseopt->gisprompt = "old,dbase,dbase";
+ ibaseopt->key_desc = "path";
+ ibaseopt->guisection = _("Input");
omapopt = G_define_standard_option(G_OPT_V_OUTPUT);
omapopt->required = NO;
+ omapopt->description = _("Name for output vector map (default: input)");
+ omapopt->guisection = _("Output");
flag.list = G_define_flag();
flag.list->key = 'l';
@@ -101,6 +112,7 @@
flag.transformz->label =
_("Assume z co-ordinate is ellipsoidal height and "
"transform if possible");
+ flag.transformz->guisection = _("Output");
/* The parser checks if the map already exists in current mapset,
we switch out the check and do it
@@ -154,9 +166,16 @@
if (stat >= 0) { /* yes, we can access the mapset */
/* if requested, list the vector maps in source location - MN 5/2001 */
if (flag.list->answer) {
+ int i;
+ char **list;
G_verbose_message(_("Checking location <%s> mapset <%s>"),
iloc_name, iset_name);
- G_list_element("vector", "vector", iset_name, 0);
+ list = G_list(G_ELEMENT_VECTOR, G__getenv("GISDBASE"),
+ G__getenv("LOCATION_NAME"), iset_name);
+ for (i = 0; list[i]; i++) {
+ fprintf(stdout, "%s\n", list[i]);
+ }
+ fflush(stdout);
exit(EXIT_SUCCESS); /* leave v.proj after listing */
}
More information about the grass-commit
mailing list