[GRASS-SVN] r33845 - grass/branches/develbranch_6/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Oct 12 06:48:12 EDT 2008


Author: martinl
Date: 2008-10-12 06:48:12 -0400 (Sun, 12 Oct 2008)
New Revision: 33845

Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_modules/gselect.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/menuform.py
Log:
wxGUI: layer/dbcolumn selection fixed


Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/gselect.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/gselect.py	2008-10-12 10:46:47 UTC (rev 33844)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/gselect.py	2008-10-12 10:48:12 UTC (rev 33845)
@@ -41,7 +41,11 @@
         """
         wx.combo.ComboCtrl.__init__(self, parent=parent, id=id, size=size)
 
+        self.GetChildren()[0].SetName("Select")
+        self.GetChildren()[0].type = type
+        
         self.tcp = TreeCtrlComboPopup()
+
         self.SetPopupControl(self.tcp)
         self.SetPopupExtents(0,100)
         self.tcp.GetElementList(type, mapsets, exceptOf)
@@ -104,6 +108,7 @@
         for value in self.value:
             str += value + ","
         str = str.rstrip(',')
+        
         return str
 
     def OnPopup(self):
@@ -417,18 +422,27 @@
 
         super(LayerSelect, self).__init__(parent, id, pos=pos, size=size,
                                           choices=choices)
+        self.SetName("LayerSelect")
 
-        if not vector:
+        if len(choices) > 1:
             return
 
-        self.InsertLayers(vector)
+        if vector:
+            self.InsertLayers(vector)
+        else:
+            self.SetItems(['1'])
+            self.SetSelection(0)
         
     def InsertLayers(self, vector):
         """Insert layers for a vector into the layer combobox"""
         layerchoices = VectorDBInfo(vector).layers.keys()
 
-        self.SetItems(map(str, layerchoices))
-        self.SetStringSelection('1')
+        if len(layerchoices) > 1:
+            self.SetItems(map(str, layerchoices))
+            self.SetStringSelection('1')
+        else:
+            self.SetItems(['1'])
+            self.SetSelection(0)
         
 class ColumnSelect(wx.ComboBox):
     """
@@ -437,24 +451,30 @@
     """
     def __init__(self, parent,
                  id=wx.ID_ANY, value='', pos=wx.DefaultPosition,
-                 size=wx.DefaultSize, vector=None, layer=1, choices=[]):
+                 size=globalvar.DIALOG_COMBOBOX_SIZE, vector=None,
+                 layer=1, choices=[]):
 
         super(ColumnSelect, self).__init__(parent, id, value, pos, size, choices,
                                            style=wx.CB_READONLY)
 
-        if not vector:
-            return
+        self.SetName("ColumnSelect")
 
-        self.InsertColumns(vector, layer)
+        if vector:
+            self.InsertColumns(vector, layer)
                 
     def InsertColumns(self, vector, layer):
         """Insert columns for a vector attribute table into the columns combobox"""
         dbInfo = VectorDBInfo(vector)
-        table = dbInfo.layers[int(layer)]['table']
-        columnchoices = dbInfo.tables[table]
-        #columnchoices.sort()
+        
+        try:
+            table = dbInfo.layers[int(layer)]['table']
+            columnchoices = dbInfo.tables[table]
+        except (KeyError, ValueError):
+            columnchoices = {}
+        
         self.SetItems(columnchoices.keys())
-
+        self.SetValue('')
+        
 class DbColumnSelect(wx.ComboBox):
     """
     Creates combo box for selecting columns from any table.

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/menuform.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/menuform.py	2008-10-12 10:46:47 UTC (rev 33844)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/menuform.py	2008-10-12 10:48:12 UTC (rev 33845)
@@ -192,15 +192,14 @@
         if grassModule is not None:
             xml.sax.parseString( getInterfaceDescription( grassModule ) , processTask( self ) )
 
