[GRASS-SVN] r41448 - in grass/branches/develbranch_6:
gui/wxpython/gui_modules lib/gis
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Mar 15 10:15:31 EDT 2010
Author: martinl
Date: 2010-03-15 10:15:30 -0400 (Mon, 15 Mar 2010)
New Revision: 41448
Modified:
grass/branches/develbranch_6/gui/wxpython/gui_modules/menuform.py
grass/branches/develbranch_6/lib/gis/parser.c
Log:
bugfix #928 - fails to pre-seed the GUI
(merge r41447 from trunk)
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/menuform.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/menuform.py 2010-03-15 14:06:01 UTC (rev 41447)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/menuform.py 2010-03-15 14:15:30 UTC (rev 41448)
@@ -55,6 +55,7 @@
import types
from threading import Thread
import Queue
+import shlex
### i18N
import gettext
@@ -295,24 +296,24 @@
wx.PostEvent(self.parent, event)
class grassTask:
- """
- This class holds the structures needed for both filling by the parser and
- use by the interface constructor.
+ """!This class holds the structures needed for both filling by the
+ parser and use by the interface constructor.
- Use as either grassTask() for empty definition or grassTask( 'grass.command' )
- for parsed filling.
+ Use as either grassTask() for empty definition or
+ grassTask('grass.command' ) for parsed filling.
"""
def __init__(self, grassModule = None):
self.name = _('unknown')
- self.params = []
+ self.params = list()
self.description = ''
self.label = ''
- self.flags = []
- self.keywords = []
+ self.flags = list()
+ self.keywords = list()
+
if grassModule is not None:
processTask(tree = etree.fromstring(getInterfaceDescription(grassModule)),
task = self)
-
+
def get_name(self):
"""!Get task name"""
return self.name
@@ -409,6 +410,17 @@
return cmd
+ def set_options(self, opts):
+ """!Set flags and parameters
+
+ @param opts list of flags and parameters"""
+ for opt in opts:
+ if opt[0] == '-': # flag
+ self.set_flag(opt.lstrip('-'), True)
+ else: # parameter
+ key, value = opt.split('=', 1)
+ self.set_param(key, value)
+
class processTask:
"""!A ElementTree handler for the --interface-description output,
as defined in grass-interface.dtd. Extend or modify this and the
@@ -508,9 +520,9 @@
return default
def GetTask(self):
- """!Get grassTask intance"""
+ """!Get grassTask instance"""
return self.task
-
+
class helpPanel(wx.html.HtmlWindow):
"""
This panel holds the text from GRASS docs.
@@ -585,21 +597,20 @@
self.Ok = False
class mainFrame(wx.Frame):
- """
- This is the Frame containing the dialog for options input.
+ """!This is the Frame containing the dialog for options input.
The dialog is organized in a notebook according to the guisections
defined by each GRASS command.
- If run with a parent, it may Apply, Ok or Cancel; the latter two close the dialog.
- The former two trigger a callback.
+ If run with a parent, it may Apply, Ok or Cancel; the latter two
+ close the dialog. The former two trigger a callback.
If run standalone, it will allow execution of the command.
- The command is checked and sent to the clipboard when clicking 'Copy'.
+ The command is checked and sent to the clipboard when clicking
+ 'Copy'.
"""
def __init__(self, parent, ID, task_description, get_dcmd=None, layer=None):
-
self.get_dcmd = get_dcmd
self.layer = layer
self.task = task_description
@@ -1682,33 +1693,32 @@
event.Skip()
-def getInterfaceDescription( cmd ):
- """
- Returns the XML description for the GRASS cmd.
+def getInterfaceDescription(cmd):
+ """!Returns the XML description for the GRASS cmd.
The DTD must be located in $GISBASE/etc/grass-interface.dtd,
otherwise the parser will not succeed.
- Note: 'cmd' is given as string
+ @param cmd command (name of GRASS module)
"""
cmdout = os.popen(cmd + r' --interface-description', "r").read()
- if not len(cmdout) > 0 :
+ if not len(cmdout) > 0:
raise IOError, _("Unable to fetch interface description for command '%s'.") % cmd
- p = re.compile( '(grass-interface.dtd)')
- p.search( cmdout )
+ p = re.compile('(grass-interface.dtd)')
+ p.search(cmdout)
cmdout = p.sub(globalvar.ETCDIR + r'/grass-interface.dtd', cmdout)
+
return cmdout
class GrassGUIApp(wx.App):
+ """!Stand-alone GRASS command GUI
"""
- Stand-alone GRASS command GUI
- """
def __init__(self, grass_task):
self.grass_task = grass_task
wx.App.__init__(self, False)
-
+
def OnInit(self):
- self.mf = mainFrame(parent=None, ID=wx.ID_ANY, task_description=self.grass_task)
+ self.mf = mainFrame(parent = None, ID = wx.ID_ANY, task_description = self.grass_task)
self.mf.CentreOnScreen()
self.mf.Show(True)
self.SetTopWindow(self.mf)
@@ -1889,11 +1899,14 @@
if __name__ == "__main__":
if len(sys.argv) == 1:
- print _("usage: %s <grass command>") % sys.argv[0]
- sys.exit()
+ sys.exit(_("usage: %s <grass command>") % sys.argv[0])
if sys.argv[1] != 'test':
- q=wx.LogNull()
- GrassGUIApp( grassTask( sys.argv[1] ) ).MainLoop()
+ q = wx.LogNull()
+ cmd = shlex.split(sys.argv[1])
+ task = grassTask(cmd[0])
+ task.set_options(cmd[1:])
+ app = GrassGUIApp(task)
+ app.MainLoop()
else: #Test
# Test grassTask from within a GRASS session
if os.getenv("GISBASE") is not None:
Modified: grass/branches/develbranch_6/lib/gis/parser.c
===================================================================
--- grass/branches/develbranch_6/lib/gis/parser.c 2010-03-15 14:06:01 UTC (rev 41447)
+++ grass/branches/develbranch_6/lib/gis/parser.c 2010-03-15 14:15:30 UTC (rev 41448)
@@ -958,15 +958,15 @@
}
}
+ /* Split options where multiple answers are OK */
+ split_opts();
+
/* Run the gui if it was specifically requested */
if (force_gui) {
G_gui();
return -1;
}
- /* Split options where multiple answers are OK */
- split_opts();
-
/* Check multiple options */
error += check_multiple_opts();
@@ -976,8 +976,7 @@
/* Make sure all required options are set */
error += check_required();
-
-
+
if (error) {
if (G_verbose() > G_verbose_min())
G_usage();
@@ -1998,7 +1997,7 @@
sprintf(script, "%s/etc/wxpython/gui_modules/menuform.py",
getenv("GISBASE"));
- G_spawn(getenv("GRASS_PYTHON"), getenv("GRASS_PYTHON"), script, pgm_name, NULL);
+ G_spawn(getenv("GRASS_PYTHON"), getenv("GRASS_PYTHON"), script, G_recreate_command(), NULL);
}
/**
More information about the grass-commit
mailing list