[GRASS-SVN] r53892 - in grass/trunk/gui/wxpython: gmodeler gui_core
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Nov 18 05:19:43 PST 2012
Author: wenzeslaus
Date: 2012-11-18 05:19:42 -0800 (Sun, 18 Nov 2012)
New Revision: 53892
Modified:
grass/trunk/gui/wxpython/gmodeler/dialogs.py
grass/trunk/gui/wxpython/gui_core/ghelp.py
grass/trunk/gui/wxpython/gui_core/goutput.py
grass/trunk/gui/wxpython/gui_core/prompt.py
Log:
wxGUI/SearchModuleWindow: decoupling SMW and GPrompt; dangling of autocomplete list fixed (co-author: annakrat)
Modified: grass/trunk/gui/wxpython/gmodeler/dialogs.py
===================================================================
--- grass/trunk/gui/wxpython/gmodeler/dialogs.py 2012-11-18 12:40:34 UTC (rev 53891)
+++ grass/trunk/gui/wxpython/gmodeler/dialogs.py 2012-11-18 13:19:42 UTC (rev 53892)
@@ -31,10 +31,11 @@
from core import globalvar
from core import utils
+from core.modulesdata import ModulesData
from gui_core.widgets import GNotebook
from core.gcmd import GError, EncodeString
from gui_core.dialogs import ElementDialog, MapLayersDialogForModeler
-from gui_core.ghelp import SearchModuleWindow
+from gui_core.ghelp import SearchModuleWindow, EVT_MODULE_SELECTED
from gui_core.prompt import GPromptSTC
from gui_core.forms import CmdPanel
from gui_core.gselect import Select
@@ -134,14 +135,17 @@
self.cmdBox = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
label=" %s " % _("Command"))
-
- self.cmd_prompt = GPromptSTC(parent = self)
- self.search = SearchModuleWindow(parent = self.panel, cmdPrompt = self.cmd_prompt, showTip = True)
+
+ modulesData = ModulesData()
+ self.cmd_prompt = GPromptSTC(parent = self, modulesData = modulesData)
+ self.search = SearchModuleWindow(parent = self.panel,
+ modulesData = modulesData,
+ showTip = True)
+ self.search.Bind(EVT_MODULE_SELECTED,
+ lambda event:
+ self.cmd_prompt.SetTextAndFocus(event.name + ' '))
wx.CallAfter(self.cmd_prompt.SetFocus)
- # get commands
- items = self.cmd_prompt.GetCommandItems()
-
self.btnCancel = wx.Button(self.panel, wx.ID_CANCEL)
self.btnOk = wx.Button(self.panel, wx.ID_OK)
self.btnOk.SetDefault()
@@ -155,7 +159,7 @@
self._layout()
self.SetSize((500, 275))
-
+
def _layout(self):
cmdSizer = wx.StaticBoxSizer(self.cmdBox, wx.VERTICAL)
cmdSizer.Add(item = self.cmd_prompt, proportion = 1,
Modified: grass/trunk/gui/wxpython/gui_core/ghelp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/ghelp.py 2012-11-18 12:40:34 UTC (rev 53891)
+++ grass/trunk/gui/wxpython/gui_core/ghelp.py 2012-11-18 13:19:42 UTC (rev 53892)
@@ -32,6 +32,7 @@
import wx.lib.customtreectrl as CT
from wx.lib.hyperlink import HyperLinkCtrl
import wx.lib.flatnotebook as FN
+from wx.lib.newevent import NewEvent
import grass.script as grass
@@ -42,13 +43,14 @@
from core.debug import Debug
from core.settings import UserSettings
+gModuleSelected, EVT_MODULE_SELECTED = NewEvent()
+
class SearchModuleWindow(wx.Panel):
"""!Search module window (used in MenuTreeWindow)"""
- def __init__(self, parent, modulesData, id = wx.ID_ANY, cmdPrompt = None,
+ def __init__(self, parent, modulesData, id = wx.ID_ANY,
showChoice = True, showTip = False, **kwargs):
self.showTip = showTip
self.showChoice = showChoice
- self.cmdPrompt = cmdPrompt
self.modulesData = modulesData
wx.Panel.__init__(self, parent = parent, id = id, **kwargs)
@@ -69,8 +71,7 @@
self.search = wx.SearchCtrl(parent = self, id = wx.ID_ANY,
size = (-1, 25), style = wx.TE_PROCESS_ENTER)
- if self.cmdPrompt:
- self.search.Bind(wx.EVT_TEXT, self.OnSearchModule)
+ self.search.Bind(wx.EVT_TEXT, self.OnSearchModule)
if self.showTip:
self.searchTip = StaticWrapText(parent = self, id = wx.ID_ANY,
@@ -78,8 +79,7 @@
if self.showChoice:
self.searchChoice = wx.Choice(parent = self, id = wx.ID_ANY)
- if self.cmdPrompt:
- self.searchChoice.SetItems(self.modulesData.GetCommandItems())
+ self.searchChoice.SetItems(self.modulesData.GetCommandItems())
self.searchChoice.Bind(wx.EVT_CHOICE, self.OnSelectModule)
self._layout()
@@ -126,14 +126,7 @@
def OnSearchModule(self, event):
"""!Search module by keywords or description"""
- if not self.cmdPrompt:
- event.Skip()
- return
-
- # hide autocomplete
- if self.cmdPrompt.AutoCompActive():
- self.cmdPrompt.AutoCompCancel()
-
+
text = event.GetEventObject().GetValue()
if not text:
self.modulesData.SetFilter()
@@ -157,15 +150,10 @@
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()
-
+
+ moduleEvent = gModuleSelected(name = cmd)
+ wx.PostEvent(self, moduleEvent)
+
desc = self.modulesData.GetCommandDesc(cmd)
if self.showTip:
self.searchTip.SetLabel(desc)
Modified: grass/trunk/gui/wxpython/gui_core/goutput.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/goutput.py 2012-11-18 12:40:34 UTC (rev 53891)
+++ grass/trunk/gui/wxpython/gui_core/goutput.py 2012-11-18 13:19:42 UTC (rev 53892)
@@ -43,7 +43,7 @@
from gui_core.prompt import GPromptSTC
from core.debug import Debug
from core.settings import UserSettings, GetDisplayVectSettings
-from gui_core.ghelp import SearchModuleWindow
+from gui_core.ghelp import SearchModuleWindow, EVT_MODULE_SELECTED
from core.modulesdata import ModulesData
wxCmdOutput, EVT_CMD_OUTPUT = NewEvent()
@@ -274,6 +274,9 @@
self.searchPane.Collapse(True)
self.Bind(wx.EVT_COLLAPSIBLEPANE_CHANGED, self.OnSearchPaneChanged, self.searchPane)
self.search.Bind(wx.EVT_TEXT, self.OnUpdateStatusBar)
+ self.search.Bind(EVT_MODULE_SELECTED,
+ lambda event:
+ self.cmdPrompt.SetTextAndFocus(event.name + ' '))
else:
self.search = None
@@ -396,7 +399,6 @@
border = wx.BoxSizer(wx.VERTICAL)
self.search = SearchModuleWindow(parent = pane,
- cmdPrompt = self.cmdPrompt,
modulesData = modulesData)
border.Add(item = self.search, proportion = 0,
Modified: grass/trunk/gui/wxpython/gui_core/prompt.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/prompt.py 2012-11-18 12:40:34 UTC (rev 53891)
+++ grass/trunk/gui/wxpython/gui_core/prompt.py 2012-11-18 13:19:42 UTC (rev 53892)
@@ -34,7 +34,6 @@
from core import globalvar
from core import utils
-from lmgr.menudata import LayerManagerMenuData
from core.gcmd import EncodeString, DecodeString, GetRealCmd
class PromptListCtrl(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin):
@@ -687,6 +686,7 @@
self.Bind(wx.EVT_KEY_DOWN, self.OnKeyPressed)
self.Bind(wx.stc.EVT_STC_AUTOCOMP_SELECTION, self.OnItemSelected)
self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemChanged)
+ self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
def OnTextSelectionChanged(self, event):
"""!Copy selected text to clipboard and skip event.
@@ -768,7 +768,21 @@
self.cmdDesc = gtask.parse_interface(GetRealCmd(cmd))
except IOError:
self.cmdDesc = None
-
+
+ def OnKillFocus(self, event):
+ """!Hides autocomplete"""
+ # hide autocomplete
+ if self.AutoCompActive():
+ self.AutoCompCancel()
+ event.Skip()
+
+ def SetTextAndFocus(self, text):
+ pos = len(text)
+ self.SetText(text)
+ self.SetSelectionStart(pos)
+ self.SetCurrentPos(pos)
+ self.SetFocus()
+
def UpdateCmdHistory(self, cmd):
"""!Update command history
More information about the grass-commit
mailing list