[GRASS-SVN] r37596 - in grass/trunk/gui/wxpython: . gui_modules xml

svn_grass at osgeo.org svn_grass at osgeo.org
Fri May 29 17:57:37 EDT 2009


Author: martinl
Date: 2009-05-29 17:57:37 -0400 (Fri, 29 May 2009)
New Revision: 37596

Modified:
   grass/trunk/gui/wxpython/gui_modules/menudata.py
   grass/trunk/gui/wxpython/gui_modules/menuform.py
   grass/trunk/gui/wxpython/gui_modules/prompt.py
   grass/trunk/gui/wxpython/wxgui.py
   grass/trunk/gui/wxpython/xml/menudata.xml
Log:
wxGUI: search modules (stage 1 - description only)


Modified: grass/trunk/gui/wxpython/gui_modules/menudata.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/menudata.py	2009-05-29 21:52:24 UTC (rev 37595)
+++ grass/trunk/gui/wxpython/gui_modules/menudata.py	2009-05-29 21:57:37 UTC (rev 37596)
@@ -1,4 +1,4 @@
-"""
+"""!
 @package menudata.py
 
 @brief Complex list for main menu entries for GRASS wxPython GUI.
@@ -6,7 +6,7 @@
 Classes:
  - Data
 
-COPYRIGHT:  (C) 2007-2008 by the GRASS Development Team
+(C) 2007-2009 by the GRASS Development Team
 This program is free software under the GNU General Public
 License (>=v2). Read the file COPYING that comes with GRASS
 for details.
@@ -24,11 +24,11 @@
     import elementtree.ElementTree as etree # Python <= 2.4
 
 class Data:
-    '''Data object that returns menu descriptions to be used in wxgui.py.'''
+    '''!Data object that returns menu descriptions to be used in wxgui.py.'''
     def __init__(self, gisbase=None):
         if not gisbase:
             gisbase = os.getenv('GISBASE')
-	filename = gisbase + '/etc/wxpython/xml/menudata.xml'
+	filename = os.path.join(gisbase, 'etc', 'wxpython', 'xml', 'menudata.xml')
 	self.tree = etree.parse(filename)
 
     def getMenuItem(self, mi):
@@ -70,6 +70,24 @@
 		fh.write('     _(%r),\n' % node.text)
 	fh.write('    \'\']\n')
 
+    def GetModules(self):
+        """!Create dictionary of modules used to search module by
+        keywords, description, etc."""
+        modules = dict()
+        
+        for node in self.tree.getiterator():
+            if node.tag == 'menuitem':
+                module = description = ''
+                for child in node.getchildren():
+                    if child.tag == 'help':
+                        description = child.text
+                    if child.tag == 'command':
+                        module = child.text
+                if module:
+                    modules[module] = { 'desc': description }
+        
+        return modules
+
 if __name__ == "__main__":
     import sys
     if len(sys.argv) < 2:

Modified: grass/trunk/gui/wxpython/gui_modules/menuform.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/menuform.py	2009-05-29 21:52:24 UTC (rev 37595)
+++ grass/trunk/gui/wxpython/gui_modules/menuform.py	2009-05-29 21:57:37 UTC (rev 37596)
@@ -1792,13 +1792,13 @@
         self.parent = parent
         self.grass_task = None
 
-    def ParseInterface(self, cmd):
+    def ParseInterface(self, cmd, parser = processTask):
         """!Parse interface
 
         @param cmd command to be parsed (given as list)
         """
         grass_task = grassTask()
