[GRASS-SVN] r50712 - sandbox/lucadelu
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Feb 7 12:33:43 EST 2012
Author: lucadelu
Date: 2012-02-07 09:33:43 -0800 (Tue, 07 Feb 2012)
New Revision: 50712
Modified:
sandbox/lucadelu/r.li.setup.py
Log:
r.li.setup improvement
Modified: sandbox/lucadelu/r.li.setup.py
===================================================================
--- sandbox/lucadelu/r.li.setup.py 2012-02-07 13:24:00 UTC (rev 50711)
+++ sandbox/lucadelu/r.li.setup.py 2012-02-07 17:33:43 UTC (rev 50712)
@@ -58,8 +58,7 @@
self.rlipath = os.path.join(os.environ['HOME'], '.grass%d' % self.major_version, 'r.li')
#check if self.rlipath exists
self.CheckFolder()
- #return all the configuration files in self.rlipath
- self.listfiles = os.listdir(self.rlipath)
+ self.listfiles = self.ListFiles()
###END VARIABLES
#init of frame
wx.Frame.__init__(self, parent = parent, id = id, title = title, **kwargs)
@@ -77,12 +76,15 @@
self.btn_remove = wx.Button(parent = self.panel, id = wx.ID_ANY, label = _("Remove"))
self.btn_remove.SetToolTipString(_('Remove a configuration file'))
self.btn_new = wx.Button(parent = self.panel, id = wx.ID_ANY, label = _("Create"))
- self.btn_new.SetToolTipString(_('Create a new configuration file'))
+ self.btn_new.SetToolTipString(_('Create a new configuration file'))
+ self.btn_rename = wx.Button(parent = self.panel, id = wx.ID_ANY, label = _("Rename"))
+ self.btn_rename.SetToolTipString(_('Renane a configuration file'))
#set action for button
self.btn_close.Bind(wx.EVT_BUTTON, self.OnClose)
self.btn_help.Bind(wx.EVT_BUTTON, self.OnHelp)
self.btn_remove.Bind(wx.EVT_BUTTON, self.OnRemove)
- self.btn_new.Bind(wx.EVT_BUTTON, self.OnNew)
+ self.btn_new.Bind(wx.EVT_BUTTON, self.OnNew)
+ self.btn_rename.Bind(wx.EVT_BUTTON, self.OnRename)
self._layout()
###END BUTTONS
@@ -103,6 +105,7 @@
###BUTTONS
buttonSizer = wx.BoxSizer(wx.HORIZONTAL)
buttonSizer.Add(item = self.btn_new, flag = wx.ALL, border = 5)
+ buttonSizer.Add(item = self.btn_rename, flag = wx.ALL, border = 5)
buttonSizer.Add(item = self.btn_remove, flag = wx.ALL, border = 5)
buttonSizer.Add(item = self.btn_help, flag = wx.ALL, border = 5)
buttonSizer.Add(item = self.btn_close, flag = wx.ALL, border = 5)
@@ -128,7 +131,14 @@
def ListFiles(self):
"""!Check the configuration files inside the path"""
- return os.listdir(self.rlipath)
+ # list of configuration file
+ listfiles = []
+ #return all the configuration files in self.rlipath, check if there are
+ #link or directory and doesn't add them
+ for l in os.listdir(self.rlipath):
+ if os.path.isfile(os.path.join(self.rlipath,l)):
+ listfiles.append(l)
+ return listfiles
def OnClose(self,event):
"""!Close window"""
@@ -148,7 +158,28 @@
def OnNew(self, event):
"""!Remove configuration file from path and update the list"""
RLIWizard(self)
+ self.listfiles = self.ListFiles()
+ self.listfileBox.Clear()
+ self.listfileBox.Set(self.listfiles)
+ def OnRename(self, event):
+ """!Rename an existing configuration file"""
+ try:
+ confile = self.listfiles[self.listfileBox.GetSelections()[0]]
+ except:
+ gcmd.GMessage(parent = self,
+ message = _("You have to select a configuration file"))
+ return
+ dlg = wx.TextEntryDialog(parent = self.parent,
+ message = _('Set te new name for %s configuration file') % confile,
+ caption = _('Rename configuration file'))
+ if dlg.ShowModal() == wx.ID_OK:
+ res = dlg.GetValue()
+ os.rename(os.path.join(self.rlipath,confile),os.path.join(self.rlipath,res))
+ self.listfiles = self.ListFiles()
+ self.listfileBox.Clear()
+ self.listfileBox.Set(self.listfiles)
+
class RLIWizard(object):
"""
Start wizard here and finish wizard here
@@ -157,7 +188,9 @@
def __init__(self, parent):
self.parent = parent # GMFrame
self.wizard = wiz.Wizard(parent=parent, id=wx.ID_ANY, title=_("Create new configuration file for r.li modules"))
-
+ self.major_version = int(grass.version()['version'].split('.', 1)[0])
+ self.rlipath = os.path.join(os.environ['HOME'], '.grass%d' % self.major_version, 'r.li')
+
#pages
self.startpage = FirstPage(self.wizard, self)
self.keyboardpage = KeybordPage(self.wizard, self)
@@ -191,13 +224,13 @@
style = wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
if dlg.ShowModal() == wx.ID_NO:
- dlg.Destroy()
- print "no"
self._cleanup()
+ dlg.Destroy()
else:
+ self._write_confile()
+ self._cleanup()
dlg.Destroy()
- print "yes"
- self._cleanup()
+
else:
self.wizard.Destroy()
gcmd.GMessage(parent = self.parent,
@@ -205,13 +238,68 @@
"Configuration file not created."))
self._cleanup()
+ def _write_confile(self):
+ """Write the configuration file"""
+ f = open(os.path.join(self.rlipath,self.startpage.conf_name),'w')
+ self._write_region(f)
+ self._write_area(f)
+ f.close()
+
+ def _temp_region(self):
+ # save current settings:
+ grass.use_temp_region()
+
+ # Temporarily aligning region resolution to $RASTER resolution
+ # keep boundary settings
+ grass.run_command('g.region', rast = self.startpage.rast)
+ self.gregion = grass.region()
+
+
+ def _write_region(self,fil):
+ """Write the region"""
+ self.rasterinfo = grast.raster_info(self.startpage.rast)
+ if self.startpage.region == 'whole':
+ fil.write("SAMPLINGFRAME 0|0|1|1\n")
+ self._temp_region()
+ self.SF_X = 0.0
+ self.SF_Y = 0.0
+ self.SF_RL = abs(int(float(self.gregion['s']-self.gregion['n']) / float(self.gregion['nsres'])))
+ self.SF_CL = abs(int(float(self.gregion['e']-self.gregion['w']) / float(self.gregion['ewres'])))
+ elif self.startpage.region == 'key':
+ self._temp_region()
+ self.SF_X = self.keyboardpage.col_up
+ self.SF_Y = self.keyboardpage.row_up
+ self.SF_RL = self.keyboardpage.row_len
+ self.SF_CL = self.keyboardpage.col_len
+ per_x = float(self.SF_X) / float(self.rasterinfo['cols'])
+ per_y = float(self.SF_Y) / float(self.rasterinfo['rows'])
+ per_rl = float(self.SF_RL) / float(self.rasterinfo['cols'])
+ per_cl = float(self.SF_CL) / float(self.rasterinfo['cols'])
+ fil.write("SAMPLINGFRAME %f|%f|%f|%f\n" % (per_x,per_y,per_rl,per_cl))
+
+ def _write_area(self,fil):
+ """Write the region"""
+ if self.samplingareapage.samplingtype == 'whole':
+ x = float(self.SF_X) / float(self.rasterinfo['cols'])
+ cl = float(self.SF_CL) / float(self.rasterinfo['cols'])
+ y = float(self.SF_Y) / float(self.rasterinfo['rows'])
+ rl = float(self.SF_RL) / float(self.rasterinfo['rows'])
+ if self.startpage.region == 'whole':
+ fil.write("SAMPLEAREA %.1f|%.1f|%.1f|%.1f\n" % (x,y,rl,cl))
+ elif self.startpage.region == 'key':
+ fil.write("SAMPLEAREA %f|%f|%f|%f\n" % (x,y,rl,cl))
+
+
def _cleanup(self):
+ """Clean all the variables to save into configuration file"""
self.startpage.conf_name = ''
self.startpage.rast = ''
self.startpage.vect = ''
self.startpage.region = 'whole'
self.keyboardpage.col_len = ''
- self.keyboardpage.row_len = ''
+ self.keyboardpage.col_up = ''
+ self.keyboardpage.row_len = ''
+ self.keyboardpage.row_up = ''
self.samplingareapage.samplingtype = 'whole'
self.samplingunitskey.sizew = ''
self.samplingunitskey.sizeh = ''
@@ -418,37 +506,21 @@
"""!Sets the name of configuration file"""
self.col_up = self.ColUpLefttxt.GetValue()
checkValue(self.col_up)
- if self.col_up == '':
- wx.FindWindowById(wx.ID_FORWARD).Enable(False)
- else:
- wx.FindWindowById(wx.ID_FORWARD).Enable(True)
def OnRowLeft(self,event):
"""!Sets the name of configuration file"""
self.row_up = self.RowUpLefttxt.GetValue()
checkValue(self.row_up)
- if self.row_up == '':
- wx.FindWindowById(wx.ID_FORWARD).Enable(False)
- else:
- wx.FindWindowById(wx.ID_FORWARD).Enable(True)
def OnColLen(self,event):
"""!Sets the name of configuration file"""
self.col_len = self.ColLentxt.GetValue()
checkValue(self.col_len)
- if self.col_len == '':
- wx.FindWindowById(wx.ID_FORWARD).Enable(False)
- else:
- wx.FindWindowById(wx.ID_FORWARD).Enable(True)
def OnRowLeft(self,event):
"""!Sets the name of configuration file"""
self.row_len = self.RowLentxt.GetValue()
checkValue(self.row_len)
- if self.row_len == '':
- wx.FindWindowById(wx.ID_FORWARD).Enable(False)
- else:
- wx.FindWindowById(wx.ID_FORWARD).Enable(True)
def OnEnterPage(self, event):
"""!Sets the default values, for the entire map
@@ -470,6 +542,7 @@
if self.row_len == '' or self.col_len == '' or self.row_up == '' or self.col_up == '':
wx.FindWindowById(wx.ID_FORWARD).Enable(False)
else:
+ print self.row_len, self.col_len, self.row_up, self.col_up
wx.FindWindowById(wx.ID_FORWARD).Enable(True)
class SamplingAreasPage(TitledPage):
More information about the grass-commit
mailing list