[GRASS-SVN] r46814 - grass/trunk/gui/wxpython/gui_modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Jun 28 03:19:21 EDT 2011
Author: mmetz
Date: 2011-06-28 00:19:21 -0700 (Tue, 28 Jun 2011)
New Revision: 46814
Modified:
grass/trunk/gui/wxpython/gui_modules/gselect.py
grass/trunk/gui/wxpython/gui_modules/menuform.py
Log:
fix crash with native vectors, simplify layer input option
Modified: grass/trunk/gui/wxpython/gui_modules/gselect.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gselect.py 2011-06-28 07:04:41 UTC (rev 46813)
+++ grass/trunk/gui/wxpython/gui_modules/gselect.py 2011-06-28 07:19:21 UTC (rev 46814)
@@ -9,7 +9,6 @@
- TreeCrtlComboPopup
- VectorDBInfo
- LayerSelect
- - LayerNameSelect
- DriverSelect
- DatabaseSelect
- ColumnSelect
@@ -599,7 +598,7 @@
@param layer vector layer number
"""
- return self.layers[layer]['key']
+ return str(self.layers[layer]['key'])
def GetTable(self, layer):
"""!Get table name of given layer
@@ -624,74 +623,26 @@
"""
return self.tables[table]
-class LayerSelect(wx.Choice):
- def __init__(self, parent, id = wx.ID_ANY,
- size=globalvar.DIALOG_LAYER_SIZE,
- vector = None, choices = [], all = False, default = None):
- """!Creates widget for selecting vector map layer numbers
+class LayerSelect(wx.ComboBox):
+ def __init__(self, parent, id = wx.ID_ANY,
+ size = globalvar.DIALOG_COMBOBOX_SIZE,
+ vector = None, dsn = None, choices = [], all = False, default = None):
+ """!Creates combo box for selecting vector map layer names
- @param vector vector map name or None
- @param choices list of predefined choices
- @param all adds layer '-1' (e.g., for d.vect)
- @param default default layer number
+ @param vector vector map name (native or connected via v.external)
+ @param dsn OGR data source name
"""
+ super(LayerSelect, self).__init__(parent, id, size = size, choices = choices)
- super(LayerSelect, self).__init__(parent, id, size = size,
- choices = choices)
-
self.all = all
self.SetName("LayerSelect")
# default value
self.default = default
-
- if len(choices) > 1:
- return
- if vector:
- self.InsertLayers(vector)
- else:
- if all:
- self.SetItems(['-1', '1'])
- else:
- self.SetItems(['1'])
- self.SetStringSelection('1')
+ self.InsertLayers(vector = vector, dsn = dsn)
- def InsertLayers(self, vector):
- """!Insert layers for a vector into the layer combobox"""
- layerchoices = utils.GetVectorNumberOfLayers(self, vector)
-
- if self.all or len(layerchoices) == 0:
- layerchoices.insert(0, '-1')
- if len(layerchoices) > 1:
- self.SetItems(layerchoices)
- self.SetStringSelection('1')
- elif len(layerchoices) == 1:
- self.SetItems(layerchoices)
- self.SetStringSelection(layerchoices[0])
-
- if self.default:
- self.SetStringSelection(str(self.default))
-
-class LayerNameSelect(wx.ComboBox):
- def __init__(self, parent, id = wx.ID_ANY,
- size = globalvar.DIALOG_COMBOBOX_SIZE,
- vector = None, dsn = None):
- """!Creates combo box for selecting vector map layer names
-
- @param vector vector map name (native or connected via v.external)
- @param dsn OGR data source name
- """
- super(LayerNameSelect, self).__init__(parent, id, size = size)
- self.SetName("LayerNameSelect")
-
- if vector:
- # -> native
- self.InsertLayers(vector = vector)
- elif dsn:
- self.InsertLayers(dsn = dsn)
-
def InsertLayers(self, vector = None, dsn = None):
"""!Insert layers for a vector into the layer combobox
@@ -701,9 +652,22 @@
@param dsn OGR data source name
"""
layers = list()
+ if self.all:
+ layers.append('-1')
+
if vector:
# TODO
- pass
+ ret = gcmd.RunCommand('v.db.connect',
+ read = True,
+ quiet = True,
+ fs = '|',
+ flags = 'g',
+ map = vector)
+ for line in ret.splitlines():
+ layerinfo = line.split('|')
+ layername = layerinfo[0].split('/')
+ layers.append(layername[len(layername) - 1])
+
elif dsn:
ret = gcmd.RunCommand('v.in.ogr',
read = True,
@@ -712,9 +676,14 @@
dsn = dsn)
if ret:
layers = ret.splitlines()
-
+
+ if len(layers) == 0:
+ if self.default == None:
+ layers.append('')
+ else:
+ layers.append(self.default)
self.SetItems(layers)
- self.SetSelection(0)
+ #self.SetSelection(0)
class DriverSelect(wx.ComboBox):
"""!Creates combo box for selecting database driver.
@@ -804,7 +773,7 @@
if vector:
self.InsertColumns(vector, layer)
-
+
def InsertColumns(self, vector, layer, excludeKey = False, type = None, dbInfo = None):
"""!Insert columns for a vector attribute table into the columns combobox
Modified: grass/trunk/gui/wxpython/gui_modules/menuform.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/menuform.py 2011-06-28 07:04:41 UTC (rev 46813)
+++ grass/trunk/gui/wxpython/gui_modules/menuform.py 2011-06-28 07:19:21 UTC (rev 46814)
@@ -223,8 +223,7 @@
map = layer = None
driver = db = table = None
- if name in ('LayerSelect', 'LayerNameSelect',
- 'ColumnSelect'):
+ if name in ('LayerSelect', 'ColumnSelect'):
if p.get('element', '') == 'vector': # -> vector
# get map name
map = p.get('value', '')
@@ -268,13 +267,8 @@
pTable = self.task.get_param('dbtable', element = 'element', raiseError = False)
if pTable:
table = pTable.get('value', '')
-
+
if name == 'LayerSelect':
- if map in cparams and not cparams[map]['layers']:
- win.InsertLayers(vector = map)
- cparams[map]['layers'] = win.GetItems()
-
- elif name == 'LayerNameSelect':
# determine format
native = True
for id in pMap['wxId']:
@@ -283,11 +277,17 @@
winVec.GetSelection() != 0:
native = False
break
- if not native:
- if map:
- self.data[win.InsertLayers] = { 'dsn' : map.rstrip('@OGR') }
- else:
- self.data[win.InsertLayers] = { }
+ # TODO: update only if needed
+ #if native:
+ # if map:
+ # self.data[win.InsertLayers] = { 'vector' : map }
+ # else:
+ # self.data[win.InsertLayers] = { }
+ #else:
+ # if map:
+ # self.data[win.InsertLayers] = { 'dsn' : map.rstrip('@OGR') }
+ # else:
+ # self.data[win.InsertLayers] = { }
elif name == 'TableSelect':
self.data[win.InsertTables] = { 'driver' : driver,
@@ -1563,28 +1563,21 @@
all = True
else:
all = False
- win = wx.BoxSizer(wx.HORIZONTAL)
if p.get('age', 'old') == 'old':
- win1 = gselect.LayerSelect(parent = which_panel,
+ win = gselect.LayerSelect(parent = which_panel,
all = all,
default = p['default'])
- win1.Bind(wx.EVT_CHOICE, self.OnUpdateSelection)
- win1.Bind(wx.EVT_CHOICE, self.OnSetValue)
+ win.Bind(wx.EVT_COMBOBOX, self.OnUpdateSelection)
+ win.Bind(wx.EVT_COMBOBOX, self.OnSetValue)
else:
- win1 = wx.SpinCtrl(parent = which_panel, id = wx.ID_ANY,
+ win = wx.SpinCtrl(parent = which_panel, id = wx.ID_ANY,
min = 1, max = 100, initial = int(p['default']))
- win1.Bind(wx.EVT_SPINCTRL, self.OnSetValue)
- win2 = gselect.LayerNameSelect(parent = which_panel)
- if p.get('value','') != '':
- win2.SetItems([p['value']])
- win2.SetSelection(0)
+ win.Bind(wx.EVT_SPINCTRL, self.OnSetValue)
+ if p.get('value','') == '':
+ win.SetItems([p['value']])
+ win.SetSelection(0)
- win2.Bind(wx.EVT_COMBOBOX, self.OnSetValue)
- p['wxId'] = [ win1.GetId(), win2.GetId() ]
- win.Add(item = win1, proportion = 0)
- win.Add(item = win2, proportion = 0,
- flag = wx.LEFT | wx.ALIGN_CENTER_VERTICAL,
- border = 5)
+ p['wxId'] = [ win.GetId() ]
elif p.get('prompt', '') == 'dbdriver':
win = gselect.DriverSelect(parent = which_panel,
More information about the grass-commit
mailing list