[GRASS-SVN] r48993 -
grass/branches/develbranch_6/gui/wxpython/gui_modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Oct 29 14:25:10 EDT 2011
Author: martinl
Date: 2011-10-29 11:25:10 -0700 (Sat, 29 Oct 2011)
New Revision: 48993
Modified:
grass/branches/develbranch_6/gui/wxpython/gui_modules/menuform.py
Log:
wxGUI/menuform: allow to save text from interactive input
(merge r48991 & r48992 from trunk)
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/menuform.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/menuform.py 2011-10-29 18:20:15 UTC (rev 48992)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/menuform.py 2011-10-29 18:25:10 UTC (rev 48993)
@@ -1290,17 +1290,25 @@
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())
-
- if self.parent.GetName() == 'MainFrame' and self.parent.modeler:
+ p['wxId'].append(btnSave.GetId())
+
+ if self.parent.GetName() == 'MainFrame' and self.parent.modeler:
parChk = wx.CheckBox(parent = which_panel, id = wx.ID_ANY,
label = _("Parameterized in model"))
parChk.SetName('ModelParam')
@@ -1447,6 +1455,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()
@@ -1463,7 +1507,7 @@
f = open(filename, "w")
try:
- f.write(text)
+ f.write(text + os.linesep)
finally:
f.close()
else:
More information about the grass-commit
mailing list