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

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Feb 10 02:57:28 EST 2008


Author: cmbarton
Date: 2008-02-10 02:57:28 -0500 (Sun, 10 Feb 2008)
New Revision: 30049

Modified:
   grass/trunk/gui/wxpython/gui_modules/gselect.py
   grass/trunk/gui/wxpython/gui_modules/menuform.py
Log:
Modified gselect and menuform to allow for multiple map or other GIS element entry when 'multiple = yes' in interface-description. Note: maintaining '@mapset' is crashing wxPython. This may be in g.parser, as it doesn't seem to be in menuform.

Modified: grass/trunk/gui/wxpython/gui_modules/gselect.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gselect.py	2008-02-10 07:41:58 UTC (rev 30048)
+++ grass/trunk/gui/wxpython/gui_modules/gselect.py	2008-02-10 07:57:28 UTC (rev 30049)
@@ -31,8 +31,8 @@
                            pos=wx.DefaultPosition, size=(-1,-1), type='cell',
                            style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER):
         """
-        A dialog box for the GIS element selector control so that it can be launched f
-        rom a button or other control.
+        A dialog box for the GIS element selector control so that it can be launched
+        from a button or other control.
         """
 
         wx.Dialog.__init__(self, parent, id, title, pos, size, style)
@@ -41,10 +41,8 @@
 
         sizer = wx.BoxSizer(wx.VERTICAL)
 
-        box = wx.BoxSizer(wx.HORIZONTAL)
         self.selection = Select(self, id=wx.ID_ANY, size=(300,-1),type=type)
-        box.Add(self.selection, 0, wx.ALIGN_CENTER|wx.ALL, 5)
-        sizer.Add(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
+        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)
         sizer.Add(line, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.RIGHT|wx.TOP, 5)
@@ -63,6 +61,11 @@
 
         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):

Modified: grass/trunk/gui/wxpython/gui_modules/menuform.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/menuform.py	2008-02-10 07:41:58 UTC (rev 30048)
+++ grass/trunk/gui/wxpython/gui_modules/menuform.py	2008-02-10 07:57:28 UTC (rev 30049)
@@ -55,6 +55,7 @@
 import wx.lib.flatnotebook as FN
 import wx.lib.colourselect as csel
 import wx.lib.filebrowsebutton as filebrowse
+from wx.lib.expando import ExpandoTextCtrl, EVT_ETC_LAYOUT_NEEDED
 import wx.html
 
 # Do the python 2.0 standard xml thing and map it on the old names
@@ -823,6 +824,8 @@
         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:
@@ -1000,17 +1003,34 @@
                                 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':
-                    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
+                    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)
+                        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)                    
+                    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)
                 # color entry
                 elif p.get('prompt','') == 'color':
                     # Heuristic way of finding whether transparent is allowed
@@ -1080,8 +1100,6 @@
                 if tooltip:
                     txt.SetToolTipString(tooltip)
 
-
-
         maxsizes = (0,0)
         for section in sections:
             tabsizer[section].SetSizeHints( tab[section] )
@@ -1190,8 +1208,8 @@
                 porf[ 'value' ] = me.GetValue()
 
         self.OnUpdateValues()
+        event.Skip()
 
-
     def createCmd( self, ignoreErrors = False ):
         """
         Produce a command line string (list) or feeding into GRASS.
@@ -1209,7 +1227,38 @@
             cmd = None
 
         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 ):
     """



More information about the grass-commit mailing list