[GRASS-SVN] r48991 - grass/trunk/gui/wxpython/gui_modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Oct 29 14:16:13 EDT 2011
Author: martinl
Date: 2011-10-29 11:16:13 -0700 (Sat, 29 Oct 2011)
New Revision: 48991
Modified:
grass/trunk/gui/wxpython/gui_modules/menuform.py
Log:
wxGUI/menuform: allow to save text from interactive input
Modified: grass/trunk/gui/wxpython/gui_modules/menuform.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/menuform.py 2011-10-29 17:05:03 UTC (rev 48990)
+++ grass/trunk/gui/wxpython/gui_modules/menuform.py 2011-10-29 18:16:13 UTC (rev 48991)
@@ -1384,15 +1384,23 @@
f = open(p['value'])
ifbb.SetValue(''.join(f.readlines()))
f.close()
-
+
ifbb.Bind(wx.EVT_TEXT, self.OnFileText)
+
+ btnSave = wx.Button(parent = which_panel, id = wx.ID_SAVE)
+ btnSave.Bind(wx.EVT_BUTTON, self.OnFileSave)
+
which_sizer.Add(item = wx.StaticText(parent = which_panel, id = wx.ID_ANY,
label = _('or enter values interactively')),
proportion = 0,
flag = wx.EXPAND | wx.RIGHT | wx.LEFT | wx.BOTTOM, border = 5)
which_sizer.Add(item = ifbb, proportion = 1,
flag = wx.EXPAND | wx.RIGHT | wx.LEFT, border = 5)
+ which_sizer.Add(item = btnSave, proportion = 0,
+ flag = wx.ALIGN_RIGHT | wx.RIGHT | wx.TOP, border = 5)
+
p['wxId'].append(ifbb.GetId())
+ p['wxId'].append(btnSave.GetId())
# directory selector
elif p.get('prompt','') != 'color' and p.get('element', '') == 'dir':
@@ -1576,6 +1584,42 @@
return p['value']
return p.get('default', '')
+ def OnFileSave(self, event):
+ """!Save interactive input to the file"""
+ wId = event.GetId()
+ win = {}
+ for p in self.task.params:
+ if wId in p.get('wxId', []):
+ win['file'] = self.FindWindowById(p['wxId'][0])
+ win['text'] = self.FindWindowById(p['wxId'][1])
+ break
+
+ if not win:
+ return
+
+ text = win['text'].GetValue()
+ if not text:
+ gcmd.GMessage(parent = self,
+ message = _("Nothing to save."))
+ return
+
+ dlg = wx.FileDialog(parent = self,
+ message = _("Save input as..."),
+ defaultDir = os.getcwd(),
+ style = wx.SAVE | wx.FD_OVERWRITE_PROMPT)
+
+ if dlg.ShowModal() == wx.ID_OK:
+ path = dlg.GetPath()
+ f = open(path, "w")
+ try:
+ f.write(text + os.linesep)
+ finally:
+ f.close()
+
+ win['file'].SetValue(path)
+
+ dlg.Destroy()
+
def OnFileText(self, event):
"""File input interactively entered"""
text = event.GetString()
More information about the grass-commit
mailing list