Browse Source

wxGUI: improve SearchModuleWindow

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@42204 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 15 năm trước cách đây
mục cha
commit
360a0a906c

+ 1 - 0
gui/wxpython/gui_modules/__init__.py

@@ -8,6 +8,7 @@ all = [
     "gcmd.py",
     "gdialogs.py",
     "georect.py",
+    "ghelp.py"
     "globalvar.py",
     "goutput.py",
     "gselect.py",

+ 83 - 17
gui/wxpython/gui_modules/help.py

@@ -35,6 +35,7 @@ import  wx.lib.scrolledpanel as scrolled
 import menudata
 import gcmd
 import globalvar
+import menuform
 
 class HelpWindow(wx.Frame):
     """!GRASS Quickstart help window"""
@@ -63,14 +64,18 @@ class HelpWindow(wx.Frame):
 
 class SearchModuleWindow(wx.Panel):
     """!Search module window (used in MenuTreeWindow)"""
-    def __init__(self, parent, id = wx.ID_ANY, showLabel = True, **kwargs):
-        self.showLabel = showLabel
+    def __init__(self, parent, id = wx.ID_ANY, cmdPrompt = None, showChoice = True, **kwargs):
+        self.showChoice = showChoice
+        self.cmdPrompt  = cmdPrompt
         
         wx.Panel.__init__(self, parent = parent, id = id, **kwargs)
         
         self._searchDict = { _('description') : 'description',
                              _('command')     : 'command',
                              _('keywords')    : 'keywords' }
+
+        self.box = wx.StaticBox(parent = self, id = wx.ID_ANY,
+                                label=" %s " % _("Find module(s)"))
         
         self.searchBy = wx.Choice(parent = self, id = wx.ID_ANY,
                                   choices = [_('description'),
@@ -81,25 +86,34 @@ class SearchModuleWindow(wx.Panel):
         self.search = wx.TextCtrl(parent = self, id = wx.ID_ANY,
                                   value = "", size = (-1, 25),
                                   style = wx.TE_PROCESS_ENTER)
+        self.search.Bind(wx.EVT_TEXT, self.OnSearchModule)
+        
+        if self.showChoice:
+            self.searchTip  = menuform.StaticWrapText(parent = self, id = wx.ID_ANY,
+                                                      size = (-1, 35))
+            
+            self.searchChoice = wx.Choice(parent = self, id = wx.ID_ANY)
+            self.searchChoice.Bind(wx.EVT_CHOICE, self.OnSelectModule)
         
         self._layout()
 
     def _layout(self):
         """!Do layout"""
-                # search
-        sizer = wx.BoxSizer(wx.HORIZONTAL)
-        if self.showLabel:
-            sizer.Add(item = wx.StaticText(parent = self, id = wx.ID_ANY,
-                                           label = _("Find module by:")),
-                      proportion = 0,
-                      flag = wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.ALL,
-                      border = 3)
-        sizer.Add(item = self.searchBy, proportion = 0,
-                  flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT | wx.LEFT | wx.RIGHT,
-                  border = 5)
-        sizer.Add(item = self.search, proportion = 1,
-                  flag = wx.EXPAND | wx.RIGHT | wx.ALIGN_CENTER_VERTICAL,
-                  border = 5)
+        sizer = wx.StaticBoxSizer(self.box, wx.HORIZONTAL)
+        gridSizer = wx.GridBagSizer(hgap = 3, vgap = 3)
+        gridSizer.AddGrowableCol(1)
+        
+        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))
+        if self.showChoice:
+            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))
+        
+        sizer.Add(item = gridSizer, proportion = 1)
         
         self.SetSizer(sizer)
         sizer.Fit(self)
@@ -113,6 +127,58 @@ class SearchModuleWindow(wx.Panel):
     def SetSelection(self, i):
         """!Set selection element"""
         self.searchBy.SetSelection(i)
+
+    def OnSearchModule(self, event):
+        """!Search module by keywords or description"""
+        if not self.cmdPrompt:
+            event.Skip()
+            return
+        
+        text = event.GetString()
+        if not text:
+            self.cmdPrompt.SetFilter(None)
+            return
+        
+        modules = dict()
+        iFound = 0
+        for module, data in self.cmdPrompt.moduleDesc.iteritems():
+            found = False
+            if self.searchBy.GetSelection() == 0: # -> description
+                if text in data['desc']:
+                    found = True
+            else: # -> keywords
+                if self.cmdPrompt.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.cmdPrompt.SetFilter(modules)
+        self.searchTip.SetLabel(_("%d modules found") % iFound)
+        self.searchChoice.SetItems(self.cmdPrompt.GetCommandItems())
+        
+    def OnSelectModule(self, event):
+        """!Module selected from choice, update command prompt"""
+        cmd  = event.GetString().split(' ', 1)[0]
+        text = cmd + ' '
+        pos = len(text)
+
+        if self.cmdPrompt:
+            self.cmdPrompt.SetText(text)
+            self.cmdPrompt.SetSelectionStart(pos)
+            self.cmdPrompt.SetCurrentPos(pos)
+            self.cmdPrompt.SetFocus()
+        
+        desc = self.cmdPrompt.GetCommandDesc(cmd)
+        self.searchTip.SetLabel(desc)
         
 class MenuTreeWindow(wx.Panel):
     """!Show menu tree"""
