Skip to content

Commit

Permalink
wxGUI: VectorSelect implemented
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.osgeo.org/grass/grass/trunk@37998 15284696-431f-4ddb-bdfa-cd5b030d7da7
  • Loading branch information
landam committed Jun 20, 2009
1 parent 3e3983e commit 15883b5
Showing 1 changed file with 64 additions and 20 deletions.
84 changes: 64 additions & 20 deletions gui/wxpython/gui_modules/gselect.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Classes:
- Select
- VectorSelect
- TreeCrtlComboPopup
- VectorDBInfo
- LayerSelect
Expand Down Expand Up @@ -34,10 +35,9 @@
from preferences import globalSettings as UserSettings

class Select(wx.combo.ComboCtrl):
def __init__(self, parent, id, size,
def __init__(self, parent, id, size = globalvar.DIALOG_GSELECT_SIZE,
type=None, multiple=False, mapsets=None, exceptOf=[]):
"""
Custom control to create a ComboBox with a tree control
"""!Custom control to create a ComboBox with a tree control
to display and select GIS elements within acessible mapsets.
Elements can be selected with mouse. Can allow multiple selections, when
argument multiple=True. Multiple selections are separated by commas.
Expand All @@ -51,22 +51,59 @@ def __init__(self, parent, id, size,
self.SetPopupControl(self.tcp)
self.SetPopupExtents(0,100)
if type:
self.tcp.GetElementList(type, mapsets, exceptOf)
self.tcp.SetData(type = type, mapsets = mapsets,
exceptOf = exceptOf, multiple = multiple)

def SetElementList(self, type, mapsets = None, exceptOf = []):
self.tcp.seltree.DeleteAllItems()
self.tcp.GetElementList(type)
"""!Set element list
@param type GIS element type
@param mapsets list of acceptable mapsets (None for all in search path)
@param exceptOf list of GIS elements to be excluded"""
self.tcp.SetData(type = type, mapsets = mapsets,
exceptOf = exceptOf)

class VectorSelect(Select):
def __init__(self, parent, ftype, **kwargs):
"""!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,
type = 'vector', **kwargs)

# remove vector maps which do not contain given feature type
self.tcp.SetFilter(self.__filterElements)

def __filterElements(self, parentItem):
"""!Filter vector maps in given mapset"""
root = self.tcp.seltree.GetRootItem()
item, cookie = self.tcp.seltree.GetFirstChild(parentItem)
while item:
if self.tcp.seltree.GetItemParent(item) != root:
# skip Mapset items
vectorName = self.tcp.seltree.GetItemText(item)
try:
if int(grass.vector_info_topo(vectorName)['points']) < 1:
self.tcp.seltree.Delete(item)
except KeyError:
self.tcp.seltree.Delete(item)

if not item:
item, cookie = self.tcp.seltree.GetNextChild(parentItem, cookie)
continue

if self.tcp.seltree.ItemHasChildren(item):
item = self.__filterElements(item)

item, cookie = self.tcp.seltree.GetNextChild(parentItem, cookie)

class TreeCtrlComboPopup(wx.combo.ComboPopup):
"""
Create a tree ComboBox for selecting maps and other GIS elements
"""!Create a tree ComboBox for selecting maps and other GIS elements
in accessible mapsets within the current location
"""

# overridden ComboPopup methods
def Init(self):
self.value = [] # for multiple is False -> len(self.value) in [0,1]
Expand All @@ -76,6 +113,8 @@ def Init(self):
self.mapsets = []
self.exceptOf = []

self.SetFilter(None)

def Create(self, parent):
self.seltree = wx.TreeCtrl(parent, style=wx.TR_HIDE_ROOT
|wx.TR_HAS_BUTTONS
Expand Down Expand Up @@ -117,12 +156,18 @@ def GetStringValue(self):

return str

def SetFilter(self, filter):
"""!Set filter for GIS elements, see e.g. VectorSelect"""
self.filterElements = filter

def OnPopup(self):
"""!Limited only for first selected"""
# update list
self.seltree.DeleteAllItems()
self.GetElementList(self.type, self.mapsets, self.exceptOf)

if self.filterElements:
self.filterElements(self.seltree.GetRootItem())

if len(self.value) > 0:
root = self.seltree.GetRootItem()
if not root:
Expand All @@ -148,9 +193,12 @@ def GetAdjustedSize(self, minWidth, prefHeight, maxHeight):
return wx.Size(minWidth, min(200, maxHeight))

def GetElementList(self, element, mapsets=None, exceptOf=[]):
"""
Get list of GIS elements in accessible mapsets and display as tree
"""!Get list of GIS elements in accessible mapsets and display as tree
with all relevant elements displayed beneath each mapset branch
@param element GIS element
@param mapsets list of acceptable mapsets (None for all mapsets in search path)
@param exceptOf list of GIS elements to be excluded
"""
# get current mapset
curr_mapset = grass.gisenv()['MAPSET']
Expand Down Expand Up @@ -429,8 +477,7 @@ def GetTableDesc(self, table):
return self.tables[table]

class LayerSelect(wx.Choice):
"""
Creates combo box for selecting data layers defined for vector.
"""!Creates combo box for selecting data layers defined for vector.
The 'layer' terminology is likely to change for GRASS 7
"""
def __init__(self, parent,
Expand Down Expand Up @@ -477,8 +524,7 @@ def InsertLayers(self, vector):
self.SetStringSelection(str(self.default))

class DriverSelect(wx.ComboBox):
"""
Creates combo box for selecting database driver.
"""!Creates combo box for selecting database driver.
"""
def __init__(self, parent, choices, value,
id=wx.ID_ANY, pos=wx.DefaultPosition,
Expand All @@ -492,8 +538,7 @@ def __init__(self, parent, choices, value,
self.SetStringSelection(value)

class DatabaseSelect(wx.TextCtrl):
"""
Creates combo box for selecting database driver.
"""!Creates combo box for selecting database driver.
"""
def __init__(self, parent, value='',
id=wx.ID_ANY, pos=wx.DefaultPosition,
Expand All @@ -504,8 +549,7 @@ def __init__(self, parent, value='',
self.SetName("DatabaseSelect")

class TableSelect(wx.ComboBox):
"""
Creates combo box for selecting attribute tables from the database
"""!Creates combo box for selecting attribute tables from the database
"""
def __init__(self, parent,
id=wx.ID_ANY, value='', pos=wx.DefaultPosition,
Expand Down

0 comments on commit 15883b5

Please sign in to comment.