-        handler = processTask(grass_task)
+        handler = parser(grass_task)
         enc = locale.getdefaultlocale()[1]
         if enc and enc.lower() not in ("utf8", "utf-8"):
             xml.sax.parseString(getInterfaceDescription(cmd[0]).decode(enc).encode("utf-8"),

Modified: grass/trunk/gui/wxpython/gui_modules/prompt.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/prompt.py	2009-05-29 21:52:24 UTC (rev 37595)
+++ grass/trunk/gui/wxpython/gui_modules/prompt.py	2009-05-29 21:57:37 UTC (rev 37596)
@@ -1,4 +1,4 @@
-"""
+"""!
 @package prompt.py
 
 @brief GRASS prompt
@@ -25,22 +25,40 @@
 import wx
 import wx.lib.mixins.listctrl as listmix
 
+from grass.script import core as grass
+
 import globalvar
 import utils
 import menuform
-from grass.script import core as grass
+import menudata
 
 class GPrompt:
     """!Interactive GRASS prompt"""
     def __init__(self, parent):
-        self.parent = parent
-                
+        self.parent = parent # GMFrame
+        
+        # dictionary of modules (description, keywords, ...)
+        self.modules = self.parent.menudata.GetModules()
+        
         self.panel, self.input = self.__create()
         
     def __create(self):
         """!Create widget"""
         cmdprompt = wx.Panel(self.parent)
         
+        #
+        # search
+        #
+        searchTxt = wx.StaticText(parent = cmdprompt, id = wx.ID_ANY,
+                                  label = _("Search:"))
+        
+        self.searchBy = wx.Choice(parent = cmdprompt, id = wx.ID_ANY,
+                             choices = [_("description"),
+                                        _("keywords")])
+        
+        self.search = wx.TextCtrl(parent = cmdprompt, id = wx.ID_ANY,
+                             value = "", size = (-1, 25))
+        
         label = wx.Button(parent = cmdprompt, id = wx.ID_ANY,
                           label = _("Cmd >"), size = (-1, 25))
         label.SetToolTipString(_("Click for erasing command prompt"))
@@ -59,25 +77,46 @@
                                    value = "",
                                    style=wx.TE_LINEWRAP | wx.TE_PROCESS_ENTER,
                                    size = (-1, 25))
+            self.searchBy.Enable(False)
+            self.search.Enable(False)
         
         cmdinput.SetFont(wx.Font(10, wx.FONTFAMILY_MODERN, wx.NORMAL, wx.NORMAL, 0, ''))
         
         wx.CallAfter(cmdinput.SetInsertionPoint, 0)
         
+        # bidnings
         label.Bind(wx.EVT_BUTTON,        self.OnCmdErase)
         cmdinput.Bind(wx.EVT_TEXT_ENTER, self.OnRunCmd)
         cmdinput.Bind(wx.EVT_TEXT,       self.OnUpdateStatusBar)
+        self.search.Bind(wx.EVT_TEXT,    self.OnSearchModule)
         
         # layout
-        sizer = wx.BoxSizer(wx.HORIZONTAL)
-        sizer.Add(item = label, proportion = 0,
-                  flag = wx.EXPAND | wx.LEFT | wx.RIGHT |
-                  wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER,
-                  border = 3)
-        sizer.Add(item = cmdinput, proportion = 1,
-                  flag = wx.EXPAND | wx.ALL,
-                  border = 1)
+        sizer = wx.GridBagSizer(hgap=5, vgap=5)
+        sizer.AddGrowableCol(2)
+
+        sizer.Add(item = searchTxt,
+                  flag = wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL,
+                  pos = (0, 0))
+
+        sizer.Add(item = self.searchBy,
+                  flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER,
+                  pos = (0, 1))
         
+        sizer.Add(item = self.search,
+                  flag = wx.EXPAND | wx.RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER,
+                  border = 5,
+                  pos = (0, 2))
+        
+        sizer.Add(item = label, 
+                  flag = wx.LEFT | wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER,
+                  border = 5,
+                  pos = (1, 0))
+        
+        sizer.Add(item = cmdinput,
+                  flag = wx.EXPAND | wx.RIGHT,
+                  border = 5,
+                  pos = (1, 1), span = (1, 2))
+        
         cmdprompt.SetSizer(sizer)
         sizer.Fit(cmdprompt)
         cmdprompt.Layout()
@@ -125,6 +164,21 @@
             self.parent.statusbar.SetStatusText(_("Type GRASS command and run by pressing ENTER"))
             event.Skip()
         