@@ -128,7 +194,7 @@ class MenuTreeWindow(wx.Panel):
         self.tree.Load()
 
         # search widget
-        self.search = SearchModuleWindow(parent = self)
+        self.search = SearchModuleWindow(parent = self, showChoice = False)
         
         # buttons
         self.btnRun   = wx.Button(self, id = wx.ID_OK, label = _("Run"))

+ 11 - 90
gui/wxpython/gui_modules/gmodeler.py

@@ -58,6 +58,8 @@ from debug        import Debug
 from gcmd         import GMessage, GError
 from gdialogs     import ElementDialog, GetImageHandlers
 from preferences  import PreferencesBaseDialog, globalSettings as UserSettings
+from ghelp        import SearchModuleWindow
+
 from grass.script import core as grass
 
 class Model(object):
@@ -477,6 +479,7 @@ class ModelFrame(wx.Frame):
                 Debug.msg(4, "ModelFrame.OnModelSave(): filename=%s" % self.modelFile)
                 self.WriteModelFile(self.modelFile)
                 self.SetStatusText(_('File <%s> saved') % self.modelFile, 0)
+                self.SetTitle(self.baseTitle + " - " +  os.path.basename(self.modelFile))
         elif not self.modelFile:
             self.OnModelSaveAs(None)
         
@@ -1530,37 +1533,20 @@ class ModelSearchDialog(wx.Dialog):
         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.searchBy.SetSelection(0)
-        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)
-
+        self.search = SearchModuleWindow(parent = self.panel, cmdPrompt = self.cmd_prompt)
+        
         # 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, 275))
@@ -1570,31 +1556,12 @@ class ModelSearchDialog(wx.Dialog):
         btnSizer.AddButton(self.btnCancel)
         btnSizer.AddButton(self.btnOk)
         btnSizer.Realize()
-
-        findSizer = wx.StaticBoxSizer(self.findBox, wx.HORIZONTAL)
-        gridSizer = wx.GridBagSizer(hgap = 3, vgap = 3)
-        gridSizer.AddGrowableCol(1)
-
-        cmdSizer = wx.StaticBoxSizer(self.cmdBox, wx.VERTICAL)
-        
-        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)
-        
-        cmdSizer.Add(item=self.cmd_prompt, proportion=1,
-                      flag=wx.EXPAND | wx.ALL, border=1)
         
         mainSizer = wx.BoxSizer(wx.VERTICAL)
-        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=self.search, proportion=0,
+                      flag=wx.EXPAND | wx.ALL, border=3)
+        mainSizer.Add(item=self.cmd_prompt, proportion=1,
+                      flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, border=3)
         mainSizer.Add(item=btnSizer, proportion=0,
                       flag=wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border=5)
         
@@ -1619,53 +1586,7 @@ class ModelSearchDialog(wx.Dialog):
             cmd = shlex.split(utils.EncodeString((line)))
             
         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()
         

+ 6 - 39
gui/wxpython/gui_modules/goutput.py

@@ -40,7 +40,7 @@ import prompt
 
 from debug       import Debug
 from preferences import globalSettings as UserSettings
-from help        import SearchModuleWindow
+from ghelp       import SearchModuleWindow
 
 wxCmdOutput,   EVT_CMD_OUTPUT   = NewEvent()
 wxCmdProgress, EVT_CMD_PROGRESS = NewEvent()
@@ -186,9 +186,10 @@ class GMConsole(wx.SplitterWindow):
         self.Bind(EVT_CMD_DONE, self.OnCmdDone)
         
         # search & command prompt
-        self.search = SearchModuleWindow(parent = self.panelPrompt)
-        
         self.cmd_prompt = prompt.GPromptSTC(parent = self)
+                
+        self.search = SearchModuleWindow(parent = self.panelPrompt, cmdPrompt = self.cmd_prompt)
+        
         if self.parent.GetName() != 'LayerManager':
             self.search.Hide()
             self.cmd_prompt.Hide()
@@ -227,8 +228,6 @@ class GMConsole(wx.SplitterWindow):
         self.btn_abort.Bind(wx.EVT_BUTTON,         self.OnCmdAbort)
         self.btn_abort.Bind(EVT_CMD_ABORT,         self.OnCmdAbort)
         
-        self.search.Bind(wx.EVT_TEXT,              self.OnSearchModule)
-        
         self.__layout()
         
     def __layout(self):
@@ -244,7 +243,7 @@ class GMConsole(wx.SplitterWindow):
         
         if self.search.IsShown():
             PromptSizer.Add(item=self.search, proportion=0,
-                            flag=wx.EXPAND | wx.ALL, border=1)
+                            flag=wx.EXPAND | wx.ALL, border=3)
         PromptSizer.Add(item=self.cmd_prompt, proportion=1,
                         flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, border=3)
         
@@ -542,39 +541,7 @@ class GMConsole(wx.SplitterWindow):
     def GetCmd(self):
         """!Get running command or None"""
         return self.requestQ.get()
-
-    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.search.GetSelection() == 'description': # -> 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.parent.statusbar.SetStatusText(_("%d modules found") % iFound)
-        self.cmd_prompt.SetFilter(modules)
-        
+    
     def OnCmdOutput(self, event):
         """!Print command output"""
         message = event.text