[GRASS-SVN] r68411 - grass/trunk/gui/wxpython/gui_core
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun May 8 20:43:12 PDT 2016
Author: wenzeslaus
Date: 2016-05-08 20:43:12 -0700 (Sun, 08 May 2016)
New Revision: 68411
Modified:
grass/trunk/gui/wxpython/gui_core/pyedit.py
Log:
pyedit: specify CLI parameters for script using a dialog (alternative to module GUI dialogs)
Modified: grass/trunk/gui/wxpython/gui_core/pyedit.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/pyedit.py 2016-05-09 03:14:08 UTC (rev 68410)
+++ grass/trunk/gui/wxpython/gui_core/pyedit.py 2016-05-09 03:43:12 UTC (rev 68411)
@@ -266,6 +266,7 @@
self.filename = None
self.tempfile = None # bool, make them strings for better code
self.overwrite = False
+ self.parameters = None
def OnRun(self, event):
"""Run Python script"""
@@ -284,6 +285,7 @@
mode = stat.S_IMODE(os.lstat(self.filename)[stat.ST_MODE])
os.chmod(self.filename, mode | stat.S_IXUSR)
else:
+ # always save automatically before running
fd = open(self.filename, "w")
try:
fd.write(self.body.GetText())
@@ -298,7 +300,10 @@
env = os.environ.copy()
if self.overwrite:
env['GRASS_OVERWRITE'] = '1'
- self.giface.RunCmd([fd.name], env=env)
+ cmd = [fd.name]
+ if self.parameters:
+ cmd.extend(self.parameters)
+ self.giface.RunCmd(cmd, env=env)
def SaveAs(self):
"""Save python script to file"""
@@ -459,6 +464,24 @@
dlg.Destroy()
return True
+ def OnSetParameters(self, event):
+ """Handle setting CLI parameters for the script (asks for input)"""
+ dlg = wx.TextEntryDialog(
+ parent=self.guiparent,
+ caption=_("Set parameters for the script"),
+ message=_("Specify command line parameters for the script separated by spaces:"),
+ )
+ if self.parameters:
+ dlg.SetValue(" ".join(self.parameters))
+ # TODO: modality might not be needed here if we bind the events
+ if dlg.ShowModal() == wx.ID_OK:
+ text = dlg.GetValue().strip()
+ # TODO: split in the same way as in console
+ if text:
+ self.parameters = text.split()
+ else:
+ self.parameters = None
+
def OnHelp(self, event):
# inspired by g.manual but simple not using GRASS_HTML_BROWSER
# not using g.manual because it does not show
@@ -501,6 +524,7 @@
label=_('Save (Ctrl+S)')),
'run': MetaIcon(img='execute',
label=_('Run (Ctrl+R)')),
+ # TODO: better icons for overwrite modes
'overwriteTrue': MetaIcon(img='locked',
label=_('Activate overwrite')),
'overwriteFalse': MetaIcon(img='unlocked',
@@ -532,6 +556,7 @@
self.parent.OnHelp),
))
+ # TODO: add overwrite also to the menu and sync with toolbar
def OnSetOverwrite(self, event):
if self.GetToolState(self.overwrite):
self.SetToolNormalBitmap(self.overwrite,
@@ -652,7 +677,10 @@
overwrite = property(_get_overwrite, _set_overwrite,
doc="Tells if overwrite should be used")
+ def OnSetParameters(self, *args, **kwargs):
+ self.controller.OnSetParameters(*args, **kwargs)
+
def main():
"""Test application (potentially useful as g.gui.pyedit)"""
app = wx.App()
More information about the grass-commit
mailing list