[GRASS-SVN] r50953 - sandbox/lucadelu
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Feb 26 18:17:54 EST 2012
Author: lucadelu
Date: 2012-02-26 15:17:54 -0800 (Sun, 26 Feb 2012)
New Revision: 50953
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-26 23:00:05 UTC (rev 50952)
+++ sandbox/lucadelu/r.li.setup.py 2012-02-26 23:17:54 UTC (rev 50953)
@@ -10,6 +10,7 @@
sampling region)
- Keybord (page to insert region areas from keybord)
- SamplingAreas (define sampling area)
+ - SummaryPage (show choosen options)
(C) 2011 by the GRASS Development Team
This program is free software under the GNU General Public License
@@ -30,9 +31,9 @@
import time
from core import globalvar
+from gui_core import gselect
from core import gcmd
from core import utils
-from gui_core import gselect
from location_wizard.wizard import TitledPage as TitledPage
from grass.script import core as grass
from grass.script import raster as grast
@@ -47,17 +48,23 @@
else:
wx.FindWindowById(wx.ID_FORWARD).Enable(True)
+def retRLiPath():
+ major_version = int(grass.version()['version'].split('.', 1)[0])
+ rlipath = os.path.join(os.environ['HOME'], '.grass%d' % major_version, 'r.li')
+ if os.path.exists(rlipath):
+ return rlipath
+ else:
+ os.mkdir(rlipath)
+ return rlipath
+
class RLiSetupFrame(wx.Frame):
def __init__(self, parent, id = wx.ID_ANY,
style = wx.DEFAULT_FRAME_STYLE | wx.RESIZE_BORDER,
title = _("r.li.setup"), **kwargs):
- ###VARIABLES
+ ###VARIABLES
self.parent = parent
self.cmd = "r.li.setup"
- 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')
- #check if self.rlipath exists
- self.CheckFolder()
+ self.rlipath = retRLiPath()
self.listfiles = self.ListFiles()
###END VARIABLES
#init of frame
@@ -121,14 +128,6 @@
sizer.Fit(self.panel)
self.Layout()
- def CheckFolder(self):
- """!Check if the folder of r.li it is present in the .grass7 path"""
- if os.path.exists(self.rlipath):
- return
- else:
- os.mkdir(self.rlipath)
- return
-
def ListFiles(self):
"""!Check the configuration files inside the path"""
# list of configuration file
@@ -188,9 +187,7 @@
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')
-
+ self.rlipath = retRLiPath()
#pages
self.startpage = FirstPage(self.wizard, self)
self.keyboardpage = KeybordPage(self.wizard, self)
@@ -346,17 +343,17 @@
flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
self.sizer.Add(item = self.vectselect, border=5, pos=(3, 2),
flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- #define sempling region
- self.sempling_reg = wx.RadioBox(parent=self, id=wx.ID_ANY,
- label= _("Define sempling region (region for analysis)"),
- choices=[_('Whole map layer'),
- _('Keyboard setting'), _('Draw the sempling frame')],
- majorDimension=wx.RA_SPECIFY_COLS)
- self.sizer.Add(item=self.sempling_reg,
+ #define sampling region
+ self.sampling_reg = wx.RadioBox(parent=self, id=wx.ID_ANY,
+ label= _("Define sampling region (region for analysis)"),
+ choices=[_('Whole map layer'),
+ _('Keyboard setting'), _('Draw the sampling frame')],
+ majorDimension=wx.RA_SPECIFY_COLS)
+ self.sizer.Add(item=self.sampling_reg,
flag=wx.ALIGN_CENTER | wx.ALL | wx.EXPAND, border=5,
pos=(5, 1), span=(5, 2))
#bindings
- self.sempling_reg.Bind(wx.EVT_RADIOBOX, self.OnSempling)
+ self.sampling_reg.Bind(wx.EVT_RADIOBOX, self.OnSampling)
self.newconftxt.Bind(wx.EVT_KILL_FOCUS, self.OnName)
self.vectselect.Bind(wx.EVT_TEXT, self.OnVector)
self.mapselect.Bind(wx.EVT_TEXT, self.OnRast)
@@ -366,7 +363,7 @@
wx.FindWindowById(wx.ID_FORWARD).Enable(False)
- def OnSempling(self,event):
+ def OnSampling(self,event):
"""!Change map type"""
if event.GetInt() == 0:
self.region = 'whole'
@@ -387,25 +384,30 @@
wx.FindWindowById(wx.ID_FORWARD).Enable(True)
def OnName(self,event):
- """!Sets the name of configuration file"""
- self.conf_name = self.newconftxt.GetValue()
- if self.region != '' and self.rast != '' and self.conf_name != '' and not \
- wx.FindWindowById(wx.ID_FORWARD).IsEnabled():
- wx.FindWindowById(wx.ID_FORWARD).Enable(True)
+ """!Sets the name of configuration file"""
+ self.conf_name = self.newconftxt.GetValue()
+ if self.conf_name in self.parent.parent.listfiles:
+ gcmd.GMessage(parent = self,
+ message = _("The configuration file %s already " % self.conf_name \
+ + "exists, please change name"))
+ self.newconftxt.SetValue('')
+ if self.region != '' or self.rast != '' or self.conf_name != '' and not \
+ wx.FindWindowById(wx.ID_FORWARD).IsEnabled():
+ wx.FindWindowById(wx.ID_FORWARD).Enable(True)
def OnRast(self, event):
"""!Sets raster map"""
self.rast = event.GetString()
- if self.region != '' and self.conf_name != '' and self.rast != '' and not \
+ if self.region != '' or self.conf_name != '' or self.rast != '' and not \
wx.FindWindowById(wx.ID_FORWARD).IsEnabled():
wx.FindWindowById(wx.ID_FORWARD).Enable(True)
def OnVector(self, event):
"""!Sets vector map"""
self.vect = event.GetString()
- if self.region != '' and self.conf_name != '' and self.rast != '' and not \
- wx.FindWindowById(wx.ID_FORWARD).IsEnabled():
- wx.FindWindowById(wx.ID_FORWARD).Enable(True)
+ if self.region != '' or self.conf_name != '' or self.rast != '' and not \
+ wx.FindWindowById(wx.ID_FORWARD).IsEnabled():
+ wx.FindWindowById(wx.ID_FORWARD).Enable(True)
def OnExitPage(self, event=None):
"""!Function during exiting"""
@@ -440,7 +442,7 @@
"""
def __init__(self, wizard, parent):
- TitledPage.__init__(self, wizard, _("Insert sempling frame parameter"))
+ TitledPage.__init__(self, wizard, _("Insert sampling frame parameter"))
self.parent = parent
self.sizer.AddGrowableCol(2)
@@ -551,7 +553,7 @@
"""
def __init__(self, wizard, parent):
- TitledPage.__init__(self, wizard, _("Insert sempling areas"))
+ TitledPage.__init__(self, wizard, _("Insert sampling areas"))
self.samplingtype = 'whole'
self.parent = parent
self.sizer.AddGrowableCol(2)
@@ -687,7 +689,7 @@
class SampleUnitsKeyPage(TitledPage):
"""!Set values from keyboard for sample units"""
-
+
def __init__(self, wizard, parent):
TitledPage.__init__(self, wizard, _("Units"))
@@ -699,105 +701,116 @@
self.typeBox = wx.RadioBox(parent=self, id=wx.ID_ANY,
label= _("Select type of shape"),
choices=[_('Rectangle'), _('Circle')],
- style=wx.VERTICAL)
- self.sizer.Add(self.typeBox, pos = (1, 1),
- flag = wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- choicess = [_('Random non overlapping'), _('Systematic contiguos'),
- _('Stratified random'), _('Systematic non contiguos'),
- _('Centered over sites')]
- self.distributionBox = wx.RadioBox(parent=self, id=wx.ID_ANY,
- label= _("Select method of sampling unit distribution"),
- choices = choicess, style=wx.VERTICAL)
- self.distributionBox.EnableItem(4,False)
- self.sizer.Add(self.distributionBox, pos = (1, 2),
- flag = wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- # size width
- self.sizewidth = wx.StaticText(parent = self, id = wx.ID_ANY,
- label = _('What wide size (in cells)'))
- self.sizewidthtxt = wx.TextCtrl(parent = self, id = wx.ID_ANY, size=(250, -1))
- self.sizer.Add(self.sizewidth, pos = (2, 1),
- flag = wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.sizer.Add(self.sizewidthtxt, border=5, pos=(2, 2),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- # size width
- wx.CallAfter(self.sizewidthtxt.SetFocus)
- self.sizehight = wx.StaticText(parent = self, id = wx.ID_ANY,
- label = _('What high size (in cells)'))
- self.sizehighttxt = wx.TextCtrl(parent = self, id = wx.ID_ANY, size=(250, -1))
- wx.CallAfter(self.sizewidthtxt.SetFocus)
- self.sizer.Add(self.sizehight, pos = (3, 1),
- flag = wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.sizer.Add(self.sizehighttxt, border=5, pos=(3, 2),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ majorDimension=wx.RA_SPECIFY_COLS)
- wx.FindWindowById(wx.ID_FORWARD).Enable(False)
- self.typeBox.Bind(wx.EVT_RADIOBOX, self.OnType)
- self.distributionBox.Bind(wx.EVT_RADIOBOX, self.OnMethod)
- self.sizewidthtxt.Bind(wx.EVT_KILL_FOCUS, self.OnNameW)
- self.sizehighttxt.Bind(wx.EVT_KILL_FOCUS, self.OnNameH)
+ self.sizer.Add(self.typeBox, flag = wx.ALIGN_LEFT, pos = (1, 1))
+
+ self.typeBox.Bind(wx.EVT_RADIOBOX, self.OnType)
self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
- self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnExitPage)
def OnEnterPage(self, event):
- """!Check if sites vector it is present"""
- # method of distribution
- if self.parent.startpage.vect != '':
- self.distributionBox.EnableItem(5, True)
+ try:
+ self.sizer.Hide(self.widthLabel)
+ self.sizer.Hide(self.widthTxt)
+ self.sizer.Remove(self.widthLabel)
+ self.sizer.Remove(self.widthTxt)
self.sizer.Layout()
+ except:
+ print "except width"
+ pass
+ try:
+ self.sizer.Hide(self.heightLabel)
+ self.sizer.Hide(self.heightTxt)
+ self.sizer.Remove(self.heightLabel)
+ self.sizer.Remove(self.heightTxt)
+ self.sizer.Layout()
+ except:
+ pass
+ try:
+ self.sizer.Hide(self.distributionBox)
+ self.sizer.Remove(self.distributionBox)
+ self.sizer.Layout()
+ except:
+ pass
- def OnExitPage(self, event=None):
- """!Function during exiting"""
- if self.sizew == '' or self.sizeh == '':
- wx.FindWindowById(wx.ID_FORWARD).Enable(False)
- else:
- wx.FindWindowById(wx.ID_FORWARD).Enable(True)
+ if self.parent.samplingareapage.samplingtype == 'moving':
+ self.widthLabel = wx.StaticText(parent = self, id = wx.ID_ANY,
+ label = _('Width size (in cells)?)'))
+ self.widthTxt = wx.TextCtrl(parent = self, id = wx.ID_ANY, size=(250, -1))
+ wx.CallAfter(self.widthLabel.SetFocus)
+ self.sizer.Add(item = self.widthLabel, border=5, pos=(2, 1),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.sizer.Add(item = self.widthTxt, border=5, pos=(2, 2),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.heightLabel = wx.StaticText(parent = self, id = wx.ID_ANY,
+ label = _('Height size (in cells)?)'))
+ self.heightTxt = wx.TextCtrl(parent = self, id = wx.ID_ANY, size=(250, -1))
+ wx.CallAfter(self.heightTxt.SetFocus)
+ self.sizer.Add(item = self.heightLabel, border=5, pos=(3, 1),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.sizer.Add(item = self.heightTxt, border=5, pos=(3, 2),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ elif self.parent.samplingareapage.samplingtype == 'units':
+ self.distributionBox = wx.RadioBox(parent=self, id=wx.ID_ANY,
+ label= _("Select method of sampling unit distribution"),
+ choices=[_('Random non overlapping'),
+ _('Systematic contiguos'), _('Stratified random'),
+ _('Systematic non contiguos'), _('Centered over sites')],
+ majorDimension=wx.RA_SPECIFY_COLS)
+ self.sizer.Add(item = self.distributionBox, border=5, pos=(2, 1),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+
- def OnNameW(self,event):
- """!Sets the name of configuration file"""
- self.sizew = self.sizewidthtxt.GetValue()
-
- def OnNameH(self,event):
- """!Sets the name of configuration file"""
- self.sizeh = self.sizehighttxt.GetValue()
-
def OnType(self,event):
- if event.GetInt() == 0:
- try:
- self.sizer.Hide(self.sizewidth)
- self.sizer.Remove(self.sizewidth)
- self.sizer.Hide(self.sizehight)
- self.sizer.Remove(self.sizehight)
- self.sizer.Layout()
- except:
- pass
- self.sizewidth = wx.StaticText(parent = self, id = wx.ID_ANY,
- label = _('What wide size (in cells)'))
- self.sizehight = wx.StaticText(parent = self, id = wx.ID_ANY,
- label = _('What high size (in cells)'))
- self.sizer.Add(self.sizewidth, pos = (2, 1),
- flag = wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.sizer.Add(self.sizehight, pos = (3, 1),
- flag = wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ try:
+ self.sizer.Hide(self.widthLabel)
+ self.sizer.Hide(self.widthTxt)
+ self.sizer.Hide(self.heightLabel)
+ self.sizer.Hide(self.heightTxt)
+ self.sizer.Hide(self.distributionBox)
+ self.sizer.Remove(self.widthLabel)
+ self.sizer.Remove(self.widthTxt)
+ self.sizer.Remove(self.heightLabel)
+ self.sizer.Remove(self.heightTxt)
+ self.sizer.Remove(self.distributionBox)
self.sizer.Layout()
- elif event.GetInt() == 1:
- try:
- self.sizer.Hide(self.sizewidth)
- self.sizer.Remove(self.sizewidth)
- self.sizer.Hide(self.sizehight)
- self.sizer.Remove(self.sizehight)
- self.sizer.Layout()
- except:
- pass
- self.sizewidth = wx.StaticText(parent = self, id = wx.ID_ANY,
- label = _('What radius size (in meters)'))
- self.sizehight = wx.StaticText(parent = self, id = wx.ID_ANY,
- label = _('Name for the circle mask'))
- self.sizer.Add(self.sizewidth, pos = (2, 1),
- flag = wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.sizer.Add(self.sizehight, pos = (3, 1),
- flag = wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.sizer.Layout()
-
+ except:
+ pass
+ if event.GetInt() == 0:
+ self.widthLabel = wx.StaticText(parent = self, id = wx.ID_ANY,
+ label = _('Width size (in cells)?)'))
+ self.widthTxt = wx.TextCtrl(parent = self, id = wx.ID_ANY, size=(250, -1))
+ wx.CallAfter(self.widthLabel.SetFocus)
+ self.sizer.Add(item = self.widthLabel, border=5, pos=(2, 1),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.sizer.Add(item = self.widthTxt, border=5, pos=(2, 2),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.heightLabel = wx.StaticText(parent = self, id = wx.ID_ANY,
+ label = _('Height size (in cells)?)'))
+ self.heightTxt = wx.TextCtrl(parent = self, id = wx.ID_ANY, size=(250, -1))
+ wx.CallAfter(self.heightTxt.SetFocus)
+ self.sizer.Add(item = self.heightLabel, border=5, pos=(3, 1),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.sizer.Add(item = self.heightTxt, border=5, pos=(3, 2),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ elif event.GetInt() == 1:
+ self.widthLabel = wx.StaticText(parent = self, id = wx.ID_ANY,
+ label = _('What radius size (in meters)?)'))
+ self.widthTxt = wx.TextCtrl(parent = self, id = wx.ID_ANY, size=(250, -1))
+ wx.CallAfter(self.widthLabel.SetFocus)
+ self.sizer.Add(item = self.widthLabel, border=5, pos=(2, 1),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.sizer.Add(item = self.widthTxt, border=5, pos=(2, 2),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.heightLabel = wx.StaticText(parent = self, id = wx.ID_ANY,
+ label = _('Name of the circle mask'))
+ self.heightTxt = wx.TextCtrl(parent = self, id = wx.ID_ANY, size=(250, -1))
+ wx.CallAfter(self.heightTxt.SetFocus)
+ self.sizer.Add(item = self.heightLabel, border=5, pos=(3, 1),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.sizer.Add(item = self.heightTxt, border=5, pos=(3, 2),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+
def OnMethod(self,event):
if event.GetInt() == 0:
# exit a window asking "What number of sampling units to use"
@@ -854,15 +867,16 @@
self.sizer.Add(item = self.regiontxt, border=5, pos=(4, 2),
flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
- #sampling area
- self.samplinglabel = wx.StaticText(parent = self, id = wx.ID_ANY,
- label = _('Sempling area type:'))
- self.samplingtxt = wx.StaticText(parent = self, id = wx.ID_ANY,
- label = "")
- self.sizer.Add(item = self.samplinglabel, border=5, pos=(6, 1),
- flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.sizer.Add(item = self.samplingtxt, border=5, pos=(6, 2),
+ self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
+ self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnExitPage)
+ #sampling area
+ self.samplinglabel = wx.StaticText(parent = self, id = wx.ID_ANY,
+ label = _('Sampling area type:'))
+ self.samplingtxt = wx.StaticText(parent = self, id = wx.ID_ANY,
+ label = "")
+ self.sizer.Add(item = self.samplinglabel, border=5, pos=(6, 1),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.sizer.Add(item = self.samplingtxt, border=5, pos=(6, 2),
flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
def OnEnterPage(self, event):
@@ -916,6 +930,12 @@
self.parent.keyboardpage.col_len, self.parent.keyboardpage.row_len)
self.regionkeytxt.SetLabel(regKeyVals)
+ def OnExitPage(self, event):
+ """Write the output configuration file"""
+ outputFile = open(os.path.join(self.parent.rlipath,
+ self.parent.startpage.conf_name),"w")
+ outputFile.write(self.parent.startpage.rast)
+ outputFile.close()
if __name__ == "__main__":
import gettext
More information about the grass-commit
mailing list