[GRASS-SVN] r53900 - in grass/trunk/gui/wxpython: core lmgr modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Nov 18 11:00:15 PST 2012
Author: annakrat
Date: 2012-11-18 11:00:14 -0800 (Sun, 18 Nov 2012)
New Revision: 53900
Modified:
grass/trunk/gui/wxpython/core/modulesdata.py
grass/trunk/gui/wxpython/lmgr/menudata.py
grass/trunk/gui/wxpython/modules/extensions.py
Log:
wxGUI/extension: fix search module (co-author wenzeslaus)
Modified: grass/trunk/gui/wxpython/core/modulesdata.py
===================================================================
--- grass/trunk/gui/wxpython/core/modulesdata.py 2012-11-18 18:40:11 UTC (rev 53899)
+++ grass/trunk/gui/wxpython/core/modulesdata.py 2012-11-18 19:00:14 UTC (rev 53900)
@@ -51,7 +51,7 @@
\endcode
"""
if cmd in self.moduleDesc:
- return self.moduleDesc[cmd]['desc']
+ return self.moduleDesc[cmd]['description']
return ''
@@ -131,7 +131,7 @@
for module, data in self.moduleDesc.iteritems():
found = False
if findIn == 'description':
- if text in data['desc']:
+ if text in data['description']:
found = True
elif findIn == 'keywords':
if text in ','.join(data['keywords']):
Modified: grass/trunk/gui/wxpython/lmgr/menudata.py
===================================================================
--- grass/trunk/gui/wxpython/lmgr/menudata.py 2012-11-18 18:40:11 UTC (rev 53899)
+++ grass/trunk/gui/wxpython/lmgr/menudata.py 2012-11-18 19:00:14 UTC (rev 53900)
@@ -49,7 +49,7 @@
keywords = child.text.split(',')
if module:
- modules[module] = { 'desc': description,
+ modules[module] = { 'description': description,
'keywords' : keywords }
if len(keywords) < 1:
print >> sys.stderr, "WARNING: Module <%s> has no keywords" % module
Modified: grass/trunk/gui/wxpython/modules/extensions.py
===================================================================
--- grass/trunk/gui/wxpython/modules/extensions.py 2012-11-18 18:40:11 UTC (rev 53899)
+++ grass/trunk/gui/wxpython/modules/extensions.py 2012-11-18 19:00:14 UTC (rev 53900)
@@ -34,9 +34,95 @@
from core.gcmd import GError, RunCommand
from core.utils import SetAddOnPath
from gui_core.forms import GUI
-from gui_core.widgets import ItemTree, GListCtrl, SearchModuleWidget
+from gui_core.widgets import ItemTree, GListCtrl, SearchModuleWidget, EVT_MODULE_SELECTED
+class ExtensionModulesData(object):
+ """!Holds information about modules.
+
+ @todo add doctest
+ """
+ def __init__(self, modulesDesc):
+
+ self.moduleDesc = modulesDesc
+ self.moduleDescOriginal = modulesDesc
+
+ def GetCommandDesc(self, cmd):
+ """!Gets the description for a given module (command).
+
+ If the given module is not available, an empty string is returned.
+
+ \code
+ print data.GetCommandDesc('r.info')
+ Outputs basic information about a raster map.
+ \endcode
+ """
+ if cmd in self.moduleDesc:
+ return self.moduleDesc[cmd]['description']
+
+ return ''
+
+ def GetCommandItems(self):
+ """!Gets list of available modules (commands).
+
+ The list contains available module names.
+
+ \code
+ print data.GetCommandItems()[0:4]
+ ['d.barscale', 'd.colorlist', 'd.colortable', 'd.correlate']
+ \endcode
+ """
+ items = self.moduleDesc.keys()
+ items.sort()
+
+ return items
+
+ def FindModules(self, text, findIn):
+ """!Finds modules according to given text.
+
+ @param text string to search
+ @param findIn where to search for text
+ (allowed values are 'description', 'keywords' and 'command')
+ """
+ modules = dict()
+ iFound = 0
+ for module, data in self.moduleDescOriginal.iteritems():
+ found = False
+ if findIn == 'description':
+ if text in data['description']:
+ found = True
+ elif findIn == 'keywords':
+ if text in data['keywords']:
+ found = True
+ elif findIn == 'command':
+ if module[:len(text)] == text:
+ found = True
+ else:
+ raise ValueError("Parameter findIn is not valid")
+
+ if found:
+ iFound += 1
+ modules[module] = data
+ return modules, iFound
+
+ def SetFilter(self, data = None):
+ """!Sets filter modules
+
+ If @p data is not specified, module dictionary is derived
+ from an internal data structures.
+
+ @todo Document this method.
+
+ @param data data dict
+ """
+ if data:
+ self.moduleDesc = data
+ else:
+ self.moduleDesc = self.moduleDescOriginal
+
+ def SetData(self, data):
+ self.moduleDesc = self.moduleDescOriginal = data
+
class InstallExtensionWindow(wx.Frame):
def __init__(self, parent, id = wx.ID_ANY,
title = _("Fetch & install extension from GRASS Addons"), **kwargs):
@@ -57,12 +143,15 @@
self.fullDesc = wx.CheckBox(parent = self.panel, id = wx.ID_ANY,
label = _("Fetch full info including description and keywords"))
self.fullDesc.SetValue(True)
+
+ self.tree = ExtensionTree(parent = self.panel, log = parent.GetLogWindow())
- self.search = SearchModuleWidget(parent = self.panel, modulesData = None)
- self.search.SetSelection(0)
+ self.modulesData = ExtensionModulesData(modulesDesc = self.tree.GetModules())
+ self.search = SearchModuleWidget(parent = self.panel, modulesData = self.modulesData,
+ showChoice = False)
+ self.search.SetSelection(0)
+ self.search.Bind(EVT_MODULE_SELECTED, self.OnShowItem)
- self.tree = ExtensionTree(parent = self.panel, log = parent.GetLogWindow())
-
self.optionBox = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
label = " %s " % _("Options"))
if sys.platform == 'win32':
@@ -191,8 +280,8 @@
return
self.tree.SearchItems(element = element,
- value = event.GetString())
-
+ value = event.GetEventObject().GetValue())
+
nItems = len(self.tree.itemsMarked)
if event.GetString():
self.SetStatusText(_("%d items match") % nItems, 0)
@@ -210,6 +299,8 @@
wx.BeginBusyCursor()
self.SetStatusText(_("Fetching list of modules from GRASS-Addons SVN (be patient)..."), 0)
self.tree.Load(url = self.repo.GetValue().strip(), full = self.fullDesc.IsChecked())
+ modulesDesc = self.tree.GetModules()
+ self.modulesData.SetData(modulesDesc)
self.SetStatusText("", 0)
wx.EndBusyCursor()
@@ -385,6 +476,22 @@
"""Check if items are loaded"""
return self._loaded
+ def GetModules(self):
+ modules = {}
+ root = self.GetRootItem()
+ child, cookie = self.GetFirstChild(root)
+ while child and child.IsOk():
+ if self.ItemHasChildren(child):
+ subChild, subCookie = self.GetFirstChild(child)
+ while subChild and subChild.IsOk():
+ name = self.GetItemText(subChild)
+ data = self.GetPyData(subChild)
+ modules[name] = data
+ subChild, subCookie = self.GetNextChild(child, subCookie)
+ child, cookie = self.GetNextChild(root, cookie)
+
+ return modules
+
class UninstallExtensionWindow(wx.Frame):
def __init__(self, parent, id = wx.ID_ANY,
title = _("Uninstall GRASS Addons extensions"), **kwargs):
More information about the grass-commit
mailing list