[GRASS-SVN] r46853 -
grass/branches/releasebranch_6_4/gui/wxpython/gui_modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Jun 29 10:28:58 EDT 2011
Author: mmetz
Date: 2011-06-29 07:28:58 -0700 (Wed, 29 Jun 2011)
New Revision: 46853
Modified:
grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/gselect.py
grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/menuform.py
Log:
improve vector layer selection
Modified: grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/gselect.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/gselect.py 2011-06-29 14:14:27 UTC (rev 46852)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/gselect.py 2011-06-29 14:28:58 UTC (rev 46853)
@@ -623,56 +623,47 @@
"""
return self.tables[table]
-class LayerSelect(wx.Choice):
+class LayerSelect(wx.ComboBox):
"""!Creates combo box for selecting data layers defined for vector.
The 'layer' terminology is likely to change for GRASS 7
"""
def __init__(self, parent,
id=wx.ID_ANY, pos=wx.DefaultPosition,
size=globalvar.DIALOG_LAYER_SIZE,
- vector=None, choices=[], initial=['1'], default=None):
+ vector=None, choices=[], initial=[], default=None):
super(LayerSelect, self).__init__(parent, id, pos=pos, size=size,
choices=choices)
- # initial choices (force '1' to be included)
self.initial = initial
- if '1' not in self.initial:
- self.initial.append('1')
+ self.SetName("LayerSelect")
+
# default value
self.default = default
+
+ self.InsertLayers(vector = vector)
- self.SetName("LayerSelect")
-
- if len(choices) > 1:
- return
-
- if vector:
- self.InsertLayers(vector)
- else:
- self.SetItems(self.initial)
- self.SetStringSelection('1')
-
def InsertLayers(self, vector):
"""!Insert layers for a vector into the layer combobox"""
- layerchoices = utils.GetVectorNumberOfLayers(self, vector)
+ if vector:
+ layers = utils.GetVectorNumberOfLayers(self, vector)
+ else:
+ layers = list()
+
for layer in self.initial:
- if layer in layerchoices:
+ if layer in layers:
continue
- layerchoices.append(layer)
-
- if len(layerchoices) == 0:
- layerchoices.insert(0, '-1')
- elif len(layerchoices) > 1:
- self.SetItems(layerchoices)
- self.SetStringSelection('1')
- elif len(layerchoices) == 1:
- self.SetItems(layerchoices)
- self.SetStringSelection(layerchoices[0])
-
+ layers.append(layer)
+
if self.default:
- self.SetStringSelection(str(self.default))
+ if len(layers) == 0:
+ layers.insert(0, str(self.default))
+ elif self.default not in layers:
+ layers.append(self.default)
+
+ if len(layers) >= 1:
+ self.SetItems(layers)
class DriverSelect(wx.ComboBox):
"""!Creates combo box for selecting database driver.
Modified: grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/menuform.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/menuform.py 2011-06-29 14:14:27 UTC (rev 46852)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/menuform.py 2011-06-29 14:28:58 UTC (rev 46853)
@@ -238,9 +238,9 @@
pLayer = self.task.get_param('layer', element='element', raiseError=False)
if pLayer:
if pLayer.get('value', '') != '':
- layer = int(pLayer.get('value', 1))
+ layer = pLayer.get('value', '')
else:
- layer = int(pLayer.get('default', 1))
+ layer = pLayer.get('default', '')
else:
layer = 1
@@ -652,7 +652,7 @@
self.goutput.RunCmd(cmd, onDone = self.OnDone)
except AttributeError, e:
- print >> sys.stderr, "%s: Propably not running in wxgui.py session?" % (e)
+ print >> sys.stderr, "%s: Probably not running in wxgui.py session?" % (e)
print >> sys.stderr, "parent window is: %s" % (str(self.parent))
else:
gcmd.Command(cmd)
@@ -1128,31 +1128,40 @@
size = globalvar.DIALOG_TEXTCTRL_SIZE)
win.Bind(wx.EVT_TEXT, self.OnSetValue)
else:
- value = p.get('value', '')
- if not value:
- value = p.get('default', '')
+ value = self._getValue(p)
if p.get('prompt', '') in ('layer',
'layer_all',
'layer_zero'):
- initial = ['1']
- if p.get('prompt', '') == 'layer_all':
- initial.insert(0, '-1')
- if p.get('prompt', '') == 'layer_zero':
- initial.insert(0, '0')
if p.get('age', 'old_layer') == 'old_layer':
+ initial = list()
+ if p.get('prompt', '') == 'layer_all':
+ initial.insert(0, '-1')
+ elif p.get('prompt', '') == 'layer_zero':
+ initial.insert(0, '0')
+ lyrvalue = p.get('default')
+ if lyrvalue != '':
+ if lyrvalue not in initial:
+ initial.append(str(lyrvalue))
+ lyrvalue = p.get('value')
+ if lyrvalue != '':
+ if lyrvalue not in initial:
+ initial.append(str(lyrvalue))
+
win = gselect.LayerSelect(parent=which_panel,
initial=initial,
default=p['default'])
p['wxGetValue'] = win.GetStringSelection
- win.Bind(wx.EVT_CHOICE, self.OnUpdateSelection)
- win.Bind(wx.EVT_CHOICE, self.OnSetValue)
+ win.Bind(wx.EVT_TEXT, self.OnUpdateSelection)
+ win.Bind(wx.EVT_TEXT, self.OnSetValue)
+ win.SetValue(str(value)) # default or previously set value
else:
win = wx.SpinCtrl(parent=which_panel, id=wx.ID_ANY,
min=1, max=100, initial=int(p['default']))
win.Bind(wx.EVT_SPINCTRL, self.OnSetValue)
-
+ win.SetValue(int(value)) # default or previously set value
+
elif p.get('prompt', '') == 'dbdriver':
win = gselect.DriverSelect(parent = which_panel,
choices = p.get('values', []),
@@ -1575,13 +1584,15 @@
if not found:
return
- if name in ('LayerSelect', 'DriverSelect', 'TableSelect',
+ if name in ('DriverSelect', 'TableSelect',
'LocationSelect', 'MapsetSelect', 'ProjSelect'):
porf['value'] = me.GetStringSelection()
elif name == 'GdalSelect':
porf['value'] = event.dsn
elif name == 'ModelParam':
porf['parameterized'] = me.IsChecked()
+ elif name == 'LayerSelect':
+ porf['value'] = me.GetValue()
else:
porf['value'] = me.GetValue()
More information about the grass-commit
mailing list