[GRASS-SVN] r30063 - grass/trunk/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Feb 10 14:03:39 EST 2008


Author: cmbarton
Date: 2008-02-10 14:03:38 -0500 (Sun, 10 Feb 2008)
New Revision: 30063

Modified:
   grass/trunk/gui/wxpython/gui_modules/gselect.py
   grass/trunk/gui/wxpython/gui_modules/menuform.py
Log:
Martin's patch to improve multiple GIS element selection. Note: seems to work now with '@mapset'.

Modified: grass/trunk/gui/wxpython/gui_modules/gselect.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gselect.py	2008-02-10 17:33:05 UTC (rev 30062)
+++ grass/trunk/gui/wxpython/gui_modules/gselect.py	2008-02-10 19:03:38 UTC (rev 30063)
@@ -28,8 +28,8 @@
 
 class SelectDialog(wx.Dialog):
     def __init__(self, parent, id=wx.ID_ANY, title='Select GIS element',
-                           pos=wx.DefaultPosition, size=(-1,-1), type='cell',
-                           style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER):
+                pos=wx.DefaultPosition, size=(-1,-1), type='cell', multiple=False,
+                style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER):
         """
         A dialog box for the GIS element selector control so that it can be launched
         from a button or other control.
@@ -37,11 +37,12 @@
 
         wx.Dialog.__init__(self, parent, id, title, pos, size, style)
 
-        self.selection = ''
+        self.selection = None
 
         sizer = wx.BoxSizer(wx.VERTICAL)
 
-        self.selection = Select(self, id=wx.ID_ANY, size=(300,-1),type=type)
+        self.selection = Select(self, id=wx.ID_ANY, size=(300,-1), type=type,
+                                multiple=multiple)
         sizer.Add(self.selection, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
 
         line = wx.StaticLine(self, -1, size=(20,-1), style=wx.LI_HORIZONTAL)
@@ -61,24 +62,21 @@
 
         self.SetSizer(sizer)
         sizer.Fit(self)
-        self.Layout()
-                
-    def ElementName(self):
-        element = self.selection.GetValue()
-        return element
 
 class Select(wx.combo.ComboCtrl):
-    def __init__(self, parent, id, size, type):
+    def __init__(self, parent, id, size, type, multiple):
         """
         Custom control to create a ComboBox with a tree control
-        to display GIS elements within acessible mapsets.
-        Elements can be selected with mouse.
+        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.
         """
         wx.combo.ComboCtrl.__init__(self, parent=parent, id=id, size=size)
         self.tcp = TreeCtrlComboPopup()
         self.SetPopupControl(self.tcp)
         self.SetPopupExtents(0,100)
         self.tcp.GetElementList(type)
+        self.tcp.SetMultiple(multiple)
 
     def SetElementList(self, type):
         self.tcp.seltree.DeleteAllItems()
@@ -91,12 +89,11 @@
     """
 
     # overridden ComboPopup methods
-
     def Init(self):
-        self.value = None
+        self.value = [] # for multiple is False -> len(self.value) in [0,1]
         self.curitem = None
+        self.multiple = False
 
-
     def Create(self, parent):
         self.seltree = wx.TreeCtrl(parent, style=wx.TR_HIDE_ROOT
                                    |wx.TR_HAS_BUTTONS
@@ -130,14 +127,17 @@
         return self.seltree
 
     def GetStringValue(self):
-        if self.value:
-            return self.seltree.GetItemText(self.value)
-        return ""
+        str = ""
+        for value in self.value:
+            str += self.seltree.GetItemText(value) + ","
+        str = str.rstrip(',')
+        return str
 
     def OnPopup(self):
-        if self.value:
-            self.seltree.EnsureVisible(self.value)
-            self.seltree.SelectItem(self.value)
+        """Limited only for first selected"""
+        if len(self.value) > 0:
+            self.seltree.EnsureVisible(self.value[0])
+            self.seltree.SelectItem(self.value[0])
 
     def SetStringValue(self, value):
         # this assumes that item strings are unique...
@@ -146,7 +146,7 @@
             return
         found = self.FindItem(root, value)
         if found:
-            self.value = found
+            self.value.append(found)
             self.seltree.SelectItem(found)
 
     def GetAdjustedSize(self, minWidth, prefHeight, maxHeight):
@@ -274,13 +274,20 @@
             self.curitem = item
 
             if self.seltree.GetRootItem() == self.seltree.GetItemParent(item):
-                self.value = None # cannot select mapset item
+                self.value = [] # cannot select mapset item
             else:
-                self.value = item
+                if self.multiple is True:
+                    self.value.append(item)
+                else:
+                    self.value = [item, ]
 
             self.Dismiss()
 
         evt.Skip()
 
+    def SetMultiple(self, value):
+        """Select multiple items?"""
+        self.multiple = value
 
 
+

Modified: grass/trunk/gui/wxpython/gui_modules/menuform.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/menuform.py	2008-02-10 17:33:05 UTC (rev 30062)
+++ grass/trunk/gui/wxpython/gui_modules/menuform.py	2008-02-10 19:03:38 UTC (rev 30063)
@@ -824,8 +824,6 @@
         self.notebook = FN.FlatNotebook( self, id=wx.ID_ANY, style=nbStyle)
         self.notebook.SetTabAreaColour(globalvar.FNPageColor)
         self.notebook.Bind( FN.EVT_FLATNOTEBOOK_PAGE_CHANGED, self.OnPageChange )
-        self.selecttxt = '' # special text control to receive multiple GIS element selections
-        self.element = '' # GIS element to select in multi-selection control
         tab = {}
         tabsizer = {}
         for section in sections:
@@ -1003,34 +1001,21 @@
                                 flag=wx.ADJUST_MINSIZE | wx.RIGHT | wx.LEFT | wx.TOP, border=5)
                 # element selection tree combobox (maps, icons, regions, etc.)
                 if p.get('prompt','') != 'color' and p.get('element', '') != 'file':
