[GRASS-SVN] r50394 - in grass/branches/develbranch_6/gui/wxpython:
core gmodeler gui_core modules tools
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Jan 23 14:47:29 EST 2012
Author: martinl
Date: 2012-01-23 11:47:29 -0800 (Mon, 23 Jan 2012)
New Revision: 50394
Modified:
grass/branches/develbranch_6/gui/wxpython/core/globalvar.py
grass/branches/develbranch_6/gui/wxpython/core/utils.py
grass/branches/develbranch_6/gui/wxpython/gmodeler/dialogs.py
grass/branches/develbranch_6/gui/wxpython/gmodeler/model.py
grass/branches/develbranch_6/gui/wxpython/gui_core/forms.py
grass/branches/develbranch_6/gui/wxpython/gui_core/goutput.py
grass/branches/develbranch_6/gui/wxpython/gui_core/menu.py
grass/branches/develbranch_6/gui/wxpython/gui_core/prompt.py
grass/branches/develbranch_6/gui/wxpython/modules/extensions.py
grass/branches/develbranch_6/gui/wxpython/tools/update_menudata.py
Log:
wxGUI: reorganize command lists
Modified: grass/branches/develbranch_6/gui/wxpython/core/globalvar.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/core/globalvar.py 2012-01-23 17:50:57 UTC (rev 50393)
+++ grass/branches/develbranch_6/gui/wxpython/core/globalvar.py 2012-01-23 19:47:29 UTC (rev 50394)
@@ -102,40 +102,37 @@
MAP_WINDOW_SIZE = (800, 600)
GM_WINDOW_SIZE = (500, 600)
-"""!File name extension binaries/scripts"""
-if sys.platform == 'win32':
- EXT_BIN = '.exe'
- EXT_SCT = ''
-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:
- cmd.append(fname)
- elif ext == EXT_BIN:
+ 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)
- # 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')):
@@ -149,27 +146,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 not scriptsOnly and ext == EXT_BIN:
- cmd.append(name)
- if scriptsOnly:
- if ext == EXT_SCT:
- cmd.append(name)
- elif ext == '.py':
- cmd.append(fname)
+ 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/branches/develbranch_6/gui/wxpython/core/utils.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/core/utils.py 2012-01-23 17:50:57 UTC (rev 50393)
+++ grass/branches/develbranch_6/gui/wxpython/core/utils.py 2012-01-23 19:47:29 UTC (rev 50394)
@@ -21,7 +21,7 @@
import re
import locale
-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
@@ -764,3 +764,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/branches/develbranch_6/gui/wxpython/gmodeler/dialogs.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gmodeler/dialogs.py 2012-01-23 17:50:57 UTC (rev 50393)
+++ grass/branches/develbranch_6/gui/wxpython/gmodeler/dialogs.py 2012-01-23 19:47:29 UTC (rev 50394)
@@ -207,7 +207,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/branches/develbranch_6/gui/wxpython/gmodeler/model.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gmodeler/model.py 2012-01-23 17:50:57 UTC (rev 50393)
+++ grass/branches/develbranch_6/gui/wxpython/gmodeler/model.py 2012-01-23 19:47:29 UTC (rev 50394)
@@ -2221,7 +2221,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/branches/develbranch_6/gui/wxpython/gui_core/forms.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_core/forms.py 2012-01-23 17:50:57 UTC (rev 50393)
+++ grass/branches/develbranch_6/gui/wxpython/gui_core/forms.py 2012-01-23 19:47:29 UTC (rev 50394)
@@ -1833,7 +1833,7 @@
# parse the interface decription
try:
global _blackList
- 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)
@@ -1985,10 +1985,7 @@
if sys.argv[1] != 'test':
q = wx.LogNull()
cmd = utils.split(sys.argv[1])
- if sys.platform == 'win32':
- if cmd[0] in globalvar.grassCmd['script']:
- cmd[0] += globalvar.EXT_SCT
- task = gtask.grassTask(cmd[0])
+ task = gtask.grassTask(utils.GetRealCmd(cmd[0]))
task.set_options(cmd[1:])
app = GrassGUIApp(task)
app.MainLoop()
Modified: grass/branches/develbranch_6/gui/wxpython/gui_core/goutput.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_core/goutput.py 2012-01-23 17:50:57 UTC (rev 50393)
+++ grass/branches/develbranch_6/gui/wxpython/gui_core/goutput.py 2012-01-23 19:47:29 UTC (rev 50394)
@@ -474,7 +474,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 \
@@ -522,10 +522,6 @@
else:
# other GRASS commands (r|v|g|...)
- if sys.platform == 'win32':
- if command[0] in globalvar.grassCmd['script']:
- command[0] += globalvar.EXT_SCT
-
hasParams = False
if command[0] != 'r.mapcalc':
task = GUI(show = None).ParseCommand(command)
@@ -806,7 +802,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/branches/develbranch_6/gui/wxpython/gui_core/menu.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_core/menu.py 2012-01-23 17:50:57 UTC (rev 50393)
+++ grass/branches/develbranch_6/gui/wxpython/gui_core/menu.py 2012-01-23 19:47:29 UTC (rev 50394)
@@ -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/branches/develbranch_6/gui/wxpython/gui_core/prompt.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_core/prompt.py 2012-01-23 17:50:57 UTC (rev 50393)
+++ grass/branches/develbranch_6/gui/wxpython/gui_core/prompt.py 2012-01-23 19:47:29 UTC (rev 50394)
@@ -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,11 +803,8 @@
self.UpdateCmdHistory([cmd])
self.OnCmdErase(None)
else:
- if sys.platform == 'win32':
- if cmd in globalvar.grassCmd['script']:
- cmd += globalvar.EXT_SCT
try:
- self.cmdDesc = gtask.parse_interface(cmd)
+ self.cmdDesc = gtask.parse_interface(utils.GetRealCmd(cmd))
except IOError:
self.cmdDesc = None
@@ -835,7 +832,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(' ')
@@ -980,7 +977,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])
@@ -1042,15 +1039,11 @@
except IndexError:
cmd = ''
- if cmd not in globalvar.grassCmd['all']:
+ if cmd not in globalvar.grassCmd:
return
- if sys.platform == 'win32':
- if cmd in globalvar.grassCmd['script']:
- cmd += globalvar.EXT_SCT
+ info = gtask.command_info(utils.GetRealCmd(cmd))
- info = gtask.command_info(cmd)
-
self.CallTipSetBackground("#f4f4d1")
self.CallTipSetForeground("BLACK")
self.CallTipShow(pos, info['usage'] + '\n\n' + info['description'])
@@ -1122,14 +1115,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()):
- if sys.platform == 'win32':
- if cmd in globalvar.grassCmd['script']:
- cmd += globalvar.EXT_SCT
+
try:
- self.cmdDesc = gtask.parse_interface(cmd)
+ self.cmdDesc = gtask.parse_interface(utils.GetRealCmd(cmd))
except IOError:
self.cmdDesc = None
event.Skip()
Modified: grass/branches/develbranch_6/gui/wxpython/modules/extensions.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/modules/extensions.py 2012-01-23 17:50:57 UTC (rev 50393)
+++ grass/branches/develbranch_6/gui/wxpython/modules/extensions.py 2012-01-23 19:47:29 UTC (rev 50394)
@@ -227,7 +227,7 @@
return
name = self.tree.GetItemText(item)
- globalvar.grassCmd['all'].add(name)
+ globalvar.grassCmd.add(name)
def OnItemSelected(self, event):
"""!Item selected"""
Modified: grass/branches/develbranch_6/gui/wxpython/tools/update_menudata.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/tools/update_menudata.py 2012-01-23 17:50:57 UTC (rev 50393)
+++ grass/branches/develbranch_6/gui/wxpython/tools/update_menudata.py 2012-01-23 19:47:29 UTC (rev 50394)
@@ -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