-    def get_param(self, aParam, raiseError=True):
+    def get_param(self, value, element='name', raiseError=True):
         """Find and return a param by name."""
         for p in self.params:
-            lparam = len(aParam)
-            if p['name'] == aParam or \
-                    p['name'][:lparam] == aParam:
+            if p[element] == value:
                 return p
         if raiseError:
-            raise ValueError, _("Parameter not found: %s") % aParam
+            raise ValueError, _("Parameter not found: %s") % \
+                value
         else:
             return None
 
@@ -1123,25 +1122,33 @@
                                 flag=style, border=5)
                 p['wxId'] = txt3.GetId()
 
-            if p.get('type','string') == 'string' and p.get('gisprompt',False) == True:
+            #
+            # element selection tree combobox (maps, icons, regions, etc.)
+            #
+            if p.get('gisprompt', False) == True:
                 txt = wx.StaticText(parent=which_panel, label = title + ':')
                 self.label_id.append(txt.GetId())
                 which_sizer.Add(item=txt, proportion=0,
                                 flag=wx.ADJUST_MINSIZE | wx.RIGHT | wx.LEFT | wx.TOP, border=5)
-                # element selection tree combobox (maps, icons, regions, etc.)
-                if p.get('prompt','') not in ('color', 'dbcolumn', 'dbtable') and \
+                # GIS element entry
+                if p.get('prompt','') not in ('color',
+                                              'dbcolumn',
+                                              'dbtable',
+                                              'layer') and \
                        p.get('element', '') != 'file':
-                    if p.get('multiple','no') == 'yes':
+                    if p.get('multiple', 'no') == 'yes':
                         multiple = True
                     else:
                         multiple = False
