[GRASS-SVN] r49036 -
grass/branches/develbranch_6/gui/wxpython/gui_modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Nov 1 09:10:10 EDT 2011
Author: martinl
Date: 2011-11-01 06:10:10 -0700 (Tue, 01 Nov 2011)
New Revision: 49036
Modified:
grass/branches/develbranch_6/gui/wxpython/gui_modules/menuform.py
Log:
wxGUI/menuform: load file to interactive input widget
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/menuform.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/menuform.py 2011-11-01 12:52:06 UTC (rev 49035)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/menuform.py 2011-11-01 13:10:10 UTC (rev 49036)
@@ -1295,7 +1295,9 @@
ifbb.Bind(wx.EVT_TEXT, self.OnFileText)
- btnSave = wx.Button(parent = which_panel, id = wx.ID_SAVE)
+ btnLoad = wx.Button(parent = which_panel, id = wx.ID_ANY, label = _("&Load"))
+ btnLoad.Bind(wx.EVT_BUTTON, self.OnFileLoad)
+ btnSave = wx.Button(parent = which_panel, id = wx.ID_SAVEAS)
btnSave.Bind(wx.EVT_BUTTON, self.OnFileSave)
which_sizer.Add(item = wx.StaticText(parent = which_panel, id = wx.ID_ANY,
@@ -1304,10 +1306,16 @@
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,
+ btnSizer = wx.BoxSizer(wx.HORIZONTAL)
+ btnSizer.Add(item = btnLoad, proportion = 0,
+ flag = wx.ALIGN_RIGHT | wx.RIGHT, border = 10)
+ btnSizer.Add(item = btnSave, proportion = 0,
+ flag = wx.ALIGN_RIGHT)
+ which_sizer.Add(item = btnSizer, proportion = 0,
flag = wx.ALIGN_RIGHT | wx.RIGHT | wx.TOP, border = 5)
p['wxId'].append(ifbb.GetId())
+ p['wxId'].append(btnLoad.GetId())
p['wxId'].append(btnSave.GetId())
if self.parent.GetName() == 'MainFrame' and self.parent.modeler:
@@ -1457,6 +1465,34 @@
return p['value']
return p.get('default', '')
+ def OnFileLoad(self, event):
+ """!Load file to interactive input"""
+ me = event.GetId()
+ win = dict()
+ for p in self.task.params:
+ if 'wxId' in p and me in p['wxId']:
+ win['file'] = self.FindWindowById(p['wxId'][0])
+ win['text'] = self.FindWindowById(p['wxId'][1])
+ break
+
+ if not win:
+ return
+
+ path = win['file'].GetValue()
+ if not path:
+ gcmd.GMessage(parent = self,
+ message = _("Nothing to load."))
+ return
+
+ data = ''
+ f = open(path, "r")
+ try:
+ data = f.read()
+ finally:
+ f.close()
+
+ win['text'].SetValue(data)
+
def OnFileSave(self, event):
"""!Save interactive input to the file"""
wId = event.GetId()
@@ -1509,7 +1545,9 @@
f = open(filename, "w")
try:
- f.write(text + os.linesep)
+ f.write(text)
+ if text[-1] != os.linesep:
+ f.write(os.linesep)
finally:
f.close()
else:
More information about the grass-commit
mailing list