+    def OnSearchModule(self, event):
+        """!Search module by metadata"""
+        text = event.GetString()
+        if not text:
+            self.input.SetChoices(globalvar.grassCmd['all'])
+            return
+        
+        modules = []
+        for module, data in self.modules.iteritems():
+            if text in data['desc']:
+                modules.append(module)
+        
+        self.parent.statusbar.SetStatusText(_("%d modules found") % len(modules))
+        self.input.SetChoices(modules)
+                    
 class PromptListCtrl(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin):
     def __init__(self, parent, id = wx.ID_ANY, pos = wx.DefaultPosition,
                  size = wx.DefaultSize, style = 0):
@@ -133,8 +187,7 @@
         
 class TextCtrlAutoComplete(wx.TextCtrl, listmix.ColumnSorterMixin):
     def __init__ (self, parent, id = wx.ID_ANY, choices = [], **kwargs):
-        """
-        Constructor works just like wx.TextCtrl except you can pass in a
+        """!Constructor works just like wx.TextCtrl except you can pass in a
         list of choices.  You can also change the choice list at any time
         by calling setChoices.
         
@@ -146,7 +199,7 @@
             kwargs['style'] = wx.TE_PROCESS_ENTER
         
         wx.TextCtrl.__init__(self, parent, id, **kwargs)
-        
+
         # some variables
         self._choices = choices
         self._hideOnNoMatch = True
@@ -220,8 +273,7 @@
         self.dropdown.SetClientSize(self.popupsize)
 
     def _showDropDown(self, show = True):
-        """
-        Eit`her display the drop down list (show = True) or hide it
+        """!Either display the drop down list (show = True) or hide it
         (show = False).
         """
         if show:
@@ -240,8 +292,7 @@
         self.dropdown.Show(show)
     
     def _listItemVisible(self):
-        """
-        Moves the selected item to the top of the list ensuring it is
+        """!Moves the selected item to the top of the list ensuring it is
         always visible.
         """
         toSel = self.dropdownlistbox.GetFirstSelected()
@@ -250,8 +301,7 @@
         self.dropdownlistbox.EnsureVisible(toSel)
     
     def _setValueFromSelected(self):
-         """
-         Sets the wx.TextCtrl value from the selected wx.ListCtrl item.
+         """!Sets the wx.TextCtrl value from the selected wx.ListCtrl item.
          Will do nothing if no item is selected in the wx.ListCtrl.
          """
          sel = self.dropdownlistbox.GetFirstSelected()
@@ -291,8 +341,7 @@
         return self.dropdownlistbox
     
     def SetChoices(self, choices, type = 'module'):
-        """
-        Sets the choices available in the popup wx.ListBox.
+        """!Sets the choices available in the popup wx.ListBox.
         The items will be sorted case insensitively.
         """
         self._choices = choices

Modified: grass/trunk/gui/wxpython/wxgui.py
===================================================================
--- grass/trunk/gui/wxpython/wxgui.py	2009-05-29 21:52:24 UTC (rev 37595)
+++ grass/trunk/gui/wxpython/wxgui.py	2009-05-29 21:57:37 UTC (rev 37596)
@@ -104,7 +104,7 @@
         self.baseTitle = title
         self.iconsize  = (16, 16)
 
-        wx.Frame.__init__(self, parent=parent, id=id, size=(550, 400),
+        wx.Frame.__init__(self, parent=parent, id=id, size=(550, 450),
                           style=wx.DEFAULT_FRAME_STYLE)
                           
         self.SetTitle(self.baseTitle)
@@ -126,8 +126,8 @@
         # creating widgets
         # -> self.notebook, self.goutput, self.outpage
         self.notebook  = self.__createNoteBook()
+        self.menubar, self.menudata = self.__createMenuBar()
         self.cmdprompt, self.cmdinput = self.__createCommandPrompt()
-        self.menubar   = self.__createMenuBar()
         self.toolbar   = self.__createToolBar()
         self.statusbar = self.CreateStatusBar(number=1)
 
@@ -146,7 +146,7 @@
                              Left().CentrePane().BestSize((-1,-1)).Dockable(False).
                              CloseButton(False).DestroyOnClose(True).Row(1).Layer(0))
         self._auimgr.AddPane(self.cmdprompt, wx.aui.AuiPaneInfo().
-                             Bottom().BestSize((-1,25)).Dockable(False).
+                             Bottom().BestSize((-1, 60)).Dockable(False).
                              CloseButton(False).DestroyOnClose(True).
                              PaneBorder(False).Row(1).Layer(0).Position(0).
                              CaptionVisible(False))
