[GRASS-SVN] r52860 - in grass/trunk/gui/wxpython: . lmgr location_wizard
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Aug 23 09:08:20 PDT 2012
Author: annakrat
Date: 2012-08-23 09:08:19 -0700 (Thu, 23 Aug 2012)
New Revision: 52860
Modified:
grass/trunk/gui/wxpython/gis_set.py
grass/trunk/gui/wxpython/lmgr/frame.py
grass/trunk/gui/wxpython/location_wizard/dialogs.py
grass/trunk/gui/wxpython/location_wizard/wizard.py
Log:
wxGUI/locationWizard: automatic import of file used for creating location, automatic GUI start (co-author wenzeslaus), merge from releasebranch, r52789
Modified: grass/trunk/gui/wxpython/gis_set.py
===================================================================
--- grass/trunk/gui/wxpython/gis_set.py 2012-08-23 16:05:42 UTC (rev 52859)
+++ grass/trunk/gui/wxpython/gis_set.py 2012-08-23 16:08:19 UTC (rev 52860)
@@ -41,6 +41,7 @@
from gui_core.ghelp import HelpFrame
from core.gcmd import GMessage, GError, DecodeString, RunCommand
from core.utils import GetListOfLocations, GetListOfMapsets
+from location_wizard.dialogs import RegionDef
sys.stderr = codecs.getwriter('utf8')(sys.stderr)
@@ -387,11 +388,91 @@
gWizard = LocationWizard(parent = self,
grassdatabase = self.tgisdbase.GetValue())
if gWizard.location != None:
- self.OnSetDatabase(event)
+ self.tgisdbase.SetValue(gWizard.grassdatabase)
+ self.OnSetDatabase(None)
self.UpdateMapsets(os.path.join(self.gisdbase, gWizard.location))
self.lblocations.SetSelection(self.listOfLocations.index(gWizard.location))
self.lbmapsets.SetSelection(0)
+ self.SetLocation(self.gisdbase, gWizard.location, 'PERMANENT')
+ if gWizard.georeffile:
+ message = _("Do you want to import data source <%(name)s> to created location?"
+ " Default region will be set to match imported map.") % {'name': gWizard.georeffile}
+ dlg = wx.MessageDialog(parent = self,
+ message = message,
+ caption = _("Import data"),
+ style = wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
+ dlg.CenterOnScreen()
+ if dlg.ShowModal() == wx.ID_YES:
+ self.ImportFile(gWizard.georeffile)
+ else:
+ self.SetDefaultRegion(location = gWizard.location)
+ dlg.Destroy()
+ else:
+ self.SetDefaultRegion(location = gWizard.location)
+ self.ExitSuccessfully()
+
+ def SetDefaultRegion(self, location):
+ """!Asks to set default region."""
+ dlg = wx.MessageDialog(parent = self,
+ message = _("Do you want to set the default "
+ "region extents and resolution now?"),
+ caption = _("Location <%s> created") % location,
+ style = wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
+ dlg.CenterOnScreen()
+ if dlg.ShowModal() == wx.ID_YES:
+ dlg.Destroy()
+ defineRegion = RegionDef(self, location = location)
+ defineRegion.CenterOnScreen()
+ defineRegion.ShowModal()
+ defineRegion.Destroy()
+ else:
+ dlg.Destroy()
+
+ def ImportFile(self, filePath):
+ """!Tries to import file as vector or raster.
+
+ If successfull sets default region from imported map.
+ """
+ returncode, stdout, messagesIfVector = RunCommand('v.in.ogr', dsn = filePath, flags = 'l',
+ read = True, getErrorMsg = True)
+ if returncode == 0:
+ wx.BeginBusyCursor()
+ wx.Yield()
+ returncode, messages = RunCommand('v.in.ogr', dsn = filePath,
+ output = os.path.splitext(os.path.basename(filePath))[0],
+ getErrorMsg = True)
+ wx.EndBusyCursor()
+ if returncode != 0:
+ message = _("Import of vector data source <%(name)s> failed.") % {'name': filePath}
+ message += "\n" + messages
+ GError(message = message)
+ else:
+ GMessage(message = _("Vector data source <%(name)s> imported successfully.") % {'name': filePath})
+ stdout = RunCommand('g.list', type = 'vect', read = True)
+ maps = stdout.splitlines()
+ if maps:
+ # TODO: what about resolution?
+ RunCommand('g.region', flags = 's', vect = maps[0])
+
+ else:
+ wx.BeginBusyCursor()
+ wx.Yield()
+ returncode, messages = RunCommand('r.in.gdal', input = filePath,
+ output = os.path.splitext(os.path.basename(filePath))[0],
+ getErrorMsg = True)
+ wx.EndBusyCursor()
+ if returncode != 0:
+ message = _("Attempt to import data source <%(name)s> as raster or vector failed. ") % {'name': filePath}
+ message += "\n\n" + messagesIfVector + "\n" + messages
+ GError(message = message)
+ else:
+ GMessage(message = _("Raster data source <%(name)s> imported successfully.") % {'name': filePath})
+ stdout = RunCommand('g.list', type = 'rast', read = True)
+ maps = stdout.splitlines()
+ if maps:
+ RunCommand('g.region', flags = 's', rast = maps[0])
+
def OnManageLoc(self, event):
"""!Location management choice control handler
"""
@@ -774,7 +855,10 @@
return
else:
return
-
+ self.SetLocation(dbase, location, mapset)
+ self.ExitSuccessfully()
+
+ def SetLocation(self, dbase, location, mapset):
RunCommand("g.gisenv",
set = "GISDBASE=%s" % dbase)
RunCommand("g.gisenv",
@@ -782,6 +866,8 @@
RunCommand("g.gisenv",
set = "MAPSET=%s" % mapset)
+
+ def ExitSuccessfully(self):
self.Destroy()
sys.exit(0)
Modified: grass/trunk/gui/wxpython/lmgr/frame.py
===================================================================
--- grass/trunk/gui/wxpython/lmgr/frame.py 2012-08-23 16:05:42 UTC (rev 52859)
+++ grass/trunk/gui/wxpython/lmgr/frame.py 2012-08-23 16:08:19 UTC (rev 52860)
@@ -324,6 +324,7 @@
def OnLocationWizard(self, event):
"""!Launch location wizard"""
from location_wizard.wizard import LocationWizard
+ from location_wizard.dialogs import RegionDef
gWizard = LocationWizard(parent = self,
grassdatabase = grass.gisenv()['GISDBASE'])
@@ -350,6 +351,22 @@
message = _("Current location is <%(loc)s>.\n"
"Current mapset is <%(mapset)s>.") % \
{ 'loc' : location, 'mapset' : 'PERMANENT' })
+
+ # code duplication with gis_set.py
+ dlg = wx.MessageDialog(parent = self,
+ message = _("Do you want to set the default "
+ "region extents and resolution now?"),
+ caption = _("Location <%s> created") % location,
+ style = wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
+ dlg.CenterOnScreen()
+ if dlg.ShowModal() == wx.ID_YES:
+ dlg.Destroy()
+ defineRegion = RegionDef(self, location = location)
+ defineRegion.CenterOnScreen()
+ defineRegion.ShowModal()
+ defineRegion.Destroy()
+ else:
+ dlg.Destroy()
def OnSettingsChanged(self, event):
"""!Here can be functions which have to be called after EVT_SETTINGS_CHANGED.
Modified: grass/trunk/gui/wxpython/location_wizard/dialogs.py
===================================================================
--- grass/trunk/gui/wxpython/location_wizard/dialogs.py 2012-08-23 16:05:42 UTC (rev 52859)
+++ grass/trunk/gui/wxpython/location_wizard/dialogs.py 2012-08-23 16:08:19 UTC (rev 52860)
@@ -29,12 +29,12 @@
from grass.script import core as grass
-class RegionDef(BaseClass, wx.Frame):
+class RegionDef(BaseClass, wx.Dialog):
"""!Page for setting default region extents and resolution
"""
def __init__(self, parent, id = wx.ID_ANY,
title = _("Set default region extent and resolution"), location = None):
- wx.Frame.__init__(self, parent, id, title, size = (650,300))
+ wx.Dialog.__init__(self, parent, id, title, size = (650,300))
panel = wx.Panel(self, id = wx.ID_ANY)
self.SetIcon(wx.Icon(os.path.join(globalvar.ETCICONDIR, 'grass.ico'), wx.BITMAP_TYPE_ICO))
Modified: grass/trunk/gui/wxpython/location_wizard/wizard.py
===================================================================
--- grass/trunk/gui/wxpython/location_wizard/wizard.py 2012-08-23 16:05:42 UTC (rev 52859)
+++ grass/trunk/gui/wxpython/location_wizard/wizard.py 2012-08-23 16:08:19 UTC (rev 52860)
@@ -43,7 +43,7 @@
from core.gcmd import RunCommand, GError, GMessage, GWarning
from gui_core.ghelp import HelpFrame
from location_wizard.base import BaseClass
-from location_wizard.dialogs import RegionDef, SelectTransformDialog
+from location_wizard.dialogs import SelectTransformDialog
from grass.script import core as grass
@@ -1758,7 +1758,10 @@
#
self.datumtrans = None
self.proj4string = ''
-
+
+ # file from which new location is created
+ self.georeffile = None
+
#
# define wizard pages
#
@@ -1846,21 +1849,11 @@
if not msg:
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.NO_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()
+ self.grassdatabase = self.startpage.grassdatabase
+ self.georeffile = self.filepage.georeffile
+ # FIXME here was code for setting default region, what for is this if:
+ # if self.altdb == False:
+
else: # -> error
self.wizard.Destroy()
GError(parent = self.parent,
More information about the grass-commit
mailing list