[GRASS-SVN] r49174 - sandbox/lucadelu
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Nov 10 11:02:43 EST 2011
Author: lucadelu
Date: 2011-11-10 08:02:43 -0800 (Thu, 10 Nov 2011)
New Revision: 49174
Modified:
sandbox/lucadelu/r.li.setup.py
Log:
improvement
Modified: sandbox/lucadelu/r.li.setup.py
===================================================================
--- sandbox/lucadelu/r.li.setup.py 2011-11-10 15:40:30 UTC (rev 49173)
+++ sandbox/lucadelu/r.li.setup.py 2011-11-10 16:02:43 UTC (rev 49174)
@@ -21,10 +21,6 @@
import sys
import os
-#global rlisettings
-#rlisettings = {'region' : 'whole', 'rast' : '', 'vect' : '',
- #'conf_name' : '', 'vectorarea' : True, }
-
sys.path.append(os.path.join(os.getenv('GISBASE'), 'etc', 'gui', 'wxpython',
'gui_modules'))
@@ -42,8 +38,6 @@
from grass.script import core as grass
from grass.script import raster as grast
-#@TODO create wizard instead of progressively increasing window
-
#@NOTE: r.li.setup writes in the settings file with
## r.li.windows.tcl:
#exec echo "SAMPLINGFRAME $per_x|$per_y|$per_rl|$per_cl" >> $env(TMP).set
@@ -166,14 +160,11 @@
self.summarypage = SummaryPage(self.wizard, self)
#order of pages
- self.startpage.SetNext(self.keyboardpage)
-
+ self.startpage.SetNext(self.samplingareapage)
self.keyboardpage.SetPrev(self.startpage)
self.keyboardpage.SetNext(self.samplingareapage)
-
self.samplingareapage.SetPrev(self.startpage)
self.samplingareapage.SetNext(self.summarypage)
-
self.summarypage.SetPrev(self.samplingareapage)
#layout
self.startpage.DoLayout()
@@ -182,7 +173,6 @@
self.summarypage.DoLayout()
self.wizard.FitToPage(self.startpage)
-
#run_wizard
self.wizard.RunWizard(self.startpage)
@@ -196,11 +186,10 @@
TitledPage.__init__(self, wizard, _("Select maps and define name"))
self.parent = parent
- self.region = ''
+ self.region = 'whole'
self.rast = ''
self.conf_name = ''
self.vect = ''
- self.vectorarea = True
self.sizer.AddGrowableCol(2)
#name of output configuration file
@@ -248,30 +237,21 @@
self.vectselect.Bind(wx.EVT_TEXT, self.OnVector)
self.mapselect.Bind(wx.EVT_TEXT, self.OnRast)
- self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnEnterPage)
- #self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
+ self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnExitPage)
wx.FindWindowById(wx.ID_FORWARD).Enable(False)
def OnSempling(self,event):
"""!Change map type"""
if event.GetInt() == 0:
- #rlisetting['region'] = 'whole'
self.region = 'whole'
self.SetNext(self.parent.samplingareapage)
elif event.GetInt() == 1:
- #rlisetting['region'] = 'key'
- #rlisetting['vectorarea'] = False
- self.vectorarea = False
self.region = 'key'
self.SetNext(self.parent.keyboardpage)
elif event.GetInt() == 2:
- #rlisetting['region'] = 'draw'
- #rlisetting['vectorarea'] = False
- self.vectorarea = False
self.region = 'draw'
wx.FindWindowById(wx.ID_FORWARD).Enable(False)
- #if rlisetting['conf_name'] != '' and rlisetting['rast'] != '' and not \
if self.conf_name != '' and self.rast != '' and not \
wx.FindWindowById(wx.ID_FORWARD).IsEnabled():
wx.FindWindowById(wx.ID_FORWARD).Enable(True)
@@ -279,8 +259,6 @@
def OnName(self,event):
"""!Sets the name of configuration file"""
self.conf_name = self.newconftxt.GetValue()
- #rlisetting['conf_name'] = self.newconftxt.GetValue()
- #if rlisetting['region'] != '' and rlisetting['rast'] != '' and not \
if self.region != '' and self.rast != '' and not \
wx.FindWindowById(wx.ID_FORWARD).IsEnabled():
wx.FindWindowById(wx.ID_FORWARD).Enable(True)
@@ -288,8 +266,6 @@
def OnRast(self, event):
"""!Sets raster map"""
self.rast = event.GetString()
- #rlisetting['rast'] = event.GetString()
- #if rlisetting['region'] != '' and rlisetting['conf_name'] != '' and not \
if self.region != '' and self.conf_name != '' and not \
wx.FindWindowById(wx.ID_FORWARD).IsEnabled():
wx.FindWindowById(wx.ID_FORWARD).Enable(True)
@@ -297,27 +273,20 @@
def OnVector(self, event):
"""!Sets vector map"""
self.vect = event.GetString()
- #rlisetting['vect'] = event.GetString()
- def OnEnterPage(self, event=None):
- #if rlisetting['region'] == '' or rlisetting['rast'] == '' or rlisetting['conf_name'] == '':
+ def OnExitPage(self, event=None):
if self.region == '' or self.conf_name == '' or self.rast == '':
wx.FindWindowById(wx.ID_FORWARD).Enable(False)
else:
wx.FindWindowById(wx.ID_FORWARD).Enable(True)
if event.GetDirection():
if self.region == 'key':
- #if rlisetting['region'] == 'key':
self.SetNext(self.parent.keyboardpage)
- #elif rlisetting['region'] == 'whole':
- #rlisetting['vectorarea'] = False
+ self.parent.samplingareapage.SetPrev(self.parent.keyboardpage)
elif self.region == 'whole':
- self.vectorarea = False
self.SetNext(self.parent.samplingareapage)
+ self.parent.samplingareapage.SetPrev(self)
elif self.region == 'draw':
- #elif rlisetting['region'] == 'draw':
- #rlisetting['vectorarea'] = False
- self.vectorarea = False
gcmd.GMessage(parent = self,
message = _("Function not supported yet"))
event.Veto()
@@ -334,10 +303,6 @@
self.parent = parent
self.sizer.AddGrowableCol(2)
-
- #print rlisetting['rast']
- self.col_up = ''
- self.row_up = ''
self.col_len = ''
self.row_len = ''
@@ -393,42 +358,55 @@
self.RowUpLefttxt.Bind(wx.EVT_KILL_FOCUS, self.OnRowLeft)
self.ColLentxt.Bind(wx.EVT_KILL_FOCUS, self.OnColLen)
self.RowLentxt.Bind(wx.EVT_KILL_FOCUS, self.OnRowLeft)
- self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnEnterPage)
+ self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
- def OnEnterPage(self, event):
- """!Insert values into text controls for summary of location
- creation options
- """
- rastinfo = grast.raster_info(self.parent.startpage.rast)
- print rastinfo
-
def OnColLeft(self,event):
"""!Sets the name of configuration file"""
self.col_up = self.ColUpLefttxt.GetValue()
- if self.row_up != '' and self.col_len != '' and self.row_len != '' \
- and not wx.FindWindowById(wx.ID_FORWARD).IsEnabled():
- wx.FindWindowById(wx.ID_FORWARD).Enable(True)
+ 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()
- if self.col_up != '' and self.col_len != '' and self.row_len != '' \
- and not wx.FindWindowById(wx.ID_FORWARD).IsEnabled():
- wx.FindWindowById(wx.ID_FORWARD).Enable(True)
-
+ 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()
- if self.row_up != '' and self.col_up != '' and self.row_len != '' \
- and not wx.FindWindowById(wx.ID_FORWARD).IsEnabled():
- wx.FindWindowById(wx.ID_FORWARD).Enable(True)
-
+ 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()
- if self.row_up != '' and self.col_len != '' and self.col_up != '' \
- and not wx.FindWindowById(wx.ID_FORWARD).IsEnabled():
+ 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
+ """
+ self.col_up = '0'
+ self.row_up = '0'
+ if self.col_len == '' and self.row_len == '':
+ rastinfo = grast.raster_info(self.parent.startpage.rast)
+ self.col_len = rastinfo['cols']
+ self.row_len = rastinfo['rows']
+
+ self.ColUpLefttxt.SetValue(self.col_up)
+ self.RowUpLefttxt.SetValue(self.row_up)
+ self.ColLentxt.SetValue(self.col_len)
+ self.RowLentxt.SetValue(self.row_len)
+
class SamplingAreasPage(TitledPage):
"""
@@ -437,7 +415,7 @@
def __init__(self, wizard, parent):
TitledPage.__init__(self, wizard, _("Insert sempling areas"))
-
+ self.samplingtype = 'whole'
self.parent = parent
self.sizer.AddGrowableCol(2)
# toggles
@@ -458,8 +436,7 @@
self.sizer.Add(item = self.radio2, flag = wx.ALIGN_LEFT, pos = (2, 1))
self.sizer.Add(item = self.radio3, flag = wx.ALIGN_LEFT, pos = (3, 1))
self.sizer.Add(item = self.radio4, flag = wx.ALIGN_LEFT, pos = (4, 1))
-
-
+
wx.FindWindowById(wx.ID_FORWARD).Enable(False)
# bindings
@@ -473,8 +450,13 @@
"""!Insert values into text controls for summary of location
creation options
"""
- print "vector area is %s" % self.parent.startpage.vectorarea
- if self.parent.startpage.vectorarea:
+ try:
+ self.sizer.Hide(self.radio5)
+ self.sizer.Remove(self.radio5)
+ self.sizer.Layout()
+ except AttributeError:
+ pass
+ if self.parent.startpage.vect != '':
self.radio5 = wx.RadioButton(parent = self, id = wx.ID_ANY,
label = _("Select areas from the "
"overlayed vector map"))
@@ -484,14 +466,19 @@
def SetVal(self, event):
"""!Choose method"""
if event.GetId() == self.radio1.GetId():
+ self.samplingtype = 'whole'
self.DrawNothing()
elif event.GetId() == self.radio2.GetId():
+ self.samplingtype = 'regions'
self.Region()
elif event.GetId() == self.radio3.GetId():
+ self.samplingtype = 'units'
self.KeyDraw()
elif event.GetId() == self.radio4.GetId():
+ self.samplingtype = 'moving'
self.KeyDraw()
elif event.GetId() == self.radio5.GetId():
+ self.samplingtype = 'vector'
self.DrawNothing()
def Region(self):
@@ -526,7 +513,20 @@
majorDimension=wx.RA_SPECIFY_COLS)
self.sizer.Add(self.regionBox, flag = wx.ALIGN_CENTER, pos = (6, 1))
self.sizer.Layout()
+ wx.FindWindowById(wx.ID_FORWARD).Enable(False)
+ self.regionBox.Bind(wx.EVT_RADIOBOX, self.OnRegionDraw)
+ def OnRegionDraw(self):
+ if event.GetInt() == 0:
+ self.region = 'whole'
+ self.SetNext(self.parent.samplingareapage)
+ elif event.GetInt() == 1:
+ self.region = 'key'
+ self.SetNext(self.parent.keyboardpage)
+ if self.conf_name != '' and self.rast != '' and not \
+ wx.FindWindowById(wx.ID_FORWARD).IsEnabled():
+ wx.FindWindowById(wx.ID_FORWARD).Enable(True)
+
def DrawNothing(self):
try:
self.sizer.Hide(self.regionBox)
@@ -534,9 +534,7 @@
self.sizer.Layout()
except AttributeError:
pass
- self.regionBox = wx.StaticText(parent = self, id = wx.ID_ANY,label = _(''))
- self.sizer.Add(self.regionBox, flag = wx.ALIGN_CENTER, pos = (6, 1))
- self.sizer.Layout()
+ wx.FindWindowById(wx.ID_FORWARD).Enable(True)
class SampleUnitsKeyPage(TitledPage):
"""!Set values from keyboard for sample units"""
@@ -553,7 +551,8 @@
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')],
+ _('Systematic contiguos'), _('Stratified random'),
+ _('Systematic non contiguos'), _('Centered over sites')],
majorDimension=wx.RA_SPECIFY_COLS)
self.sizer.Add(self.typeBox, flag = wx.ALIGN_LEFT, pos = (1, 1))
self.sizer.Add(self.distributionBox, flag = wx.ALIGN_LEFT, pos = (2, 1))
@@ -588,54 +587,84 @@
self.parent = parent
self.sizer.AddGrowableCol(2)
-
- #column up/left
+
+ #configuration file name
+ self.conflabel = wx.StaticText(parent = self, id = wx.ID_ANY,
+ label = _('Configuration file name:'))
+ self.conftxt = wx.StaticText(parent = self, id = wx.ID_ANY,
+ label = "")
+ self.sizer.Add(item = self.conflabel, border=5, pos=(1, 1),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.sizer.Add(item = self.conftxt, border=5, pos=(1, 2),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+
+ #raster name
self.rastlabel = wx.StaticText(parent = self, id = wx.ID_ANY,
label = _('Raster name:'))
-
self.rasttxt = wx.StaticText(parent = self, id = wx.ID_ANY,
label = "")
-
- self.sizer.Add(item = self.rastlabel, border=5, pos=(1, 1),
+ self.sizer.Add(item = self.rastlabel, border=5, pos=(2, 1),
flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.sizer.Add(item = self.rasttxt, border=5, pos=(1, 2),
+ self.sizer.Add(item = self.rasttxt, border=5, pos=(2, 2),
flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
-
- #row up/left
- self.conflabel = wx.StaticText(parent = self, id = wx.ID_ANY,
- label = _('Configuration file name:'))
- self.conftxt = wx.StaticText(parent = self, id = wx.ID_ANY,
+ #vector name
+ self.vectlabel = wx.StaticText(parent = self, id = wx.ID_ANY,
+ label = _('Vector name:'))
+ self.vecttxt = wx.StaticText(parent = self, id = wx.ID_ANY,
label = "")
-
- self.sizer.Add(item = self.conflabel, border=5, pos=(2, 1),
+ self.sizer.Add(item = self.vectlabel, border=5, pos=(3, 1),
flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.sizer.Add(item = self.conftxt, border=5, pos=(2, 2),
+ self.sizer.Add(item = self.vecttxt, border=5, pos=(3, 2),
flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- #row up/left
+ #region type name
self.regionlabel = wx.StaticText(parent = self, id = wx.ID_ANY,
- label = _('Region name:'))
-
+ label = _('Region type:'))
self.regiontxt = wx.StaticText(parent = self, id = wx.ID_ANY,
label = "")
-
- self.sizer.Add(item = self.regionlabel, border=5, pos=(3, 1),
+ self.sizer.Add(item = self.regionlabel, border=5, pos=(4, 1),
flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
- self.sizer.Add(item = self.regiontxt, border=5, pos=(3, 2),
+ 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),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
def OnEnterPage(self, event):
"""!Insert values into text controls for summary of location
creation options
"""
-
self.conftxt.SetLabel(self.parent.startpage.conf_name)
self.rasttxt.SetLabel(self.parent.startpage.rast)
+ self.vecttxt.SetLabel(self.parent.startpage.vect)
self.regiontxt.SetLabel(self.parent.startpage.region)
-
+ if self.parent.startpage.region == 'key':
+ #region keybord values
+ self.regionkeylabel = wx.StaticText(parent = self, id = wx.ID_ANY,
+ label = _('Region keybord values:'))
+
+ self.regionkeytxt = wx.StaticText(parent = self, id = wx.ID_ANY,
+ label = "")
+ self.sizer.Add(item = self.regionkeylabel, border=5, pos=(5, 1),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.sizer.Add(item = self.regionkeytxt, border=5, pos=(5, 2),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ regKeyVals = "Column left up: %s - Row left up: %s\nColumn length: %s - Row length: %s\n" \
+ % (self.parent.keyboardpage.col_up, self.parent.keyboardpage.row_up,
+ self.parent.keyboardpage.col_len, self.parent.keyboardpage.row_len)
+ self.regionkeytxt.SetLabel(regKeyVals)
+ self.samplingtxt.SetLabel(self.parent.samplingareapage.samplingtype)
+
if __name__ == "__main__":
import gettext
gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode = True)
More information about the grass-commit
mailing list