[GRASS-SVN] r54045 - in grass/trunk/gui/wxpython: . rlisetup scripts
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Nov 26 03:31:41 PST 2012
Author: lucadelu
Date: 2012-11-26 03:31:41 -0800 (Mon, 26 Nov 2012)
New Revision: 54045
Added:
grass/trunk/gui/wxpython/rlisetup/
grass/trunk/gui/wxpython/rlisetup/Makefile
grass/trunk/gui/wxpython/rlisetup/frame.py
grass/trunk/gui/wxpython/rlisetup/functions.py
grass/trunk/gui/wxpython/rlisetup/g.gui.rlisetup.html
grass/trunk/gui/wxpython/rlisetup/g.gui.rlisetup.py
grass/trunk/gui/wxpython/rlisetup/wizard.py
Removed:
grass/trunk/gui/wxpython/scripts/r.li.setup.py
Modified:
grass/trunk/gui/wxpython/Makefile
Log:
add first version of rlisetup for wxpython
Modified: grass/trunk/gui/wxpython/Makefile
===================================================================
--- grass/trunk/gui/wxpython/Makefile 2012-11-26 09:50:59 UTC (rev 54044)
+++ grass/trunk/gui/wxpython/Makefile 2012-11-26 11:31:41 UTC (rev 54045)
@@ -1,6 +1,6 @@
MODULE_TOPDIR = ../..
-SUBDIRS = docs mapswipe gmodeler
+SUBDIRS = docs mapswipe gmodeler rlisetup
EXTRA_CLEAN_FILES = menustrings.py build_ext.pyc
include $(MODULE_TOPDIR)/include/Make/Dir.make
@@ -11,12 +11,12 @@
SRCFILES := $(wildcard icons/*.* scripts/* xml/*) \
$(wildcard core/* dbmgr/* gcp/* gmodeler/* gui_core/* iclass/* lmgr/* location_wizard/* \
- mapdisp/* modules/* nviz/* psmap/* mapswipe/* vdigit/* wxplot/* ogc_services/*) \
+ mapdisp/* modules/* nviz/* psmap/* mapswipe/* vdigit/* wxplot/* ogc_services/* rlisetup/*) \
gis_set.py gis_set_error.py wxgui.py README
DSTFILES := $(patsubst %,$(ETCDIR)/%,$(SRCFILES)) $(patsubst %.py,$(ETCDIR)/%.pyc,$(filter %.py,$(SRCFILES)))
PYDSTDIRS := $(patsubst %,$(ETCDIR)/%,core dbmgr gcp gmodeler gui_core iclass lmgr location_wizard \
- mapdisp modules nviz psmap mapswipe vdigit wxplot ogc_services)
+ mapdisp modules nviz psmap mapswipe vdigit wxplot ogc_services rlisetup)
DSTDIRS := $(patsubst %,$(ETCDIR)/%,icons scripts xml)
default: $(DSTFILES)
Added: grass/trunk/gui/wxpython/rlisetup/Makefile
===================================================================
--- grass/trunk/gui/wxpython/rlisetup/Makefile (rev 0)
+++ grass/trunk/gui/wxpython/rlisetup/Makefile 2012-11-26 11:31:41 UTC (rev 54045)
@@ -0,0 +1,13 @@
+MODULE_TOPDIR = ../../..
+
+PGM = g.gui.rlisetup
+WXPGM = RLiSetup
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script
+ -rm -f $(PGM).tmp.html
+ $(MAKE) $(HTMLDIR)/wxGUI.$(WXPGM).html
+
+$(HTMLDIR)/wxGUI.$(WXPGM).html: $(PGM).html | $(HTMLDIR)
+ $(PYTHON) $(GISBASE)/tools/mkhtml.py $(PGM) $(GRASS_VERSION_DATE) > $@
\ No newline at end of file
Added: grass/trunk/gui/wxpython/rlisetup/frame.py
===================================================================
--- grass/trunk/gui/wxpython/rlisetup/frame.py (rev 0)
+++ grass/trunk/gui/wxpython/rlisetup/frame.py 2012-11-26 11:31:41 UTC (rev 54045)
@@ -0,0 +1,146 @@
+# -*- coding: utf-8 -*-
+"""
+Created on Mon Nov 26 11:57:54 2012
+
+ at author: lucadelu
+"""
+
+import wx
+import os
+
+from core import globalvar, gcmd
+from grass.script import core as grass
+from rlisetup.functions import retRLiPath
+from rlisetup.wizard import RLIWizard
+
+
+class RLiSetupFrame(wx.Frame):
+
+ def __init__(self, parent, giface = None, id=wx.ID_ANY, title=_("GRASS" \
+ " GIS Setup for r.li modules"),
+ style=wx.DEFAULT_FRAME_STYLE | wx.RESIZE_BORDER, **kwargs):
+ ###VARIABLES
+ self.parent = parent
+ self.cmd = "r.li.setup"
+ self.rlipath = retRLiPath()
+ self.listfiles = self.ListFiles()
+ ###END VARIABLES
+ #init of frame
+ wx.Frame.__init__(self, parent=parent, id=id, title=title,
+ **kwargs)
+ self.SetIcon(wx.Icon(os.path.join(globalvar.ETCICONDIR, 'grass.ico'),
+ wx.BITMAP_TYPE_ICO))
+ self.panel = wx.Panel(parent=self, id=wx.ID_ANY)
+ #box for select configuration file
+ self.confilesBox = wx.StaticBox(parent=self.panel, id=wx.ID_ANY,
+ label=_('Available sampling area configuration files'))
+ self.listfileBox = wx.ListBox(parent=self.panel, id=wx.ID_ANY,
+ choices=self.listfiles)
+ ###BUTTONS
+ #definition
+ self.btn_close = wx.Button(parent=self.panel, id=wx.ID_CLOSE)
+ self.btn_help = wx.Button(parent=self.panel, id=wx.ID_HELP)
+ 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_rename = wx.Button(parent=self.panel, id=wx.ID_ANY,
+ label=_("Rename"))
+ self.btn_rename.SetToolTipString(_('Rename 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_rename.Bind(wx.EVT_BUTTON, self.OnRename)
+ self._layout()
+ ###END BUTTONS
+
+ ###SIZE FRAME
+ self.SetMinSize(self.GetBestSize())
+ ##Please check this because without this the size it is not the min
+ self.SetClientSize(self.GetBestSize())
+ ###END SIZE
+
+ def _layout(self):
+ """Set the layout"""
+ sizer = wx.BoxSizer(wx.VERTICAL)
+ ###CONFILES
+ confilesSizer = wx.StaticBoxSizer(self.confilesBox, wx.HORIZONTAL)
+ confilesSizer.Add(item=self.listfileBox, proportion=1,
+ flag=wx.EXPAND)
+ ###END CONFILES
+ ###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)
+ ###END BUTTONS
+ #add to sizer
+ sizer.Add(item=confilesSizer, proportion=0,
+ flag=wx.ALIGN_LEFT | wx.EXPAND | wx.ALL, border=3)
+ sizer.Add(item=buttonSizer, proportion=0,
+ flag=wx.ALIGN_RIGHT | wx.ALL, border=3)
+ #set dimension
+ self.panel.SetAutoLayout(True)
+ self.panel.SetSizer(sizer)
+ sizer.Fit(self.panel)
+ self.Layout()
+
+ def ListFiles(self):
+ """!Check the configuration files inside the path"""
+ # 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"""
+ self.Destroy()
+
+ def OnHelp(self, event):
+ """!Launches r.mapcalc help"""
+ gcmd.RunCommand('g.manual', parent=self, entry=self.cmd)
+
+ def OnRemove(self, event):
+ """!Remove configuration file from path and update the list"""
+ confile = self.listfiles[self.listfileBox.GetSelections()[0]]
+ self.listfileBox.Delete(self.listfileBox.GetSelections()[0])
+ grass.try_remove(os.path.join(self.rlipath, confile))
+ self.listfiles = self.ListFiles()
+ return
+
+ 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()
+ newname = "%s%s%s" % (self.rlipath, os.sep, res)
+ os.rename(os.path.join(self.rlipath, confile), newname)
+ self.listfiles = self.ListFiles()
+ self.listfileBox.Clear()
+ self.listfileBox.Set(self.listfiles)
\ No newline at end of file
Added: grass/trunk/gui/wxpython/rlisetup/functions.py
===================================================================
--- grass/trunk/gui/wxpython/rlisetup/functions.py (rev 0)
+++ grass/trunk/gui/wxpython/rlisetup/functions.py 2012-11-26 11:31:41 UTC (rev 54045)
@@ -0,0 +1,27 @@
+# -*- coding: utf-8 -*-
+"""
+Created on Mon Nov 26 11:48:03 2012
+
+ at author: lucadelu
+"""
+import wx
+import os
+from grass.script import core as grass
+
+
+def checkValue(value):
+ if value == '':
+ wx.FindWindowById(wx.ID_FORWARD).Enable(False)
+ 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
\ No newline at end of file
Added: grass/trunk/gui/wxpython/rlisetup/g.gui.rlisetup.html
===================================================================
--- grass/trunk/gui/wxpython/rlisetup/g.gui.rlisetup.html (rev 0)
+++ grass/trunk/gui/wxpython/rlisetup/g.gui.rlisetup.html 2012-11-26 11:31:41 UTC (rev 54045)
@@ -0,0 +1,22 @@
+<!-- meta page description: wxGUI Map Swipe -->
+<!-- meta page index: wxGUI -->
+<h2>DESCRIPTION</h2>
+
+The <b>RLi Setup</b> is a <em><a href="wxGUI.html">wxGUI</a></em> component
+which allows the user to create a configuration file for r.li modules.
+
+
+<h2>SEE ALSO</h2>
+
+<em>
+ <a href="wxGUI.html">wxGUI</a><br>
+ <a href="wxGUI.Components.html">wxGUI components</a>
+</em>
+
+<p>
+See also the user <a href="http://grass.osgeo.org/wiki/WxGUI_Map_Swipe">wiki</a> page.
+
+<h2>AUTHOR</h2>
+
+Converted to Python by Luca Delucchi,
+<i>$Date: 2012-03-07 13:21:57 +0100 (Wed, 07 Mar 2012) $</i>
Added: grass/trunk/gui/wxpython/rlisetup/g.gui.rlisetup.py
===================================================================
--- grass/trunk/gui/wxpython/rlisetup/g.gui.rlisetup.py (rev 0)
+++ grass/trunk/gui/wxpython/rlisetup/g.gui.rlisetup.py 2012-11-26 11:31:41 UTC (rev 54045)
@@ -0,0 +1,56 @@
+#!/usr/bin/env python
+############################################################################
+#
+# MODULE: RLi Setup
+# AUTHOR(S): Luca Delucchi <lucadeluge gmail.com>
+# PURPOSE: RLi Setup to create configuration file for r.li modules
+# COPYRIGHT: (C) 2012 by Luca, Delucchi, and the GRASS Development Team
+#
+# This program is free software; you can 1redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+############################################################################
+
+#%module
+#% description: Allows to interactively create, edit and manage models.
+#% keywords: general
+#% keywords: gui
+#% keywords: graphical modeler
+#% keywords: workflow
+#%end
+
+import os
+import sys
+
+import wx
+import gettext
+
+import grass.script as grass
+
+sys.path.append(os.path.join(os.environ['GISBASE'], "etc", "gui", "wxpython"))
+
+from core.giface import StandaloneGrassInterface
+from rlisetup.frame import RLiSetupFrame
+
+
+def main():
+ import gettext
+ gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode = True)
+
+ app = wx.PySimpleApp()
+ wx.InitAllImageHandlers()
+ frame = RLiSetupFrame(parent = None, giface = StandaloneGrassInterface())
+ frame.Show()
+
+ app.MainLoop()
+
+if __name__ == "__main__":
+ options, flags = grass.parser()
+ main()
Added: grass/trunk/gui/wxpython/rlisetup/wizard.py
===================================================================
--- grass/trunk/gui/wxpython/rlisetup/wizard.py (rev 0)
+++ grass/trunk/gui/wxpython/rlisetup/wizard.py 2012-11-26 11:31:41 UTC (rev 54045)
@@ -0,0 +1,1016 @@
+"""
+ at package rlisetup.py
+
+ at brief GUI per r.li.setup module
+
+Classes:
+ - RLiSetupFrame (first frame to show existing conf file and choose some
+ operation)
+ - RLIWizard (the main wizard)
+ - FirstPage (first page of wizard, choose name of conf file, raster, vector,
+ 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
+(>=v2). Read the file COPYING that comes with GRASS for details.
+
+ at author Luca Delucchi <lucadeluge gmail com>
+"""
+
+import sys
+import os
+
+sys.path.append(os.path.join(os.getenv('GISBASE'), 'etc', 'gui', 'wxpython'))
+
+import wx
+import wx.wizard as wiz
+import wx.lib.scrolledpanel as scrolled
+
+from gui_core import gselect
+from core import gcmd
+from location_wizard.wizard import TitledPage as TitledPage
+from rlisetup.functions import checkValue, retRLiPath
+from grass.script import core as grass
+from grass.script import raster as grast
+
+
+#@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
+
+
+class RLIWizard(object):
+ """
+ Start wizard here and finish wizard here
+ """
+
+ def __init__(self, parent):
+ self.parent = parent
+ self.wizard = wiz.Wizard(parent=parent, id=wx.ID_ANY,
+ title=_("Create new configuration file for " \
+ "r.li modules"))
+ self.rlipath = retRLiPath()
+ #pages
+ self.startpage = FirstPage(self.wizard, self)
+ self.keyboardpage = KeybordPage(self.wizard, self)
+ self.samplingareapage = SamplingAreasPage(self.wizard, self)
+ self.summarypage = SummaryPage(self.wizard, self)
+ self.units = SampleUnitsKeyPage(self.wizard, self)
+ self.moving = MovingWindows(self.wizard, self)
+
+ #order of pages
+ 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.units.SetPrev(self.samplingareapage)
+ self.units.SetNext(self.summarypage)
+ self.moving.SetPrev(self.samplingareapage)
+ self.moving.SetNext(self.summarypage)
+ self.summarypage.SetPrev(self.samplingareapage)
+
+ #layout
+ self.startpage.DoLayout()
+ self.keyboardpage.DoLayout()
+ self.samplingareapage.DoLayout()
+ self.summarypage.DoLayout()
+ self.units.DoLayout()
+ self.moving.DoLayout()
+
+ self.wizard.FitToPage(self.startpage)
+ #run_wizard
+ if self.wizard.RunWizard(self.startpage):
+ dlg = wx.MessageDialog(parent=self.parent,
+ message=_("Do you want to create r.li " \
+ "configuration file <%s>?") % self.startpage.conf_name,
+ caption=_("Create new r.li configuration file?"),
+ style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
+
+ if dlg.ShowModal() == wx.ID_NO:
+ self._cleanup()
+ dlg.Destroy()
+ else:
+ self._write_confile()
+ self._cleanup()
+ dlg.Destroy()
+ else:
+ self.wizard.Destroy()
+ gcmd.GMessage(parent=self.parent,
+ message=_("r.li.setup wizard canceled. "
+ "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.rasterinfo = grast.raster_info(self.startpage.rast)
+ 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()
+ self.SF_NSRES = self.gregion['nsres']
+ self.SF_EWRES = self.gregion['ewres']
+
+ def _write_region(self, fil):
+ """Write the region"""
+ 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'])))
+ self.SF_N = self.gregion['n']
+ self.SF_S = self.gregion['s']
+ self.SF_E = self.gregion['e']
+ self.SF_W = self.gregion['w']
+ self.per_x = float(self.SF_X) / float(self.rasterinfo['cols'])
+ self.per_y = float(self.SF_Y) / float(self.rasterinfo['rows'])
+ self.per_rl = float(self.SF_RL) / float(self.rasterinfo['rows'])
+ self.per_cl = float(self.SF_CL) / float(self.rasterinfo['cols'])
+ elif self.startpage.region == 'key':
+ self._temp_region()
+ self.SF_X = float(self.keyboardpage.col_up)
+ self.SF_Y = float(self.keyboardpage.row_up)
+ self.SF_RL = float(self.keyboardpage.row_len)
+ self.SF_CL = float(self.keyboardpage.col_len)
+ self.SF_N = self.gregion['n'] - (self.SF_NSRES * self.SF_Y)
+ self.SF_S = self.gregion['n'] - (self.SF_NSRES * self.SF_Y + self.SF_RL)
+ self.SF_W = self.gregion['w'] + (self.SF_EWRES * self.SF_X)
+ self.SF_E = self.gregion['w'] + (self.SF_EWRES * self.SF_X + self.SF_CL)
+ self.per_x = float(self.SF_X) / float(self.rasterinfo['cols'])
+ self.per_y = float(self.SF_Y) / float(self.rasterinfo['rows'])
+ self.per_rl = float(self.SF_RL) / float(self.rasterinfo['rows'])
+ self.per_cl = float(self.SF_CL) / float(self.rasterinfo['cols'])
+ #import pdb; pdb.set_trace()
+ fil.write("SAMPLINGFRAME %r|%r|%r|%r\n" % (self.per_x, self.per_y,
+ self.per_rl, self.per_cl))
+
+ def _circle(self, radius, mask):
+ """create a circle mask"""
+ self.CIR_RL = round((2 * float(radius)) / float(self.rasterinfo['ewres']))
+ self.CIR_CL = round((2 * float(radius)) / float(self.rasterinfo['nsres']))
+ if not self.CIR_RL % 2:
+ self.CIR_RL += 1
+ if not self.CIR_CL % 2:
+ self.CIR_CL += 1
+ eastEdge = float(self.SF_W + (self.CIR_RL * self.SF_EWRES))
+ southEdge = float(self.SF_N - (self.CIR_CL * self.SF_NSRES))
+ grass.del_temp_region()
+ grass.use_temp_region()
+ grass.run_command('g.region', n=self.SF_N, s=southEdge, e=eastEdge,
+ w=self.SF_W)
+ xcenter = grass.region(complete=True)['center_easting']
+ ycenter = grass.region(complete=True)['center_northing']
+ grass.run_command('r.circle', flags='b', out=mask, max=radius,
+ coordinate=[xcenter, ycenter], quiet=True)
+ grass.del_temp_region()
+ grass.use_temp_region()
+ grass.run_command('g.region', rast=self.startpage.rast)
+
+ def _write_area(self, fil):
+ """Write the region"""
+ if self.samplingareapage.samplingtype == 'whole':
+ cl = float(self.SF_CL) / float(self.rasterinfo['cols'])
+ rl = float(self.SF_RL) / float(self.rasterinfo['rows'])
+ #this two variable are unused, problably to remove
+ x = float(self.SF_X) / float(self.rasterinfo['cols'])
+ y = float(self.SF_Y) / float(self.rasterinfo['rows'])
+ if self.startpage.region == 'whole':
+ fil.write("SAMPLEAREA %r|%r|%r|%r\n" % (self.per_x, self.per_y,
+ rl, cl))
+ elif self.startpage.region == 'key':
+ fil.write("SAMPLEAREA %r|%r|%r|%r\n" % (self.per_x, self.per_y,
+ rl, cl))
+ elif self.samplingareapage.samplingtype == 'moving':
+ if self.moving.boxtype == 'circle':
+ self._circle(self.moving.width, self.moving.height)
+ cl = float(self.CIR_CL) / float(self.rasterinfo['cols'])
+ rl = float(self.CIR_RL) / float(self.rasterinfo['rows'])
+ else:
+ cl = float(self.moving.width) / float(self.rasterinfo['cols'])
+ rl = float(self.moving.height) / float(self.rasterinfo['rows'])
+ fil.write("SAMPLEAREA -1|-1|%r|%r" % (rl, cl))
+ if self.moving.boxtype == 'circle':
+ fil.write("|%s" % self.moving.height)
+ fil.write("\nMOVINGWINDOW\n")
+ elif self.samplingareapage.samplingtype == 'units':
+ if self.units.boxtype == 'circle':
+ self._circle(self.units.width, self.units.height)
+ cl = float(self.CIR_CL) / float(self.rasterinfo['cols'])
+ rl = float(self.CIR_RL) / float(self.rasterinfo['rows'])
+ else:
+ cl = float(self.units.width) / float(self.rasterinfo['cols'])
+ rl = float(self.units.height) / float(self.rasterinfo['rows'])
+ fil.write("SAMPLEAREA -1|-1|%r|%r\n" % (rl, cl))
+ if self.units.distrtype == 'non_overlapping':
+ fil.write("RANDOMNONOVERLAPPING %s\n" % self.units.distr1)
+ elif self.units.distrtype == 'systematic_contiguos':
+ fil.write("SYSTEMATICCONTIGUOUS\n")
+ elif self.units.distrtype == 'stratified_random':
+ fil.write("STRATIFIEDRANDOM %s|%s\n" % (self.units.distr1,
+ self.units.distr2))
+ elif self.units.distrtype == 'systematic_noncontiguos':
+ fil.write("SYSTEMATICNONCONTIGUOUS %s\n" % self.units.distr1)
+ elif self.units.distrtype == 'centered_oversites':
+ fil.write("")
+
+ 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.col_up = ''
+ self.keyboardpage.row_len = ''
+ self.keyboardpage.row_up = ''
+ self.samplingareapage.samplingtype = 'whole'
+ self.units.width = ''
+ self.units.height = ''
+ self.units.boxtype = ''
+ self.moving.width = ''
+ self.moving.height = ''
+ self.moving.boxtype = ''
+
+
+class FirstPage(TitledPage):
+ """
+ Set name of configuration file, choose raster and optionally vector/sites
+ """
+
+ def __init__(self, wizard, parent):
+ TitledPage.__init__(self, wizard, _("Select maps and define name"))
+
+ self.region = 'whole'
+ self.rast = ''
+ self.conf_name = ''
+ self.vect = ''
+
+ self.parent = parent
+
+ #name of output configuration file
+ self.newconflabel = wx.StaticText(parent=self, id=wx.ID_ANY,
+ label=_('Name for new configuration file to create'))
+
+ self.newconftxt = wx.TextCtrl(parent=self, id=wx.ID_ANY,
+ size=(250, -1))
+ wx.CallAfter(self.newconftxt.SetFocus)
+
+ self.sizer.Add(item=self.newconflabel, border=5, pos=(0, 0),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.sizer.Add(item=self.newconftxt, border=5, pos=(0, 1),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ #raster
+ self.mapsellabel = wx.StaticText(parent=self, id=wx.ID_ANY,
+ label=_('Raster map to use to select areas'))
+ self.mapselect = gselect.Select(parent=self, id=wx.ID_ANY,
+ size=(250, -1), type='cell',
+ multiple=False)
+ self.sizer.Add(item=self.mapsellabel, border=5, pos=(1, 0),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.sizer.Add(item=self.mapselect, border=5, pos=(1, 1),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ #vector
+ self.vectsellabel = wx.StaticText(parent=self, id=wx.ID_ANY,
+ label=_('Vector map to use to select areas'))
+ self.vectselect = gselect.Select(parent=self, id=wx.ID_ANY,
+ size=(250, -1), type='vector',
+ multiple=False)
+ self.vectsellabel.Enable(False)
+ self.vectselect.Enable(False)
+ self.sizer.Add(item=self.vectsellabel, border=5, pos=(2, 0),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.sizer.Add(item=self.vectselect, border=5, pos=(2, 1),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ #define sampling region
+ self.sampling_reg = wx.RadioBox(parent=self, id=wx.ID_ANY,
+ label=" %s " % _("Define sampling " \
+ " region(region for analysis)"),
+ choices=[_('Whole map layer'),
+ _('Keyboard setting'),
+ _('Draw the sampling frame')],
+ majorDimension=1,
+ style=wx.RA_SPECIFY_ROWS)
+
+ self.sampling_reg.EnableItem(2, False) # disable 'draw' for now
+ self.sampling_reg.SetItemToolTip(2, _("This option is not supported yet"))
+ self.sizer.Add(item=self.sampling_reg,
+ flag=wx.ALIGN_CENTER | wx.ALL | wx.EXPAND, border=5,
+ pos=(4, 0), span=(1, 2))
+ #bindings
+ 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)
+ #self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
+ self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnExitPage)
+
+ wx.CallAfter(wx.FindWindowById(wx.ID_FORWARD).Enable, False)
+ # wx.FindWindowById(wx.ID_FORWARD).Enable(False)
+ # self.OnName(None)
+
+ def OnSampling(self, event):
+ """!Change map type"""
+ if event.GetInt() == 0:
+ self.region = 'whole'
+ self.SetNext(self.parent.samplingareapage)
+ elif event.GetInt() == 1:
+ self.region = 'key'
+ self.SetNext(self.parent.keyboardpage)
+ elif event.GetInt() == 2: # currently disabled
+ self.region = 'draw'
+
+ def OnName(self, event):
+ """!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 exists, please change name") % self.conf_name)
+ self.newconftxt.SetValue('')
+ self.conf_name = ''
+ next = wx.FindWindowById(wx.ID_FORWARD)
+ next.Enable(self.CheckInput())
+
+ def OnRast(self, event):
+ """!Sets raster map"""
+ self.rast = event.GetString()
+ next = wx.FindWindowById(wx.ID_FORWARD)
+ next.Enable(self.CheckInput())
+
+ def OnVector(self, event):
+ """!Sets vector map"""
+ self.vect = event.GetString()
+ next = wx.FindWindowById(wx.ID_FORWARD)
+ next.Enable(self.CheckInput())
+
+ def CheckInput(self):
+ """!Check input fields.
+
+ @return True if configuration file is given and raster xor vector map,
+ False otherwise
+ """
+ return bool(self.conf_name and (bool(self.rast) != bool(self.vect)))
+
+ def OnExitPage(self, event=None):
+ """!Function during exiting"""
+ if self.region == 'draw' 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':
+ self.SetNext(self.parent.keyboardpage)
+ self.parent.samplingareapage.SetPrev(self.parent.keyboardpage)
+ elif self.region == 'whole':
+ self.SetNext(self.parent.samplingareapage)
+ self.parent.samplingareapage.SetPrev(self)
+ elif self.region == 'draw':
+ gcmd.GMessage(parent=self,
+ message=_("Function not supported yet"))
+ event.Veto()
+ return
+
+
+class KeybordPage(TitledPage):
+ """
+ Set name of configuration file, choose raster and optionally vector/sites
+ """
+
+ def __init__(self, wizard, parent):
+ TitledPage.__init__(self, wizard, _("Insert sampling frame parameter"))
+
+ self.parent = parent
+ self.sizer.AddGrowableCol(2)
+ self.col_len = ''
+ self.row_len = ''
+ self.col_up = '0'
+ self.row_up = '0'
+
+ #column up/left
+ self.ColUpLeftlabel = wx.StaticText(parent=self, id=wx.ID_ANY,
+ label=_("Column of upper left " \
+ "corner"))
+
+ self.ColUpLefttxt = wx.TextCtrl(parent=self, id=wx.ID_ANY,
+ size=(250, -1))
+ wx.CallAfter(self.ColUpLeftlabel.SetFocus)
+
+ self.sizer.Add(item=self.ColUpLeftlabel, border=5, pos=(1, 1),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.sizer.Add(item=self.ColUpLefttxt, border=5, pos=(1, 2),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ #row up/left
+ self.RowUpLeftlabel = wx.StaticText(parent=self, id=wx.ID_ANY,
+ label=_('Row of upper left corner'))
+
+ self.RowUpLefttxt = wx.TextCtrl(parent=self, id=wx.ID_ANY,
+ size=(250, -1))
+ wx.CallAfter(self.RowUpLeftlabel.SetFocus)
+
+ self.sizer.Add(item=self.RowUpLeftlabel, border=5, pos=(2, 1),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.sizer.Add(item=self.RowUpLefttxt, border=5, pos=(2, 2),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+
+ #row lenght
+ self.RowLenlabel = wx.StaticText(parent=self, id=wx.ID_ANY,
+ label=_('Row lenght of sampling frame'))
+
+ self.RowLentxt = wx.TextCtrl(parent=self, id=wx.ID_ANY, size=(250, -1))
+ wx.CallAfter(self.RowLenlabel.SetFocus)
+
+ self.sizer.Add(item=self.RowLenlabel, border=5, pos=(3, 1),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.sizer.Add(item=self.RowLentxt, border=5, pos=(3, 2),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+
+ #column lenght
+ self.ColLenlabel = wx.StaticText(parent=self, id=wx.ID_ANY,
+ label=_('Row lenght of sampling frame'))
+
+ self.ColLentxt = wx.TextCtrl(parent=self, id=wx.ID_ANY, size=(250, -1))
+ wx.CallAfter(self.ColLenlabel.SetFocus)
+
+ self.sizer.Add(item=self.ColLenlabel, border=5, pos=(4, 1),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.sizer.Add(item=self.ColLentxt, border=5, pos=(4, 2),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+
+ self.ColUpLefttxt.SetValue(self.col_up)
+ self.RowUpLefttxt.SetValue(self.row_up)
+
+ self.ColUpLefttxt.Bind(wx.EVT_KILL_FOCUS, self.OnColLeft)
+ 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.OnRowLen)
+ self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
+ self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnExitPage)
+
+ def OnColLeft(self, event):
+ """!Sets the name of configuration file"""
+ self.col_up = self.ColUpLefttxt.GetValue()
+ checkValue(self.col_up)
+
+ def OnRowLeft(self, event):
+ """!Sets the name of configuration file"""
+ self.row_up = self.RowUpLefttxt.GetValue()
+ checkValue(self.row_up)
+
+ def OnColLen(self, event):
+ """!Sets the name of configuration file"""
+ self.col_len = self.ColLentxt.GetValue()
+ checkValue(self.col_len)
+
+ def OnRowLen(self, event):
+ """!Sets the name of configuration file"""
+ self.row_len = self.RowLentxt.GetValue()
+ checkValue(self.row_len)
+
+ def OnEnterPage(self, event):
+ """!Sets the default values, for the entire map
+ """
+ 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.ColLentxt.SetValue(self.col_len)
+ self.RowLentxt.SetValue(self.row_len)
+
+ def OnExitPage(self, event=None):
+ """!Function during exiting"""
+ if self.row_len == '' or self.col_len == '' or self.row_up == '' or self.col_up == '':
+ wx.FindWindowById(wx.ID_FORWARD).Enable(False)
+ else:
+ wx.FindWindowById(wx.ID_FORWARD).Enable(True)
+
+
+class SamplingAreasPage(TitledPage):
+ """
+ Set name of configuration file, choose raster and optionally vector/sites
+ """
+
+ def __init__(self, wizard, parent):
+ TitledPage.__init__(self, wizard, _("Insert sampling areas"))
+ self.samplingtype = 'whole'
+ self.parent = parent
+ # toggles
+ self.radioBox = wx.RadioBox(parent=self, id=wx.ID_ANY,
+ label="",
+ choices=[_("Whole map layer"),
+ _("Regions"),
+ _("Sample units"),
+ _("Moving window"),
+ _("Select areas from the\n"
+ "overlayed vector map")],
+ majorDimension=1,
+ style=wx.RA_SPECIFY_COLS | wx.NO_BORDER)
+ self.radioBox.EnableItem(1, False)
+ self.radioBox.SetItemToolTip(1, _("This option is not supported yet"))
+
+ # layout
+ self.sizer.SetVGap(10)
+ self.sizer.Add(item=self.radioBox, flag=wx.ALIGN_LEFT, pos=(0, 0))
+
+ self.regionBox = wx.RadioBox(parent=self, id=wx.ID_ANY,
+ label=_("Choose a method"),
+ choices=[_('Use keyboard to enter sampling area'),
+ _('Use mouse to draw sampling area')],
+ majorDimension=1,
+ style=wx.RA_SPECIFY_ROWS)
+ self.regionBox.EnableItem(1, False)
+ self.regionBox.SetItemToolTip(1, _("This option is not supported yet"))
+ self.sizer.Add(self.regionBox, flag=wx.ALIGN_CENTER, pos=(1, 0))
+
+ # bindings
+ self.radioBox.Bind(wx.EVT_RADIOBOX, self.SetVal)
+ self.regionBox.Bind(wx.EVT_RADIOBOX, self.OnRegionDraw)
+ self.regionbox = 'keybord'
+
+ self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
+
+ def OnEnterPage(self, event):
+ """!Insert values into text controls for summary of location
+ creation options
+ """
+ self.SetVal(None)
+ if self.parent.startpage.vect:
+ self.radioBox.ShowItem(4, True)
+ else:
+ self.radioBox.ShowItem(4, False)
+ self.sizer.Layout()
+
+ wx.FindWindowById(wx.ID_FORWARD).Enable(True)
+
+ def SetVal(self, event):
+ """!Choose method"""
+ radio = self.radioBox.GetSelection()
+ if radio == 0:
+ self.samplingtype = 'whole'
+ self.DrawNothing()
+ # elif event.GetInt() == 1: # disabled
+ # self.samplingtype = 'regions'
+ # self.Region()
+ elif radio == 2:
+ self.samplingtype = 'units'
+ self.SetNext(self.parent.units)
+ self.KeyDraw()
+ elif radio == 3:
+ self.samplingtype = 'moving'
+ self.SetNext(self.parent.moving)
+ self.KeyDraw()
+ elif radio == 4:
+ self.samplingtype = 'vector'
+ self.DrawNothing()
+
+ def Region(self):
+ """show this only if radio2 it is selected"""
+ try:
+ self.sizer.Hide(self.regionBox)
+ self.sizer.Remove(self.regionBox)
+ self.sizer.Layout()
+ except:
+ pass
+ gcmd.GMessage(parent=self, message=_("Function not supported yet"))
+ return
+
+ def KeyDraw(self):
+ """Show this only if radio3 and radio4 it is selected"""
+ self.sizer.Show(self.regionBox)
+ self.sizer.Layout()
+
+ def OnRegionDraw(self, event):
+ """Function called by KeyDraw to find what method is choosed"""
+ if event.GetInt() == 0:
+ self.regionbox = 'keybord'
+ self.SetNext(self.parent.units)
+
+ elif event.GetInt() == 1:
+ self.regionbox = 'drawmouse'
+ return
+ #self.SetNext(self.parent.draw)
+
+ def DrawNothing(self):
+ """"""
+ self.sizer.Hide(self.regionBox)
+ self.sizer.Layout()
+
+ self.SetNext(self.parent.summarypage)
+
+
+class SampleUnitsKeyPage(TitledPage):
+ """!Set values from keyboard for sample units"""
+
+ def __init__(self, wizard, parent):
+ TitledPage.__init__(self, wizard, _("Units"))
+
+ self.parent = parent
+ self.scrollPanel = scrolled.ScrolledPanel(parent=self, id=wx.ID_ANY)
+ self.scrollPanel.SetupScrolling(scroll_x=False)
+
+ self.panelSizer = wx.GridBagSizer(5, 5)
+ self.width = ''
+ self.height = ''
+ self.boxtype = 'rectangle'
+ self.distrtype = 'non_overlapping'
+ # type of shape
+ self.typeBox = wx.RadioBox(parent=self.scrollPanel, id=wx.ID_ANY,
+ majorDimension=1, style=wx.RA_SPECIFY_COLS,
+ label=" %s " % _("Select type of shape"),
+ choices=[_('Rectangle'), _('Circle')])
+
+ self.panelSizer.Add(self.typeBox, flag=wx.ALIGN_LEFT, pos=(0, 0),
+ span=(1, 2))
+ self.widthLabel = wx.StaticText(parent=self.scrollPanel, id=wx.ID_ANY)
+ self.widthTxt = wx.TextCtrl(parent=self.scrollPanel, id=wx.ID_ANY,
+ size=(250, -1))
+
+ self.panelSizer.Add(item=self.widthLabel, pos=(1, 0),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.panelSizer.Add(item=self.widthTxt, pos=(1, 1),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+
+ self.heightLabel = wx.StaticText(parent=self.scrollPanel, id=wx.ID_ANY)
+ self.heightTxt = wx.TextCtrl(parent=self.scrollPanel, id=wx.ID_ANY,
+ size=(250, -1))
+
+ self.panelSizer.Add(item=self.heightLabel, pos=(2, 0),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.panelSizer.Add(item=self.heightTxt, pos=(2, 1),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.widthLabels = [_('Width size (in cells)? '),
+ _('What radius size (in meters)? ')]
+ self.heightLabels = [_('Height size (in cells)? '),
+ _('Name of the circle mask')]
+
+ self.distributionBox = wx.RadioBox(parent=self.scrollPanel,
+ id=wx.ID_ANY,
+ majorDimension=1,
+ style=wx.RA_SPECIFY_COLS,
+ label= " %s " % _("Select method of sampling unit distribution"),
+ choices=[_('Random non overlapping'),
+ _('Systematic contiguos'),
+ _('Stratified random'),
+ _('Systematic non contiguos'),
+ _('Centered over sites')]
+ )
+ self.distributionBox.EnableItem(5, False) # disable 'draw' for now
+ self.panelSizer.Add(item=self.distributionBox, pos=(3, 0), span=(1, 2),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+
+ self.distr1Label = wx.StaticText(parent=self.scrollPanel, id=wx.ID_ANY,
+ label=_("What number of Sampling " \
+ "Units to use?"))
+ self.distr1Txt = wx.TextCtrl(parent=self.scrollPanel, id=wx.ID_ANY,
+ size=(250, -1))
+ self.panelSizer.Add(item=self.distr1Label, pos=(4, 0),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.panelSizer.Add(item=self.distr1Txt, pos=(4, 1),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.distr2Label = wx.StaticText(parent=self.scrollPanel, id=wx.ID_ANY,
+ label="")
+ self.distr2Txt = wx.TextCtrl(parent=self.scrollPanel, id=wx.ID_ANY,
+ size=(250, -1))
+ self.panelSizer.Add(item=self.distr2Label, pos=(5, 0),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.panelSizer.Add(item=self.distr2Txt, pos=(5, 1),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.panelSizer.Hide(self.distr2Txt)
+
+ self.typeBox.Bind(wx.EVT_RADIOBOX, self.OnType)
+ self.distributionBox.Bind(wx.EVT_RADIOBOX, self.OnDistr)
+ self.widthTxt.Bind(wx.EVT_TEXT, self.OnWidth)
+ self.heightTxt.Bind(wx.EVT_TEXT, self.OnHeight)
+ self.distr1Txt.Bind(wx.EVT_TEXT, self.OnDistr1)
+ self.distr2Txt.Bind(wx.EVT_TEXT, self.OnDistr2)
+ #self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
+ self.sizer.Add(item=self.scrollPanel, pos=(0, 0), flag=wx.EXPAND)
+ self.sizer.AddGrowableCol(0)
+ self.sizer.AddGrowableRow(0)
+ self.scrollPanel.SetSizer(self.panelSizer)
+ self.OnType(None)
+
+ def OnType(self, event):
+ chosen = self.typeBox.GetSelection()
+ self.widthLabel.SetLabel(self.widthLabels[chosen])
+ self.heightLabel.SetLabel(self.heightLabels[chosen])
+ self.panelSizer.Layout()
+ if chosen == 0:
+ self.boxtype = 'rectangle'
+ else:
+ self.boxtype = 'circle'
+
+ def OnDistr(self, event):
+ chosen = self.distributionBox.GetSelection()
+ if chosen == 0:
+ self.distrtype = 'non_overlapping'
+ self.distr1Label.SetLabel(_("What number of Sampling Units to use?"))
+ self.panelSizer.Show(self.distr1Txt)
+ self.distr2Label.SetLabel("")
+ self.panelSizer.Hide(self.distr2Txt)
+ self.panelSizer.Layout()
+ elif chosen == 1:
+ self.distrtype = 'systematic_contiguos'
+ self.distr1Label.SetLabel("")
+ self.distr2Label.SetLabel("")
+ self.panelSizer.Hide(self.distr1Txt)
+ self.panelSizer.Hide(self.distr2Txt)
+ self.panelSizer.Layout()
+ elif chosen == 2:
+ self.distrtype = 'stratified_random'
+ self.distr1Label.SetLabel(_("Insert number of row strates"))
+ self.distr2Label.SetLabel(_("Insert number of column strates"))
+ self.panelSizer.Show(self.distr1Txt)
+ self.panelSizer.Show(self.distr2Txt)
+ self.panelSizer.Layout()
+ elif chosen == 3:
+ self.distrtype = 'systematic_noncontiguos'
+ self.distr1Label.SetLabel(_("Insert distance between units"))
+ self.panelSizer.Show(self.distr1Txt)
+ self.distr2Label.SetLabel("")
+ self.panelSizer.Hide(self.distr2Txt)
+ self.panelSizer.Layout()
+ elif chosen == 4:
+ self.distrtype = 'centered_oversites'
+ self.distr1Label.SetLabel("")
+ self.distr2Label.SetLabel("")
+ self.panelSizer.Hide(self.distr2Txt)
+ self.panelSizer.Hide(self.distr1Txt)
+ self.panelSizer.Layout()
+
+ def OnWidth(self, event):
+ self.width = event.GetString()
+
+ def OnHeight(self, event):
+ self.height = event.GetString()
+
+ def OnDistr1(self, event):
+ self.distr1 = event.GetString()
+
+ def OnDistr2(self, event):
+ self.distr2 = event.GetString()
+
+
+class MovingWindows(TitledPage):
+ """!Set values from keyboard for sample units"""
+
+ def __init__(self, wizard, parent):
+ TitledPage.__init__(self, wizard, _("Units"))
+
+ self.parent = parent
+ self.sizer.AddGrowableCol(2)
+ self.width = ''
+ self.height = ''
+ self.boxtype = ''
+ # type of shape
+ self.typeBox = wx.RadioBox(parent=self, id=wx.ID_ANY,
+ label=" %s " % _("Select type of shape"),
+ choices=[_('Rectangle'), _('Circle')],
+ majorDimension=1,
+ style=wx.RA_SPECIFY_COLS)
+
+ 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.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))
+ 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))
+ 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)
+
+ self.widthLabels = [_('Width size (in cells)? '),
+ _('What radius size (in meters)? ')]
+ self.heightLabels = [_('Height size (in cells)? '),
+ _('Name of the circle mask')]
+
+ self.widthTxt.Bind(wx.EVT_TEXT, self.OnWidth)
+ self.heightTxt.Bind(wx.EVT_TEXT, self.OnHeight)
+
+ def OnEnterPage(self, event):
+ self.OnType(None)
+
+ def OnType(self, event):
+ chosen = self.typeBox.GetSelection()
+ self.widthLabel.SetLabel(self.widthLabels[chosen])
+ self.heightLabel.SetLabel(self.heightLabels[chosen])
+ self.sizer.Layout()
+ if chosen == 0:
+ self.boxtype = 'rectangle'
+ else:
+ self.boxtype = 'circle'
+
+ def OnWidth(self, event):
+ self.width = event.GetString()
+
+ def OnHeight(self, event):
+ self.height = event.GetString()
+
+
+class SummaryPage(TitledPage):
+ """!Shows summary result of choosing data"""
+
+ def __init__(self, wizard, parent):
+ TitledPage.__init__(self, wizard, _("Summary"))
+ global rlisettings
+
+ self.parent = parent
+ self.sizer.AddGrowableCol(2)
+
+ #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=(0, 0),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.sizer.Add(item=self.conftxt, border=5, pos=(0, 1),
+ 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, 0),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.sizer.Add(item=self.rasttxt, border=5, pos=(1, 1),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+
+ #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.vectlabel, border=5, pos=(2, 0),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.sizer.Add(item=self.vecttxt, border=5, pos=(2, 1),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+
+ #region type name
+ self.regionlabel = wx.StaticText(parent=self, id=wx.ID_ANY,
+ label=_('Region type:'))
+ self.regiontxt = wx.StaticText(parent=self, id=wx.ID_ANY,
+ label="")
+ self.sizer.Add(item=self.regionlabel, border=5, pos=(3, 0),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.sizer.Add(item=self.regiontxt, border=5, pos=(3, 1),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+
+ #region keyboard
+ self.regionkeylabel = wx.StaticText(parent=self, id=wx.ID_ANY,
+ label="")
+ self.regionkeytxt = wx.StaticText(parent=self, id=wx.ID_ANY,
+ label="")
+ self.sizer.Add(item=self.regionkeylabel, border=5, pos=(4, 0),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.sizer.Add(item=self.regionkeytxt, border=5, pos=(4, 1),
+ 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=_('Sampling area type:'))
+ self.samplingtxt = wx.StaticText(parent=self, id=wx.ID_ANY,
+ label="")
+ self.sizer.Add(item=self.samplinglabel, border=5, pos=(5, 0),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.sizer.Add(item=self.samplingtxt, border=5, pos=(5, 1),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ #shapetype
+ self.shapelabel = wx.StaticText(parent=self, id=wx.ID_ANY,
+ label="")
+ self.shapetxt = wx.StaticText(parent=self, id=wx.ID_ANY,
+ label="")
+ self.sizer.Add(item=self.shapelabel, border=5, pos=(6, 0),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.sizer.Add(item=self.shapetxt, border=5, pos=(6, 1),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ #shapedim
+ self.shapewidthlabel = wx.StaticText(parent=self, id=wx.ID_ANY,
+ label="")
+ self.shapewidthtxt = wx.StaticText(parent=self, id=wx.ID_ANY,
+ label="")
+ self.sizer.Add(item=self.shapewidthlabel, border=5, pos=(7, 0),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.sizer.Add(item=self.shapewidthtxt, border=5, pos=(7, 1),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.shapeheightlabel = wx.StaticText(parent=self, id=wx.ID_ANY,
+ label="")
+ self.shapeheighttxt = wx.StaticText(parent=self, id=wx.ID_ANY,
+ label="")
+ self.sizer.Add(item=self.shapeheightlabel, border=5, pos=(8, 0),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.sizer.Add(item=self.shapeheighttxt, border=5, pos=(8, 1),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ #units type
+ self.unitslabel = wx.StaticText(parent=self, id=wx.ID_ANY, label="")
+ self.unitstxt = wx.StaticText(parent=self, id=wx.ID_ANY, label="")
+ self.sizer.Add(item=self.unitslabel, border=5, pos=(9, 0),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.sizer.Add(item=self.unitstxt, border=5, pos=(9, 1),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.unitsmorelabel = wx.StaticText(parent=self, id=wx.ID_ANY,
+ label="")
+ self.unitsmoretxt = wx.StaticText(parent=self, id=wx.ID_ANY, label="")
+ self.sizer.Add(item=self.unitsmorelabel, border=5, pos=(10, 0),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.sizer.Add(item=self.unitsmoretxt, border=5, pos=(10, 1),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.unitsmorelabel2 = wx.StaticText(parent=self, id=wx.ID_ANY,
+ label="")
+ self.unitsmoretxt2 = wx.StaticText(parent=self, id=wx.ID_ANY, label="")
+ self.sizer.Add(item=self.unitsmorelabel2, border=5, pos=(11, 0),
+ flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+ self.sizer.Add(item=self.unitsmoretxt2, border=5, pos=(11, 1),
+ 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.samplingtxt.SetLabel(self.parent.samplingareapage.samplingtype)
+ self.regiontxt.SetLabel(self.parent.startpage.region)
+ self.vecttxt.SetLabel(self.parent.startpage.vect)
+ if self.parent.startpage.region == 'key':
+ #region keybord values
+ self.regionkeylabel.SetLabel(_('Region keybord values:'))
+ regKeyVals = "Column left up: %s - Row left up: %s\n" \
+ "Column 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)
+ else:
+ self.regionkeylabel.SetLabel("")
+ self.regionkeytxt.SetLabel("")
+
+ if self.parent.samplingareapage.samplingtype == 'units':
+ self.shapelabel.SetLabel(_('Type of shape:'))
+ self.shapetxt.SetLabel(self.parent.units.boxtype)
+ if self.parent.units.boxtype == 'circle':
+ self.shapewidthlabel.SetLabel(_("Radius size:"))
+ self.shapeheightlabel.SetLabel(_("Name circle mask:"))
+ else:
+ self.shapewidthlabel.SetLabel(_("Width size:"))
+ self.shapeheightlabel.SetLabel(_("Heigth size:"))
+ self.shapewidthtxt.SetLabel(self.parent.units.width)
+ self.shapeheighttxt.SetLabel(self.parent.units.height)
+ self.unitslabel.SetLabel(_("Method of distribution:"))
+ self.unitstxt.SetLabel(self.parent.units.distrtype)
+ if self.parent.units.distrtype == 'non_overlapping':
+ self.unitsmorelabel.SetLabel(_("Number sampling units:"))
+ self.unitsmoretxt.SetLabel(self.parent.units.distr1)
+ elif self.parent.units.distrtype == 'systematic_noncontiguos':
+ self.unitsmorelabel.SetLabel(_("Distance between units:"))
+ self.unitsmoretxt.SetLabel(self.parent.units.distr1)
+ elif self.parent.units.distrtype == 'stratified_random':
+ self.unitsmorelabel.SetLabel(_("Number row strates:"))
+ self.unitsmoretxt.SetLabel(self.parent.units.distr1)
+ self.unitsmorelabel2.SetLabel(_("Number column strates:"))
+ self.unitsmoretxt2.SetLabel(self.parent.units.distr2)
+ elif self.parent.samplingareapage.samplingtype == 'moving':
+ self.shapelabel.SetLabel(_('Type of shape:'))
+ self.shapetxt.SetLabel(self.parent.moving.boxtype)
+ if self.parent.moving.boxtype == 'circle':
+ self.shapewidthlabel.SetLabel(_("Radius size:"))
+ self.shapeheightlabel.SetLabel(_("Name circle mask:"))
+ else:
+ self.shapewidthlabel.SetLabel(_("Width size:"))
+ self.shapeheightlabel.SetLabel(_("Heigth size:"))
+ self.shapewidthtxt.SetLabel(self.parent.moving.width)
+ self.shapeheighttxt.SetLabel(self.parent.moving.height)
+ else:
+ self.shapelabel.SetLabel("")
+ self.shapetxt.SetLabel("")
+ self.shapewidthlabel.SetLabel("")
+ self.shapewidthtxt.SetLabel("")
+ self.shapeheightlabel.SetLabel("")
+ self.shapeheighttxt.SetLabel("")
Deleted: grass/trunk/gui/wxpython/scripts/r.li.setup.py
===================================================================
--- grass/trunk/gui/wxpython/scripts/r.li.setup.py 2012-11-26 09:50:59 UTC (rev 54044)
+++ grass/trunk/gui/wxpython/scripts/r.li.setup.py 2012-11-26 11:31:41 UTC (rev 54045)
@@ -1,731 +0,0 @@
-"""
-MODULE: r_li_setup_GUI.py
-
-AUTHOR(S): Anne Ghisla <a.ghisla AT gmail.com>
-
-PURPOSE: Dedicated GUI for r.li.setup, translated and reshaped from original TclTk.
-
-DEPENDS: []
-
-COPYRIGHT: (C) 2010 by the GRASS Development Team
-
-This program is free software under the GNU General Public
-License (>=v2). Read the file COPYING that comes with GRASS
-for details.
-"""
-# bulk import from location_wizard.py.
-import os
-import shutil
-import re
-import string
-import sys
-import locale
-import platform
-
-GUIModulesPath = os.path.join(os.getenv("GISBASE"), "etc", "gui", "wxpython", "gui_modules")
-sys.path.append(GUIModulesPath)
-
-from core import globalvar
-
-import wx
-import wx.lib.mixins.listctrl as listmix
-import wx.wizard as wiz
-import wx.lib.scrolledpanel as scrolled
-import time
-
-from core import cmd as gcmd
-from core import utils
-from grass.script import core as grass
-
-#@TODO create wizard instead of progressively increasing window
-
-print >> sys.stderr, "TODO: implement r.li.setup wizard..."
-
-#@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
-
-class BaseClass(wx.Object):
- """!Base class providing basic methods"""
- def __init__(self):
- pass
-
- def MakeLabel(self, text="", style=wx.ALIGN_LEFT, parent=None):
- """!Make aligned label"""
- if not parent:
- parent = self
- return wx.StaticText(parent=parent, id=wx.ID_ANY, label=text,
- style=style)
-
- def MakeTextCtrl(self, text='', size=(100,-1), style=0, parent=None):
- """!Generic text control"""
- if not parent:
- parent = self
- return wx.TextCtrl(parent=parent, id=wx.ID_ANY, value=text,
- size=size, style=style)
-
- def MakeButton(self, text, id=wx.ID_ANY, size=(-1,-1), parent=None):
- """!Generic button"""
- if not parent:
- parent = self
- return wx.Button(parent=parent, id=id, label=text,
- size=size)
-
-class TitledPage(BaseClass, wiz.WizardPageSimple):
- """
- Class to make wizard pages. Generic methods to make
- labels, text entries, and buttons.
- """
- def __init__(self, parent, title):
-
- self.page = wiz.WizardPageSimple.__init__(self, parent)
-
- # page title
- self.title = wx.StaticText(parent=self, id=wx.ID_ANY, label=title)
- self.title.SetFont(wx.Font(13, wx.SWISS, wx.NORMAL, wx.BOLD))
-
- # main sizers
- self.pagesizer = wx.BoxSizer(wx.VERTICAL)
- self.sizer = wx.GridBagSizer(vgap=0, hgap=0)
-
- def DoLayout(self):
- """!Do page layout"""
-
-
- self.pagesizer.Add(item=self.title, proportion=0,
- flag=wx.ALIGN_CENTRE | wx.ALL,
- border=5)
- self.pagesizer.Add(item=wx.StaticLine(self, -1), proportion=0,
- flag=wx.EXPAND | wx.ALL,
- border=0)
- self.pagesizer.Add(item=self.sizer)
-
- self.SetAutoLayout(True)
- self.SetSizer(self.pagesizer)
- # tmpsizer.Fit(self)
- self.Layout()
-
-
-class LocationWizard(wx.Object):
- """
- Start wizard here and finish wizard here
- """
- def __init__(self, parent):
-# global coordsys
- self.parent = parent
-
- #
- # define wizard image
- #
- # file = "loc_wizard.png"
- file = "loc_wizard_qgis.png"
- imagePath = os.path.join(globalvar.ETCIMGDIR, file)
- wizbmp = wx.Image(imagePath, wx.BITMAP_TYPE_PNG)
- # wizbmp.Rescale(250,600)
- wizbmp = wizbmp.ConvertToBitmap()
-
- #
- # get georeferencing information from tables in $GISBASE/etc
- #
-# self.__readData()
-#
-# #
-# # datum transform number and list of datum transforms
-# #
-# self.datumtrans = 0
-# self.proj4string = ''
-#
-# #
-# # define wizard pages
-# #
- self.wizard = wiz.Wizard(parent, id=wx.ID_ANY, title=_("I m!"),
- bitmap=wizbmp)
- self.startpage = SummaryPage(self.wizard, self)
-# self.csystemspage = CoordinateSystemPage(self.wizard, self)
-# self.projpage = ProjectionsPage(self.wizard, self)
-# self.datumpage = DatumPage(self.wizard, self)
-# self.paramspage = ProjParamsPage(self.wizard,self)
-# self.epsgpage = EPSGPage(self.wizard, self)
-# self.filepage = GeoreferencedFilePage(self.wizard, self)
-# self.wktpage = WKTPage(self.wizard, self)
-# self.ellipsepage = EllipsePage(self.wizard, self)
-# self.custompage = CustomPage(self.wizard, self)
-# self.sumpage = SummaryPage(self.wizard, self)
-#
-# #
-# # set the initial order of the pages
-# # (should follow the epsg line)
-# #
-# self.startpage.SetNext(self.csystemspage)
-#
-# self.csystemspage.SetPrev(self.startpage)
-# self.csystemspage.SetNext(self.sumpage)
-#
-# self.projpage.SetPrev(self.csystemspage)
-# self.projpage.SetNext(self.paramspage)
-#
-# self.paramspage.SetPrev(self.projpage)
-# self.paramspage.SetNext(self.datumpage)
-#
-# self.datumpage.SetPrev(self.paramspage)
-# self.datumpage.SetNext(self.sumpage)
-#
-# self.ellipsepage.SetPrev(self.paramspage)
-# self.ellipsepage.SetNext(self.sumpage)
-#
-# self.epsgpage.SetPrev(self.csystemspage)
-# self.epsgpage.SetNext(self.sumpage)
-#
-# self.filepage.SetPrev(self.csystemspage)
-# self.filepage.SetNext(self.sumpage)
-#
-# self.wktpage.SetPrev(self.csystemspage)
-# self.wktpage.SetNext(self.sumpage)
-#
-# self.custompage.SetPrev(self.csystemspage)
-# self.custompage.SetNext(self.sumpage)
-#
-# self.sumpage.SetPrev(self.csystemspage)
-#
-# #
-# # do pages layout
-# #
-# self.startpage.DoLayout()
-# self.csystemspage.DoLayout()
-# self.projpage.DoLayout()
-# self.datumpage.DoLayout()
-# self.paramspage.DoLayout()
-# self.epsgpage.DoLayout()
-# self.filepage.DoLayout()
-# self.wktpage.DoLayout()
-# self.ellipsepage.DoLayout()
-# self.custompage.DoLayout()
-# self.sumpage.DoLayout()
-# self.wizard.FitToPage(self.datumpage)
-#
-# # new location created?
-# self.location = None
-# success = False
-#
-# # location created in different GIS database?
-# self.altdb = False
-
- #
- # run wizard...
- #
- if self.wizard.RunWizard(self.startpage):
- pass
-# msg = self.OnWizFinished()
-# if len(msg) < 1:
-# self.wizard.Destroy()
-# self.location = self.startpage.location
-#
-# if self.altdb == False:
-# dlg = wx.MessageDialog(parent=self.parent,
-# message=_("Do you want to set the default "
-# "region extents and resolution now?"),
-# caption=_("Location <%s> created") % self.location,
-# style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
-# dlg.CenterOnScreen()
-# if dlg.ShowModal() == wx.ID_YES:
-# dlg.Destroy()
-# defineRegion = RegionDef(self.parent, location=self.location)
-# defineRegion.CenterOnScreen()
-# defineRegion.Show()
-# else:
-# dlg.Destroy()
-# else: # -> error
-# self.wizard.Destroy()
-# wx.MessageBox(parent=self.parent,
-# message="%s" % _("Unable to create new location. "
-# "Location <%(loc)s> not created.\n\n"
-# "Details: %(err)s") % \
-# { 'loc' : self.startpage.location,
-# 'err' : msg },
-# caption=_("Location wizard"),
-# style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
-# else:
-# win = wx.MessageBox(parent=self.parent,
-# message=_("Location wizard canceled. "
-# "Location not created."),
-# caption=_("Location wizard"))
-
- def __readData(self):
- """!Get georeferencing information from tables in $GISBASE/etc/proj"""
-
- # read projection and parameters
- f = open(os.path.join(globalvar.ETCDIR, "proj", "parms.table"), "r")
- self.projections = {}
- self.projdesc = {}
- for line in f.readlines():
- line = line.strip()
- try:
- proj, projdesc, params = line.split(':')
- paramslist = params.split(';')
- plist = []
- for p in paramslist:
- if p == '': continue
- p1, pdefault = p.split(',')
- pterm, pask = p1.split('=')
- p = [pterm.strip(), pask.strip(), pdefault.strip()]
- plist.append(p)
- self.projections[proj.lower().strip()] = (projdesc.strip(), plist)
- self.projdesc[proj.lower().strip()] = projdesc.strip()
- except:
- continue
- f.close()
-
- # read datum definitions
- f = open(os.path.join(globalvar.ETCDIR, "proj", "datum.table"), "r")
- self.datums = {}
- paramslist = []
- for line in f.readlines():
- line = line.expandtabs(1)
- line = line.strip()
- if line == '' or line[0] == "#":
- continue
- datum, info = line.split(" ", 1)
- info = info.strip()
- datumdesc, params = info.split(" ", 1)
- datumdesc = datumdesc.strip('"')
- paramlist = params.split()
- ellipsoid = paramlist.pop(0)
- self.datums[datum] = (ellipsoid, datumdesc.replace('_', ' '), paramlist)
- f.close()
-
- # read ellipsiod definitions
- f = open(os.path.join(globalvar.ETCDIR, "proj", "ellipse.table"), "r")
- self.ellipsoids = {}
- for line in f.readlines():
- line = line.expandtabs(1)
- line = line.strip()
- if line == '' or line[0] == "#":
- continue
- ellipse, rest = line.split(" ", 1)
- rest = rest.strip('" ')
- desc, params = rest.split('"', 1)
- desc = desc.strip('" ')
- paramslist = params.split()
- self.ellipsoids[ellipse] = (desc, paramslist)
- f.close()
-
- # read projection parameter description and parsing table
- f = open(os.path.join(globalvar.ETCDIR, "proj", "desc.table"), "r")
- self.paramdesc = {}
- for line in f.readlines():
- line = line.strip()
- try:
- pparam, datatype, proj4term, desc = line.split(':')
- self.paramdesc[pparam] = (datatype, proj4term, desc)
- except:
- continue
- f.close()
-
- def OnWizFinished(self):
- database = self.startpage.grassdatabase
- location = self.startpage.location
- global coordsys
- msg = '' # error message (empty on success)
-
- # location already exists?
- if os.path.isdir(os.path.join(database,location)):
- dlg = wx.MessageDialog(parent=self.wizard,
- message="%s <%s>: %s" % \
- (_("Unable to create new location"),
- os.path.join(database, location),
- _("Location already exists in GRASS Database.")),
- caption=_("Error"),
- style=wx.OK | wx.ICON_ERROR)
- dlg.ShowModal()
- dlg.Destroy()
- return False
-
- # current GISDbase or a new one?
- current_gdb = grass.gisenv()['GISDBASE']
- if current_gdb != database:
- # change to new GISDbase or create new one
- if os.path.isdir(database) != True:
- # create new directory
- os.mkdir(database)
-
- # change to new GISDbase directory
- gcmd.RunCommand('g.gisenv',
- parent = self.wizard,
- set='GISDBASE=%s' % database)
-
- wx.MessageBox(parent=self.wizard,
- message=_("Location <%(loc)s> will be created "
- "in GIS data directory <%(dir)s>."
- "You will need to change the default GIS "
- "data directory in the GRASS startup screen.") % \
- { 'loc' : location, 'dir' : database},
- caption=_("New GIS data directory"),
- style=wx.OK | wx.ICON_INFORMATION | wx.CENTRE)
- # location created in alternate GISDbase
- self.altdb = True
-
- if coordsys == "xy":
- msg = self.XYCreate()
- elif coordsys == "proj":
- proj4string = self.CreateProj4String()
- msg = self.Proj4Create(proj4string)
- elif coordsys == 'custom':
- msg = self.CustomCreate()
- elif coordsys == "epsg":
- msg = self.EPSGCreate()
- elif coordsys == "file":
- msg = self.FileCreate()
- elif coordsys == "wkt":
- msg = self.WKTCreate()
-
- return msg
-
- def XYCreate(self):
- """!Create an XY location
-
- @return error message (empty string on success)
- """
- database = self.startpage.grassdatabase
- location = self.startpage.location
-
- # create location directory and PERMANENT mapset
- try:
- os.mkdir(os.path.join(database, location))
- os.mkdir(os.path.join(database, location, 'PERMANENT'))
- # create DEFAULT_WIND and WIND files
- regioninfo = ['proj: 0',
- 'zone: 0',
- 'north: 1',
- 'south: 0',
- 'east: 1',
- 'west: 0',
- 'cols: 1',
- 'rows: 1',
- 'e-w resol: 1',
- 'n-s resol: 1',
- 'top: 1',
- 'bottom: 0',
- 'cols3: 1',
- 'rows3: 1',
- 'depths: 1',
- 'e-w resol3: 1',
- 'n-s resol3: 1',
- 't-b resol: 1']
-
- defwind = open(os.path.join(database, location,
- "PERMANENT", "DEFAULT_WIND"), 'w')
- for param in regioninfo:
- defwind.write(param + '%s' % os.linesep)
- defwind.close()
-
- shutil.copy(os.path.join(database, location, "PERMANENT", "DEFAULT_WIND"),
- os.path.join(database, location, "PERMANENT", "WIND"))
-
- # create MYNAME file
- myname = open(os.path.join(database, location, "PERMANENT",
- "MYNAME"), 'w')
- myname.write('%s' % os.linesep)
- myname.close()
- except OSError, e:
- return e
-
- return ''
-
- def CreateProj4String(self):
- """!Constract PROJ.4 string"""
- location = self.startpage.location
- proj = self.projpage.p4proj
- projdesc = self.projpage.projdesc
- proj4params = self.paramspage.p4projparams
-
- datum = self.datumpage.datum
- if self.datumpage.datumdesc:
- datumdesc = self.datumpage.datumdesc +' - ' + self.datumpage.ellipse
- else:
- datumdesc = ''
- datumparams = self.datumpage.datumparams
- ellipse = self.ellipsepage.ellipse
- ellipsedesc = self.ellipsepage.ellipsedesc
- ellipseparams = self.ellipsepage.ellipseparams
-
- #
- # creating PROJ.4 string
- #
- proj4string = '%s %s' % (proj, proj4params)
-
- # set ellipsoid parameters
- if ellipse != '': proj4string = '%s +ellps=%s' % (proj4string, ellipse)
- for item in ellipseparams:
- if item[:4] == 'f=1/':
- item = ' +rf='+item[4:]
- else:
- item = ' +'+item
- proj4string = '%s %s' % (proj4string, item)
-
- # set datum and transform parameters if relevant
- if datum != '': proj4string = '%s +datum=%s' % (proj4string, datum)
- if datumparams:
- for item in datumparams:
- proj4string = '%s +%s' % (proj4string,item)
-
- proj4string = '%s +no_defs' % proj4string
-
- return proj4string
-
- def Proj4Create(self, proj4string):
- """!Create a new location for selected projection
-
- @return error message (empty string on success)
- """
- ret, msg = gcmd.RunCommand('g.proj',
- flags = 'c',
- proj4 = proj4string,
- location = self.startpage.location,
- datumtrans = self.datumtrans,
- getErrorMsg = True)
-
- if ret == 0:
- return ''
-
- return msg
-
-
- def CustomCreate(self):
- """!Create a new location based on given proj4 string
-
- @return error message (empty string on success)
- """
- proj4string = self.custompage.customstring
- location = self.startpage.location
-
- ret, msg = gcmd.RunCommand('g.proj',
- flags = 'c',
- proj4 = proj4string,
- location = location,
- getErrorMsg = True)
-
- if ret == 0:
- return ''
-
- return msg
-
- def EPSGCreate(self):
- """!Create a new location from an EPSG code.
-
- @return error message (empty string on success)
- """
- epsgcode = self.epsgpage.epsgcode
- epsgdesc = self.epsgpage.epsgdesc
- location = self.startpage.location
-
- # should not happend
- if epsgcode == '':
- return _('EPSG code missing.')
-
- ret, msg = gcmd.RunCommand('g.proj',
- flags = 'c',
- epsg = epsgcode,
- location = location,
- datumtrans = self.datumtrans,
- getErrorMsg = True)
-
- if ret == 0:
- return ''
-
- return msg
-
- def FileCreate(self):
- """!Create a new location from a georeferenced file
-
- @return error message (empty string on success)
- """
- georeffile = self.filepage.georeffile
- location = self.startpage.location
-
- # this should not happen
- if not georeffile or not os.path.isfile(georeffile):
- return _("File not found.")
-
- # creating location
- ret, msg = gcmd.RunCommand('g.proj',
- flags = 'c',
- georef = georeffile,
- location = location,
- getErrorMsg = True)
-
- if ret == 0:
- return ''
-
- return msg
-
- def WKTCreate(self):
- """!Create a new location from a WKT file
-
- @return error message (empty string on success)
- """
- wktfile = self.wktpage.wktfile
- location = self.startpage.location
-
- # this should not happen
- if not wktfile or not os.path.isfile(wktfile):
- return _("File not found.")
-
- # creating location
- ret, msg = gcmd.RunCommand('g.proj',
- flags = 'c',
- wkt = wktfile,
- location = location,
- getErrorMsg = True)
-
- if ret == 0:
- return ''
-
- return msg
-
-class SummaryPage(TitledPage):
- """
- Shows summary result of choosing coordinate system parameters
- prior to creating location
- """
- def __init__(self, wizard, parent):
- TitledPage.__init__(self, wizard, _("Summary"))
-
- self.parent = parent
-
- # labels
- self.ldatabase = self.MakeLabel("")
- self.llocation = self.MakeLabel("")
- self.lprojection = self.MakeLabel("")
- self.lproj4string = self.MakeLabel("")
- self.lproj4stringLabel = self.MakeLabel("")
-
- self.lprojection.Wrap(400)
-
- self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
- # self.Bind(wx.EVT_BUTTON, self.OnFinish, wx.ID_FINISH)
-
- # do sub-page layout
- self.__DoLayout()
-
- def __DoLayout(self):
- """!Do page layout"""
- self.sizer.AddGrowableCol(1)
- self.sizer.Add(item=self.MakeLabel(_("GRASS Database:")),
- flag=wx.ALIGN_LEFT | wx.ALL,
- border=5, pos=(1, 0))
- self.sizer.Add(item=self.ldatabase,
- flag=wx.ALIGN_LEFT | wx.ALL,
- border=5, pos=(1, 1))
- self.sizer.Add(item=self.MakeLabel(_("Location Name:")),
- flag=wx.ALIGN_LEFT | wx.ALL,
- border=5, pos=(2, 0))
- self.sizer.Add(item=self.llocation,
- flag=wx.ALIGN_LEFT | wx.ALL,
- border=5, pos=(2, 1))
- self.sizer.Add(item=self.MakeLabel(_("Projection:")),
- flag=wx.ALIGN_LEFT | wx.ALL,
- border=5, pos=(3, 0))
- self.sizer.Add(item=self.lprojection,
- flag=wx.ALIGN_LEFT | wx.ALL,
- border=5, pos=(3, 1))
- self.sizer.Add(item=self.lproj4stringLabel,
- flag=wx.ALIGN_LEFT | wx.ALL,
- border=5, pos=(4, 0))
- self.sizer.Add(item=self.lproj4string,
- flag=wx.ALIGN_LEFT | wx.ALL,
- border=5, pos=(4, 1))
- self.sizer.Add(item=(10,20),
- flag=wx.ALIGN_CENTER_HORIZONTAL | wx.ALL,
- border=5, pos=(5, 0), span=(1, 2))
-
- def OnEnterPage(self,event):
- """
- Insert values into text controls for summary of location creation options
- """
-
-# database = self.parent.startpage.grassdatabase
-# location = self.parent.startpage.location
- proj4string = self.parent.CreateProj4String()
- epsgcode = self.parent.epsgpage.epsgcode
- dtrans = self.parent.datumtrans
-
- global coordsys
- if coordsys not in ['proj', 'epsg']:
- self.lproj4stringLabel.Hide()
- self.lproj4string.Hide()
- self.lproj4stringLabel.SetLabel('')
- self.lproj4string.SetLabel('')
- else:
- self.lproj4string.Show()
- self.lproj4stringLabel.SetLabel(_("PROJ.4 definition:"))
- if coordsys == 'proj':
- ret, msg, err = gcmd.RunCommand('g.proj',
- flags = 'j',
- proj4 = proj4string,
- datumtrans = dtrans,
- location = location,
- getErrorMsg = True,
- read = True)
- elif coordsys == 'epsg':
- ret, msg, err = gcmd.RunCommand('g.proj',
- flags = 'j',
- epsg = epsgcode,
- datumtrans = dtrans,
- location = location,
- getErrorMsg = True,
- read = True)
-
- if ret == 0:
- projlabel = ''
- for line in msg.splitlines():
- projlabel = projlabel + '%s ' % line
- self.lproj4string.SetLabel(projlabel)
- else:
- wx.MessageBox(err, 'Error', wx.ICON_ERROR)
-
- self.lproj4string.Wrap(400)
-
- projdesc = self.parent.projpage.projdesc
- ellipsedesc = self.parent.ellipsepage.ellipsedesc
- datumdesc = self.parent.datumpage.datumdesc
-# self.ldatabase.SetLabel(database)
-# self.llocation.SetLabel(location)
- label = ''
-
- if coordsys == 'epsg':
- label = 'EPSG code %s (%s)' % (self.parent.epsgpage.epsgcode, self.parent.epsgpage.epsgdesc)
- self.lprojection.SetLabel(label)
- elif coordsys == 'file':
- label = 'matches file %s' % self.parent.filepage.georeffile
- self.lprojection.SetLabel(label)
- elif coordsys == 'wkt':
- label = 'matches file %s' % self.parent.wktpage.wktfile
- self.lprojection.SetLabel(label)
- elif coordsys == 'proj':
- label = ('%s, %s %s' % (projdesc, datumdesc, ellipsedesc))
- self.lprojection.SetLabel(label)
- elif coordsys == 'xy':
- label = ('XY coordinate system (not projected).')
- self.lprojection.SetLabel(label)
- elif coordsys == 'custom':
- label = ('%s' % self.parent.custompage.customstring)
- self.lprojection.SetLabel(label)
-
- def OnFinish(self, event):
- dlg = wx.MessageDialog(parent=self.wizard,
- message=_("Do you want to create GRASS location <%s>?") % location,
- caption=_("Create new location?"),
- style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
-
- if dlg.ShowModal() == wx.ID_NO:
- dlg.Destroy()
- event.Veto()
- else:
- dlg.Destroy()
- event.Skip()
-
-if __name__ == "__main__":
- app = wx.App()
- gWizard = LocationWizard(None)
-# gWizard.Show()
- app.MainLoop()
More information about the grass-commit
mailing list