[GRASS-SVN] r50396 - in grass/trunk/gui/wxpython: core gmodeler
gui_core modules tools
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Jan 23 15:11:21 EST 2012
Author: martinl
Date: 2012-01-23 12:11:20 -0800 (Mon, 23 Jan 2012)
New Revision: 50396
Modified:
grass/trunk/gui/wxpython/core/globalvar.py
grass/trunk/gui/wxpython/core/utils.py
grass/trunk/gui/wxpython/gmodeler/dialogs.py
grass/trunk/gui/wxpython/gmodeler/model.py
grass/trunk/gui/wxpython/gui_core/forms.py
grass/trunk/gui/wxpython/gui_core/goutput.py
grass/trunk/gui/wxpython/gui_core/menu.py
grass/trunk/gui/wxpython/gui_core/prompt.py
grass/trunk/gui/wxpython/modules/extensions.py
grass/trunk/gui/wxpython/tools/update_menudata.py
Log:
wxGUI: reorganize command lists
(merge r50394 from devbr6)
Modified: grass/trunk/gui/wxpython/core/globalvar.py
===================================================================
--- grass/trunk/gui/wxpython/core/globalvar.py 2012-01-23 19:58:23 UTC (rev 50395)
+++ grass/trunk/gui/wxpython/core/globalvar.py 2012-01-23 20:11:20 UTC (rev 50396)
@@ -102,41 +102,38 @@
MAP_WINDOW_SIZE = (800, 600)
GM_WINDOW_SIZE = (500, 600)
-
-"""!File name extension binaries/scripts"""
-if sys.platform == 'win32':
- EXT_BIN = '.exe'
- EXT_SCT = '.py'
-else:
- EXT_BIN = ''
- EXT_SCT = ''
-
-def GetGRASSCmds(scriptsOnly = False):
+def GetGRASSCommands():
"""!Create list of available GRASS commands to use when parsing
string from the command line
-
- @param scriptsOnly True to report only scripts
+
+ @return list of commands (set) and directory of scripts (collected
+ by extension - MS Windows only)
"""
gisbase = os.environ['GISBASE']
cmd = list()
+ if sys.platform == 'win32':
+ scripts = { '.bat' : list(),
+ '.py' : list()
+ }
+ else:
+ scripts = {}
# scan bin/
- if not scriptsOnly and os.path.exists(os.path.join(gisbase, 'bin')):
+ if os.path.exists(os.path.join(gisbase, 'bin')):
for fname in os.listdir(os.path.join(gisbase, 'bin')):
- name, ext = os.path.splitext(fname)
- if not EXT_BIN:
+ if scripts: # win32
+ name, ext = os.path.splitext(fname)
+ if ext != '.manifest':
+ cmd.append(name)
+ if ext in scripts.keys():
+ scripts[ext].append(name)
+ else:
cmd.append(fname)
- elif ext == EXT_BIN:
- cmd.append(name)
- # scan scripts/
- if os.path.exists(os.path.join(gisbase, 'scripts')):
+ # scan scripts/ (not on MS Windows)
+ if not scripts and os.path.exists(os.path.join(gisbase, 'scripts')):
for fname in os.listdir(os.path.join(gisbase, 'scripts')):
- name, ext = os.path.splitext(fname)
- if not EXT_SCT:
- cmd.append(fname)
- elif ext == EXT_SCT:
- cmd.append(name)
+ cmd.append(fname)
# scan gui/scripts/
if os.path.exists(os.path.join(gisbase, 'etc', 'gui', 'scripts')):
@@ -172,24 +169,24 @@
if not os.path.exists(path) or not os.path.isdir(path):
continue
for fname in os.listdir(path):
- name, ext = os.path.splitext(fname)
- if ext in [EXT_BIN, EXT_SCT]:
+ if scripts: # win32
+ name, ext = os.path.splitext(fname)
cmd.append(name)
+ if ext in scripts.keys():
+ scripts[ext].append(name)
else:
cmd.append(fname)
- return set(cmd)
+ return set(cmd), scripts
"""@brief Collected GRASS-relared binaries/scripts"""
-grassCmd = {}
-grassCmd['all'] = GetGRASSCmds()
-grassCmd['script'] = GetGRASSCmds(scriptsOnly = True)
+grassCmd, grassScripts = GetGRASSCommands()
"""@Toolbar icon size"""
toolbarSize = (24, 24)
"""@Is g.mlist available?"""
-if 'g.mlist' in grassCmd['all']:
+if 'g.mlist' in grassCmd:
have_mlist = True
else:
have_mlist = False
Modified: grass/trunk/gui/wxpython/core/utils.py
===================================================================
--- grass/trunk/gui/wxpython/core/utils.py 2012-01-23 19:58:23 UTC (rev 50395)
+++ grass/trunk/gui/wxpython/core/utils.py 2012-01-23 20:11:20 UTC (rev 50396)
@@ -20,7 +20,7 @@
import shlex
import re
-from core.globalvar import ETCDIR
+from core.globalvar import ETCDIR, grassScripts
sys.path.append(os.path.join(ETCDIR, "python"))
from grass.script import core as grass
@@ -742,3 +742,13 @@
return os.path.join(os.getenv('APPDATA'), 'grass%d' % version)
return os.path.join(os.getenv('HOME'), '.grass%d' % version)
+
+def GetRealCmd(cmd):
+ """!Return real command name - only for MS Windows
+ """
+ if sys.platform == 'win32':
+ for ext in grassScripts.keys():
+ if cmd in grassScripts[ext]:
+ return cmd + ext
+
+ return cmd
Modified: grass/trunk/gui/wxpython/gmodeler/dialogs.py
===================================================================
--- grass/trunk/gui/wxpython/gmodeler/dialogs.py 2012-01-23 19:58:23 UTC (rev 50395)
+++ grass/trunk/gui/wxpython/gmodeler/dialogs.py 2012-01-23 20:11:20 UTC (rev 50396)
@@ -206,7 +206,7 @@
"Unable to add new action to the model."))
return
- if cmd[0] not in globalvar.grassCmd['all']:
+ if cmd[0] not in globalvar.grassCmd:
GError(parent = self,
message = _("'%s' is not a GRASS module.\n\n"
"Unable to add new action to the model.") % cmd[0])
Modified: grass/trunk/gui/wxpython/gmodeler/model.py
===================================================================
--- grass/trunk/gui/wxpython/gmodeler/model.py 2012-01-23 19:58:23 UTC (rev 50395)
+++ grass/trunk/gui/wxpython/gmodeler/model.py 2012-01-23 20:11:20 UTC (rev 50396)
@@ -2219,7 +2219,7 @@
def _createPage(self, name, params):
"""!Define notebook page"""
- if name in globalvar.grassCmd['all']:
+ if name in globalvar.grassCmd:
task = gtask.grassTask(name)
else:
task = gtask.grassTask()
Modified: grass/trunk/gui/wxpython/gui_core/forms.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/forms.py 2012-01-23 19:58:23 UTC (rev 50395)
+++ grass/trunk/gui/wxpython/gui_core/forms.py 2012-01-23 20:11:20 UTC (rev 50396)
@@ -2008,9 +2008,7 @@
# parse the interface decription
try:
global _blackList
- if sys.platform == "win32" and cmd[0] in globalvar.grassCmd['script']:
- cmd[0] += globalvar.EXT_SCT
- self.grass_task = gtask.parse_interface(cmd[0],
+ self.grass_task = gtask.parse_interface(utils.GetRealCmd(cmd[0]),
blackList = _blackList)
except (grass.ScriptError, ValueError), e:
raise gcmd.GException(e.value)
@@ -2164,7 +2162,7 @@
if sys.argv[1] != 'test':
q = wx.LogNull()
cmd = utils.split(sys.argv[1])
- task = gtask.grassTask(cmd[0])
+ task = gtask.grassTask(utils.GetRealCmd(cmd[0]))
task.set_options(cmd[1:])
app = GrassGUIApp(task)
app.MainLoop()
Modified: grass/trunk/gui/wxpython/gui_core/goutput.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/goutput.py 2012-01-23 19:58:23 UTC (rev 50395)
+++ grass/trunk/gui/wxpython/gui_core/goutput.py 2012-01-23 20:11:20 UTC (rev 50396)
@@ -479,7 +479,7 @@
finally:
fileHistory.close()
- if command[0] in globalvar.grassCmd['all']:
+ if command[0] in globalvar.grassCmd:
# send GRASS command without arguments to GUI command interface
# except display commands (they are handled differently)
if self.parent.GetName() == "LayerManager" and \
@@ -529,6 +529,7 @@
else:
# other GRASS commands (r|v|g|...)
task = GUI(show = None).ParseCommand(command)
+
hasParams = False
if task:
options = task.get_options()
@@ -805,7 +806,7 @@
if self.parent.GetName() == "LayerManager":
self.btnCmdAbort.Enable(False)
- if event.cmd[0] not in globalvar.grassCmd['all'] or \
+ if event.cmd[0] not in globalvar.grassCmd or \
event.cmd[0] == 'r.mapcalc':
return
Modified: grass/trunk/gui/wxpython/gui_core/menu.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/menu.py 2012-01-23 19:58:23 UTC (rev 50395)
+++ grass/trunk/gui/wxpython/gui_core/menu.py 2012-01-23 20:11:20 UTC (rev 50396)
@@ -87,7 +87,7 @@
cmd = utils.split(str(gcmd))
except UnicodeError:
cmd = utils.split(EncodeString((gcmd)))
- if cmd and cmd[0] not in globalvar.grassCmd['all']:
+ if cmd and cmd[0] not in globalvar.grassCmd:
menuItem.Enable(False)
rhandler = eval('self.parent.' + handler)
Modified: grass/trunk/gui/wxpython/gui_core/prompt.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/prompt.py 2012-01-23 19:58:23 UTC (rev 50395)
+++ grass/trunk/gui/wxpython/gui_core/prompt.py 2012-01-23 20:11:20 UTC (rev 50396)
@@ -90,7 +90,7 @@
listmix.ColumnSorterMixin.__init__(self, 1)
# set choices (list of GRASS modules)
- self._choicesCmd = globalvar.grassCmd['all']
+ self._choicesCmd = globalvar.grassCmd
self._choicesMap = dict()
for type in ('raster', 'vector'):
self._choicesMap[type] = grass.list_strings(type = type[:4])
@@ -556,7 +556,7 @@
def _getListOfModules(self):
"""!Get list of modules"""
result = dict()
- for module in globalvar.grassCmd['all']:
+ for module in globalvar.grassCmd:
try:
group, name = module.split('.',1)
except ValueError:
@@ -803,7 +803,7 @@
self.OnCmdErase(None)
else:
try:
- self.cmdDesc = gtask.parse_interface(cmd)
+ self.cmdDesc = gtask.parse_interface(utils.GetRealCmd(cmd))
except IOError:
self.cmdDesc = None
@@ -831,7 +831,7 @@
return None
if len(utils.split(str(entry))) > 1:
- if cmd in globalvar.grassCmd['all']:
+ if cmd in globalvar.grassCmd:
toComplete['cmd'] = cmd
if entry[-1] == ' ':
words = entry.split(' ')
@@ -976,7 +976,7 @@
#complete command
if self.toComplete['entity'] == 'command':
- for command in globalvar.grassCmd['all']:
+ for command in globalvar.grassCmd:
if command.find(self.toComplete['cmd']) == 0:
dotNumber = list(self.toComplete['cmd']).count('.')
self.autoCompList.append(command.split('.',dotNumber)[-1])
@@ -1038,10 +1038,10 @@
except IndexError:
cmd = ''
- if cmd not in globalvar.grassCmd['all']:
+ if cmd not in globalvar.grassCmd:
return
- info = gtask.command_info(cmd)
+ info = gtask.command_info(utils.GetRealCmd(cmd))
self.CallTipSetBackground("#f4f4d1")
self.CallTipSetForeground("BLACK")
@@ -1114,11 +1114,12 @@
items = self.GetTextLeft().split()
if len(items) == 1:
cmd = items[0].strip()
- if cmd in globalvar.grassCmd['all'] and \
+ if cmd in globalvar.grassCmd and \
cmd != 'r.mapcalc' and \
(not self.cmdDesc or cmd != self.cmdDesc.get_name()):
+
try:
- self.cmdDesc = gtask.parse_interface(cmd)
+ self.cmdDesc = gtask.parse_interface(utils.GetRealCmd(cmd))
except IOError:
self.cmdDesc = None
event.Skip()
Modified: grass/trunk/gui/wxpython/modules/extensions.py
===================================================================
--- grass/trunk/gui/wxpython/modules/extensions.py 2012-01-23 19:58:23 UTC (rev 50395)
+++ grass/trunk/gui/wxpython/modules/extensions.py 2012-01-23 20:11:20 UTC (rev 50396)
@@ -229,7 +229,7 @@
return
name = self.tree.GetItemText(item)
- globalvar.grassCmd['all'].add(name)
+ globalvar.grassCmd.add(name)
def OnItemSelected(self, event):
"""!Item selected"""
Modified: grass/trunk/gui/wxpython/tools/update_menudata.py
===================================================================
--- grass/trunk/gui/wxpython/tools/update_menudata.py 2012-01-23 19:58:23 UTC (rev 50395)
+++ grass/trunk/gui/wxpython/tools/update_menudata.py 2012-01-23 20:11:20 UTC (rev 50396)
@@ -45,9 +45,9 @@
'g.parser',
'vcolors' ]
- count = len(grassCmd['all'])
+ count = len(grassCmd)
i = 0
- for module in grassCmd['all']:
+ for module in grassCmd:
i += 1
if i % 10 == 0:
grass.info('* %d/%d' % (i, count))
More information about the grass-commit
mailing list