@@ -202,15 +202,15 @@
         """!Creates menubar"""
 
         self.menubar = wx.MenuBar()
-        menud = menudata.Data()
-        for eachMenuData in menud.GetMenu():
+        self.menudata = menudata.Data()
+        for eachMenuData in self.menudata.GetMenu():
             for eachHeading in eachMenuData:
                 menuLabel = eachHeading[0]
                 menuItems = eachHeading[1]
                 self.menubar.Append(self.__createMenu(menuItems), menuLabel)
         self.SetMenuBar(self.menubar)
 
-        return self.menubar
+        return (self.menubar, self.menudata)
 
     def __createMenu(self, menuData):
         """!Creates menu"""
@@ -935,7 +935,7 @@
     def OnPreferences(self, event):
         """!General GUI preferences/settings"""
         preferences.PreferencesDialog(parent=self).ShowModal()
-
+        
     def DispHistogram(self, event):
         """
         Init histogram display canvas and tools
@@ -1481,17 +1481,21 @@
                       style=wx.OK | wx.ICON_INFORMATION | wx.CENTRE)
 
 class GMApp(wx.App):
-    """
-    GMApp class
-    """
-    def __init__(self, workspace=None):
+    def __init__(self, workspace = None):
+        """!Main GUI class.
+
+        @param workspace path to the workspace file
+        """
         self.workspaceFile = workspace
         
         # call parent class initializer
         wx.App.__init__(self, False)
         
     def OnInit(self):
-        # initialize all available image handlers
+        """!Initialize all available image handlers
+
+        @return True
+        """
         wx.InitAllImageHandlers()
 
         # create splash screen
@@ -1501,7 +1505,7 @@
         wx.SplashScreen (bitmap=introBmp, splashStyle=wx.SPLASH_CENTRE_ON_SCREEN | wx.SPLASH_TIMEOUT,
                          milliseconds=1500, parent=None, id=wx.ID_ANY)
         wx.Yield()
-
+        
         # create and show main frame
         mainframe = GMFrame(parent=None, id=wx.ID_ANY,
                             workspace = self.workspaceFile)

Modified: grass/trunk/gui/wxpython/xml/menudata.xml
===================================================================
--- grass/trunk/gui/wxpython/xml/menudata.xml	2009-05-29 21:52:24 UTC (rev 37595)
+++ grass/trunk/gui/wxpython/xml/menudata.xml	2009-05-29 21:57:37 UTC (rev 37596)
@@ -593,6 +593,7 @@
 	      <handler>self.OnMenuCmd</handler>
 	      <command>g.access</command>
 	    </menuitem>
+	    <separator/>
 	    <menuitem>
 	      <label>Show settings</label>
 	      <help>Outputs and modifies the user's current GRASS variable settings.</help>
@@ -611,6 +612,7 @@
 	      <handler>self.OnMenuCmd</handler>
 	      <command>g.change.gui.py</command>
 	    </menuitem>
+	    <separator/>
 	    <menuitem>
 	      <label>Version</label>
 	      <help>Displays version and copyright information.</help>
@@ -628,16 +630,7 @@
 	      <handler>self.OnMenuCmd</handler>
 	      <command>g.proj</command>
 	    </menuitem>
-<!--
 	    <menuitem>
-	      <label>Projection for current location</label>
-	      <help>Create/edit projection information for current location</help>
-	      <handler>self.OnXTerm</handler>
-	      <command>g.setproj</command>
-	    </menuitem>
--->
-	    <separator/>
-	    <menuitem>
 	      <label>Convert coordinates</label>
 	      <help>Convert coordinates from one projection to another (cs2cs frontend).</help>
 	      <handler>self.OnMenuCmd</handler>



More information about the grass-commit mailing list