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

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Apr 13 13:27:14 EDT 2010


Author: martinl
Date: 2010-04-13 13:27:13 -0400 (Tue, 13 Apr 2010)
New Revision: 41846

Modified:
   grass/trunk/gui/wxpython/gui_modules/gmodeler.py
   grass/trunk/gui/wxpython/gui_modules/menuform.py
   grass/trunk/gui/wxpython/gui_modules/prompt.py
Log:
wxGUI/modeler: improvements in search dialog


Modified: grass/trunk/gui/wxpython/gui_modules/gmodeler.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gmodeler.py	2010-04-13 15:38:31 UTC (rev 41845)
+++ grass/trunk/gui/wxpython/gui_modules/gmodeler.py	2010-04-13 17:27:13 UTC (rev 41846)
@@ -102,6 +102,7 @@
                 
         self.modelPage   = self.notebook.AddPage(self.canvas, text=_('Model'))
         self.commandPage = self.notebook.AddPage(self.goutput, text=_('Command output'))
+        wx.CallAfter(self.notebook.SetSelection, 0)
         
         self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
         
@@ -566,7 +567,7 @@
                 if p.get('prompt', '') in ('raster', 'vector', 'raster3d'):
                     try:
                         name, mapset = p.get('value', '').split('@', 1)
-                    except IndexError:
+                    except (ValueError, IndexError):
                         continue
                     
                     if mapset != grass.gisenv()['MAPSET']:
@@ -1095,7 +1096,7 @@
         self.frame.canvas.Refresh()
         
 class ModelSearchDialog(wx.Dialog):