-                    self.element = ''
-                    if p.get('multiple','no') == 'no':
-                        selection = gselect.Select(parent=which_panel, id=wx.ID_ANY, size=(300,-1),
-                                                  type=p.get('element','') )
-                        if p.get('value','') != '':
-                            selection.SetValue(p['value']) # parameter previously set
-
-                        which_sizer.Add(item=selection, proportion=0,
-                                        flag=wx.ADJUST_MINSIZE| wx.BOTTOM | wx.LEFT, border=5)
-                        # 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.Bind(wx.EVT_TEXT, self.OnSetValue)                    
+                    if p.get('multiple','no') == 'yes':
+                        multiple = True
                     else:
-                        btn4 = wx.Button(parent=which_panel, id=wx.ID_ANY, label='Select...')
-                        self.element = p.get('element','')
-                        self.selecttxt = ExpandoTextCtrl(parent=which_panel, id=wx.ID_ANY, value = p.get('default',''),
-                                           size = (300, -1))
-                        if p.get('value','') != '':
-                            self.selecttxt.SetValue(p['value']) # parameter previously set
-                        box = wx.BoxSizer(wx.HORIZONTAL)
-                        box.Add(item=btn4, proportion=0, flag=wx.LEFT, border=2)
-                        box.Add(item=self.selecttxt, proportion=0, flag=wx.LEFT | wx.RIGHT, border=5)
-                        which_sizer.Add(item=box, proportion=0, flag=wx.BOTTOM | wx.LEFT, border=5)
-                        p['wxId'] = self.selecttxt.GetId()
-                        btn4.Bind(wx.EVT_BUTTON, self.OnSelectButton)
-                        self.selecttxt.Bind(EVT_ETC_LAYOUT_NEEDED, self.OnRefit)
-                        self.selecttxt.Bind(wx.EVT_TEXT, self.OnSetValue)
+                        multiple = False
+                    selection = gselect.Select(parent=which_panel, id=wx.ID_ANY, size=(300,-1),
+                                               type=p.get('element',''), multiple=multiple)
+                    if p.get('value','') != '':
+                        selection.SetValue(p['value']) # parameter previously set
+
+                    which_sizer.Add(item=selection, proportion=0,
+                                    flag=wx.ADJUST_MINSIZE| wx.BOTTOM | wx.LEFT, border=5)
+                    # 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.Bind(wx.EVT_TEXT, self.OnSetValue)
                 # color entry
                 elif p.get('prompt','') == 'color':
                     # Heuristic way of finding whether transparent is allowed
@@ -1208,7 +1193,6 @@
                 porf[ 'value' ] = me.GetValue()
 
         self.OnUpdateValues()
-        event.Skip()
 
     def createCmd( self, ignoreErrors = False ):
         """
@@ -1228,38 +1212,7 @@
 
         return cmd
     
-    def OnRefit(self, event):
-        # The Expando control will redo the layout of the
-        # sizer it belongs to, but sometimes this may not be
-        # enough, so it will send us this event so we can do any
-        # other layout adjustments needed.  In this case we'll
-        # just resize the frame to fit the new needs of the sizer.
-        print 'in on refit'
-        self.Fit()
-        if event != None:
-            event.Skip()
 
-    def OnSelectButton(self, event):
-        """
-        Calls map selection control as a dialog instead of a comboBox so that
-        multiple maps can be selected.
-        """
-        # Get any values already set in map txtctrl.
-        elements = self.selecttxt.GetValue()
-        name = ''
-        dlg = gselect.SelectDialog(self, type=self.element)
-        dlg.CenterOnParent(wx.BOTH)
-        if dlg.ShowModal() == wx.ID_OK:
-            name = dlg.ElementName()
-            name = name.split('@')[0]
-            
-            if elements == '':
-                elements = name
-            else:
-                elements = '%s,%s' % (elements, name)
-                
-            self.selecttxt.SetValue(elements)        
-
 def getInterfaceDescription( cmd ):
     """
     Returns the XML description for the GRASS cmd.



More information about the grass-commit mailing list