-                    if p.get('age','') == 'new':
+                    if p.get('age', '') == 'new':
                         mapsets = [grassenv.GetGRASSVariable('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)
+                        
+                    selection = gselect.Select(parent=which_panel, id=wx.ID_ANY,
+                                               size=globalvar.DIALOG_GSELECT_SIZE,
+                                               type=p.get('element', ''),
+                                               multiple=multiple, mapsets=mapsets)
                     if p.get('value','') != '':
                         selection.SetValue(p['value']) # parameter previously set
 
@@ -1151,28 +1158,29 @@
                     # we target the textctl here
                     p['wxId'] = selection.GetChildren()[0].GetId()
                     selection.Bind(wx.EVT_TEXT, self.OnSetValue)
-                # dbcolumn entry
-                elif p.get('prompt','') in ('dbcolumn', 'dbtable'):
-                    if p.get('age', 'old') == 'old' and \
-                            p.get('multiple', 'no') == 'no':
-                        style = wx.CB_SIMPLE | wx.CB_READONLY
+                    if p.get('prompt', '') == 'vector':
+                        selection.Bind(wx.EVT_TEXT, self.OnUpdateSelection)
+                    
+                # layer, dbcolumn, dbtable entry
+                elif p.get('prompt', '') in ('dbcolumn',
+                                             'dbtable',
+                                             'layer'):
+                    if p.get('prompt', '') == 'layer':
+                        win = gselect.LayerSelect(parent=which_panel)
+                        p['wxGetValue'] = win.GetStringSelection
+                        win.Bind(wx.EVT_CHOICE, self.OnUpdateSelection)
+                        win.Bind(wx.EVT_CHOICE, self.OnSetValue)
                     else:
-                        style = wx.CB_SIMPLE
-                    columns = wx.ComboBox(parent=which_panel, id=wx.ID_ANY,
-                                          size=globalvar.DIALOG_COMBOBOX_SIZE,
-                                          style=style,
-                                          choices=[])
-                    p['wxId'] = columns.GetId()
-                    p['wxGetValue'] = columns.GetStringSelection
-                    if p.get('prompt', '') == 'dbcolumn':
-                        columns.Bind(wx.EVT_ENTER_WINDOW, self.OnDbColumn)
-                    else:
-                        columns.Bind(wx.EVT_ENTER_WINDOW, self.OnDbTable)
-                    columns.Bind(wx.EVT_COMBOBOX, self.OnSetValue)
-                    which_sizer.Add(item=columns, proportion=0,
+                        win = gselect.ColumnSelect(parent=which_panel)
+                        p['wxGetValue'] = win.GetStringSelection
+                        win.Bind(wx.EVT_COMBOBOX, self.OnSetValue)
+                    
+                    p['wxId'] = win.GetId()
+                    
+                    which_sizer.Add(item=win, proportion=0,
                                     flag=wx.ADJUST_MINSIZE | wx.BOTTOM | wx.LEFT, border=5)
                 # color entry
-                elif p.get('prompt','') == 'color':
+                elif p.get('prompt', '') == 'color':
                     # Heuristic way of finding whether transparent is allowed
                     handle_transparency =  'none' in p.get('description', '')
                     default_color = (200,200,200)
@@ -1244,7 +1252,33 @@
             if p == first_param:
                 if type(p['wxId']) == type(1):
                     self.FindWindowById(p['wxId']).SetFocus()
+        
+        #
+        # set widget relations for OnUpdateSelection
+        #
+        pMap = None
+        pLayer = None
+        pColumn = []
+        for p in self.task.params:
+            if p.get('gisprompt', False) == False:
+                continue
             
+            prompt = p.get('prompt', '')
+            
+            if prompt == 'vector':
+                name = p.get('name', '')
+                if name in ('map', 'input'):
+                    pMap = p
+            elif prompt == 'layer':
+                pLayer = p
+            elif prompt == 'dbcolumn':
+                pColumn.append(p['wxId'])
+        
+        if pMap:
+            pMap['wxId-bind'] = [pLayer['wxId'], ] + pColumn
+        if pLayer:
+            pLayer['wxId-bind'] = pColumn
+        
 	#
 	# determine panel size
 	#
@@ -1376,6 +1410,7 @@
         """
         myId = event.GetId()
         me = wx.FindWindowById( myId )
+        
         for porf in self.task.params + self.task.flags:
             if 'wxId' in porf and type( porf[ 'wxId' ] ) == type( 1 ) and porf['wxId'] == myId:
                 if porf.has_key('wxGetValue') and porf['wxGetValue']:
@@ -1384,7 +1419,52 @@
                     porf['value'] = me.GetValue()
         
         self.OnUpdateValues()
+        
+        event.Skip()
+        
+    def OnUpdateSelection(self, event):
+        """Update list of available layers, tables, columns for
+        vector map layer"""
+        id = event.GetId()
+        
+        p = self.task.get_param(id, element='wxId', raiseError=False)
+        if not p or \
+                not p.has_key('wxId-bind'):
+            return
+        
+        pMap = self.task.get_param('map', raiseError=False)
+        if not pMap:
+            pMap = self.task.get_param('input', raiseError=False)
 
+        if not pMap or \
+                pMap.get('prompt', '') != 'vector':
+            return
+
+        if p == pMap:
+            map = event.GetString()
+        else:
+            map = pMap.get('value', '')
+        if not map:
+            return
+
+        for uid in p['wxId-bind']:
+            win = self.FindWindowById(uid)
+            name = win.GetName()
+            if name == 'LayerSelect':
+                win.InsertLayers(map)
+            elif name == 'ColumnSelect':
+                pLayer = self.task.get_param('layer', element='name', raiseError=False)
+                if pLayer and \
+                        pLayer.get('prompt', '') == 'layer':
+                    if pLayer.get('value', '') != '':
+                        layer = int(pLayer.get('value', 1))
+                    else:
+                        layer = int(pLayer.get('default', 1))
+                else:
+                    layer = 1
+                
+                win.InsertColumns(map, layer)
+        
         event.Skip()
         
     def OnDbColumn(self, event):



More information about the grass-commit mailing list