-    def __init__(self, parent, id = wx.ID_ANY, title = _("Find GRASS module"),
+    def __init__(self, parent, id = wx.ID_ANY, title = _("Select GRASS module"),
                  style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, **kwargs):
         """!Graphical modeler module search window
         
@@ -1112,50 +1113,78 @@
         self.SetIcon(wx.Icon(os.path.join(globalvar.ETCICONDIR, 'grass.ico'), wx.BITMAP_TYPE_ICO))
         
         self.panel = wx.Panel(parent = self, id = wx.ID_ANY)
+
+        self.findBox = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
+                                    label=" %s " % _("Find module(s) by"))
+        self.cmdBox = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
+                                   label=" %s " % _("Command"))
         
         self.searchBy = wx.Choice(parent = self.panel, id = wx.ID_ANY,
                                   choices = [_("description"),
                                              _("keywords")])
         self.search = wx.TextCtrl(parent = self.panel, id = wx.ID_ANY,
                                   value = "", size = (-1, 25))
+        self.searchTip  = menuform.StaticWrapText(parent = self.panel, id = wx.ID_ANY,
+                                                  size = (-1, 35))
+        
+        self.searchChoice = wx.Choice(parent = self.panel, id = wx.ID_ANY)
+        
         self.cmd_prompt = prompt.GPromptSTC(parent = self)
+
+        # get commands
+        items = self.cmd_prompt.GetCommandItems()
+        self.searchTip.SetLabel(_("%d modules found") % len(items))
+        self.searchChoice.SetItems(items)
         
         self.btnCancel = wx.Button(self.panel, wx.ID_CANCEL)
         self.btnOk     = wx.Button(self.panel, wx.ID_OK)
         self.btnOk.SetDefault()
-
+        
+        self.search.Bind(wx.EVT_TEXT, self.OnSearchModule)
+        self.searchChoice.Bind(wx.EVT_CHOICE, self.OnSelectModule)
+        
         self._layout()
         
+        self.SetSize((500, 250))
+        
     def _layout(self):
         btnSizer = wx.StdDialogButtonSizer()
         btnSizer.AddButton(self.btnCancel)
         btnSizer.AddButton(self.btnOk)
         btnSizer.Realize()
 
-        bodyBox = wx.StaticBox(parent=self.panel, id=wx.ID_ANY,
-                               label=" %s " % _("Find GRASS module"))
-        bodySizer = wx.StaticBoxSizer(bodyBox, wx.VERTICAL)
-        searchSizer = wx.BoxSizer(wx.HORIZONTAL)
+        findSizer = wx.StaticBoxSizer(self.findBox, wx.HORIZONTAL)
+        gridSizer = wx.GridBagSizer(hgap = 3, vgap = 3)
+        gridSizer.AddGrowableCol(1)
+
+        cmdSizer = wx.StaticBoxSizer(self.cmdBox, wx.VERTICAL)
         
-        searchSizer.Add(item = self.searchBy,
-                        proportion = 0, flag = wx.LEFT, border = 3)
-        searchSizer.Add(item = self.search,
-                        proportion = 1, flag = wx.LEFT | wx.EXPAND, border = 3)
+        gridSizer.Add(item = self.searchBy,
+                      flag=wx.ALIGN_CENTER_VERTICAL, pos = (0, 0))
+        gridSizer.Add(item = self.search,
+                      flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, pos = (0, 1))
+        gridSizer.Add(item = self.searchTip,
+                      flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, pos = (1, 0), span = (1, 2))
+        gridSizer.Add(item = self.searchChoice,
+                      flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, pos = (2, 0), span = (1, 2))
+        findSizer.Add(item = gridSizer, proportion = 1)
         
-        bodySizer.Add(item=searchSizer, proportion=0,
+        cmdSizer.Add(item=self.cmd_prompt, proportion=1,
                       flag=wx.EXPAND | wx.ALL, border=1)
-        bodySizer.Add(item=self.cmd_prompt, proportion=1,
-                      flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, border=3)
         
         mainSizer = wx.BoxSizer(wx.VERTICAL)
-        mainSizer.Add(item=bodySizer, proportion=1,
+        mainSizer.Add(item=findSizer, proportion=0,
                       flag=wx.EXPAND | wx.ALL, border=5)
+        mainSizer.Add(item=cmdSizer, proportion=1,
+                      flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 5)
         mainSizer.Add(item=btnSizer, proportion=0,
                       flag=wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border=5)
         
         self.panel.SetSizer(mainSizer)
         mainSizer.Fit(self.panel)
         
+        self.Layout()
+
     def GetPanel(self):
         """!Get dialog panel"""
         return self.panel
@@ -1173,6 +1202,52 @@
             
         return cmd
 
+    def OnSearchModule(self, event):
+        """!Search module by keywords or description"""
+        text = event.GetString()
+        if not text:
+            self.cmd_prompt.SetFilter(None)
+            return
+        
+        modules = dict()
+        iFound = 0
+        for module, data in self.cmd_prompt.moduleDesc.iteritems():
+            found = False
+            if self.searchBy.GetSelection() == 0: # -> description
+                if text in data['desc']:
+                    found = True
+            else: # -> keywords
+                if self.cmd_prompt.CheckKey(text, data['keywords']):
+                    found = True
+
+            if found:
+                iFound += 1
+                try:
+                    group, name = module.split('.')
+                except ValueError:
+                    continue # TODO
+                
+                if not modules.has_key(group):
+                    modules[group] = list()
+                modules[group].append(name)
+
+        self.cmd_prompt.SetFilter(modules)
+        self.searchTip.SetLabel(_("%d modules found") % iFound)
+        self.searchChoice.SetItems(self.cmd_prompt.GetCommandItems())
+        
+    def OnSelectModule(self, event):
+        """!Module selected from choice, update command prompt"""
+        cmd  = event.GetString().split(' ', 1)[0]
+        text = cmd + ' '
+        pos = len(text)
+        self.cmd_prompt.SetText(text)
+        self.cmd_prompt.SetSelectionStart(pos)
+        self.cmd_prompt.SetCurrentPos(pos)
+        self.cmd_prompt.SetFocus()
+        
+        desc = self.cmd_prompt.GetCommandDesc(cmd)
+        self.searchTip.SetLabel(desc)
+                                
     def OnOk(self, event):
         self.btnOk.SetFocus()
         

Modified: grass/trunk/gui/wxpython/gui_modules/menuform.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/menuform.py	2010-04-13 15:38:31 UTC (rev 41845)
+++ grass/trunk/gui/wxpython/gui_modules/menuform.py	2010-04-13 17:27:13 UTC (rev 41846)
@@ -2086,29 +2086,33 @@
         return None
 
 class StaticWrapText(wx.StaticText):
+    """! A Static Text field that wraps its text to fit its width,
+    enlarging its height if necessary.
     """
-    A Static Text field that wraps its text to fit its width, enlarging its height if necessary.
-    """
-    def __init__(self, parent, id=wx.ID_ANY, label=u'', *args, **kwds):
+    def __init__(self, parent, id = wx.ID_ANY, label = '', *args, **kwds):
+        self.parent        = parent
         self.originalLabel = label
-        wx.StaticText.__init__(self, parent, id, u'', *args, **kwds)
+        
+        wx.StaticText.__init__(self, parent, id, label = '', *args, **kwds)
+        
         self.SetLabel(label)
-        self.Bind(wx.EVT_SIZE, self.onResize)
+        self.Bind(wx.EVT_SIZE, self.OnResize)
     
     def SetLabel(self, label):
         self.originalLabel = label
         self.wrappedSize = None
-        #self.onResize(None)
-        
-    def onResize(self, event):
+        self.OnResize(None)
+
+    def OnResize(self, event):
         if not getattr(self, "resizing", False):
             self.resizing = True
-            newSize = self.GetSize()
+            newSize = wx.Size(self.parent.GetSize().width,
+                              self.GetSize().height)
             if self.wrappedSize != newSize:
                 wx.StaticText.SetLabel(self, self.originalLabel)
                 self.Wrap(newSize.width)
-                self.wrappedSize = self.GetMinSize()
-
+                self.wrappedSize = newSize
+                
                 self.SetSize(self.wrappedSize)
             del self.resizing
 

Modified: grass/trunk/gui/wxpython/gui_modules/prompt.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/prompt.py	2010-04-13 15:38:31 UTC (rev 41845)
+++ grass/trunk/gui/wxpython/gui_modules/prompt.py	2010-04-13 17:27:13 UTC (rev 41846)
@@ -544,7 +544,33 @@
             fileHistory.close()
         
         return hist
+
+    def GetCommandDesc(self, cmd):
+        """!Get description for given command"""
+        if self.moduleDesc.has_key(cmd):
+            return self.moduleDesc[cmd]['desc']
         
+        return ''
+            
+    def GetCommandItems(self):
+        """!Get list of available commands"""
+        items = list()
+        
+        if self.autoCompFilter:
+            mList = self.autoCompFilter
+        else:
+            mList = self.moduleList
+        
+        prefixes = mList.keys()
+        prefixes.sort()
+        
+        for prefix in prefixes:
+            for command in mList[prefix]:
+                name = prefix + '.' + command
+                items.append(name)
+        
+        return items
+    
     def _getListOfModules(self):
         """!Get list of modules"""
         result = dict()



More information about the grass-commit mailing list