[GRASS-SVN] r65948 - in grass/branches/releasebranch_7_0/gui/wxpython: core gmodeler gui_core lmgr modules vnet
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Aug 17 19:43:07 PDT 2015
Author: annakrat
Date: 2015-08-17 19:43:07 -0700 (Mon, 17 Aug 2015)
New Revision: 65948
Modified:
grass/branches/releasebranch_7_0/gui/wxpython/core/gconsole.py
grass/branches/releasebranch_7_0/gui/wxpython/gmodeler/frame.py
grass/branches/releasebranch_7_0/gui/wxpython/gui_core/dialogs.py
grass/branches/releasebranch_7_0/gui/wxpython/gui_core/forms.py
grass/branches/releasebranch_7_0/gui/wxpython/lmgr/frame.py
grass/branches/releasebranch_7_0/gui/wxpython/modules/extensions.py
grass/branches/releasebranch_7_0/gui/wxpython/modules/mcalc_builder.py
grass/branches/releasebranch_7_0/gui/wxpython/modules/vclean.py
grass/branches/releasebranch_7_0/gui/wxpython/vnet/vnet_core.py
Log:
wxGUI: fix GDALImport dialog to add multiple imported layers to layer manager; update onDone methods to pass event as argument (merge from trunk, r64372 and r64373)
Modified: grass/branches/releasebranch_7_0/gui/wxpython/core/gconsole.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/core/gconsole.py 2015-08-17 11:47:30 UTC (rev 65947)
+++ grass/branches/releasebranch_7_0/gui/wxpython/core/gconsole.py 2015-08-18 02:43:07 UTC (rev 65948)
@@ -457,7 +457,6 @@
if command[0] in globalvar.grassCmd:
# send GRASS command without arguments to GUI command interface
# except ignored commands (event is emitted)
-
if self._ignoredCmdPattern and \
re.compile(self._ignoredCmdPattern).search(' '.join(command)) and \
'--help' not in command and '--ui' not in command:
@@ -628,7 +627,7 @@
notification=event.notification)
if event.onDone:
- event.onDone(cmd=event.cmd, returncode=event.returncode)
+ event.onDone(event)
self.cmdOutputTimer.Stop()
@@ -670,7 +669,8 @@
for lname in lnames:
if '@' not in lname:
lname += '@' + grass.gisenv()['MAPSET']
- self.mapCreated.emit(name=lname, ltype=prompt)
+ if grass.find_file(lname, element=p.get('element'))['fullname']:
+ self.mapCreated.emit(name=lname, ltype=prompt)
if name == 'r.mask':
self.updateMap.emit()
Modified: grass/branches/releasebranch_7_0/gui/wxpython/gmodeler/frame.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/gmodeler/frame.py 2015-08-17 11:47:30 UTC (rev 65947)
+++ grass/branches/releasebranch_7_0/gui/wxpython/gmodeler/frame.py 2015-08-18 02:43:07 UTC (rev 65948)
@@ -503,7 +503,7 @@
"""Run entire model"""
self.model.Run(self._gconsole, self.OnDone, parent = self)
- def OnDone(self, cmd, returncode):
+ def OnDone(self, event):
"""Computation finished
.. todo::
@@ -1728,7 +1728,7 @@
event.Skip()
- def OnDone(self, cmd, returncode):
+ def OnDone(self, event):
"""Python script finished"""
try_remove(self.filename)
self.filename = None
Modified: grass/branches/releasebranch_7_0/gui/wxpython/gui_core/dialogs.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/gui_core/dialogs.py 2015-08-17 11:47:30 UTC (rev 65947)
+++ grass/branches/releasebranch_7_0/gui/wxpython/gui_core/dialogs.py 2015-08-18 02:43:07 UTC (rev 65948)
@@ -22,7 +22,7 @@
- :class:`SqlQueryFrame`
- :class:`SymbolDialog`
-(C) 2008-2011 by the GRASS Development Team
+(C) 2008-2015 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.
@@ -46,7 +46,7 @@
from grass.pydispatch.signal import Signal
from core import globalvar
-from core.gcmd import GError, RunCommand, GMessage
+from core.gcmd import GError, RunCommand, GMessage, GWarning
from gui_core.gselect import LocationSelect, MapsetSelect, Select, \
OgrTypeSelect, GdalSelect, MapsetSelect, \
SubGroupSelect
@@ -1695,7 +1695,7 @@
self.btn_run.Bind(wx.EVT_BUTTON, self.OnRun)
self.Bind(wx.EVT_CLOSE, lambda evt: self.Destroy())
-
+
def doLayout(self):
"""Do layout"""
dialogSizer = wx.BoxSizer(wx.VERTICAL)
@@ -1786,7 +1786,7 @@
"""Import/Link data (each layes as separate vector map)"""
pass
- def AddLayers(self, returncode, cmd = None):
+ def AddLayers(self, returncode, cmd = None, userData = None):
"""Add imported/linked layers into layer tree"""
if not self.add.IsChecked() or returncode != 0:
return
@@ -1808,14 +1808,32 @@
# connect to this signal
llist = self._giface.GetLayerList()
if self.importType == 'gdal':
- cmd = ['d.rast',
- 'map=%s' % name]
+ if userData:
+ nBands = int(userData.get('nbands', 1))
+ else:
+ nBands = 1
+
if UserSettings.Get(group = 'rasterLayer', key = 'opaque', subkey = 'enabled'):
- cmd.append('-n')
-
- llist.AddLayer(ltype='raster',
- name=name, checked=True,
- cmd=cmd)
+ nFlag = True
+ else:
+ nFlag = False
+
+ for i in range(1, nBands+1):
+ nameOrig = name
+ if nBands > 1:
+ mapName, mapsetName = name.split('@')
+ mapName += '.%d' % i
+ name = mapName + '@' + mapsetName
+
+ cmd = ['d.rast',
+ 'map=%s' % name]
+ if nFlag:
+ cmd.append('-n')
+
+ llist.AddLayer(ltype='raster',
+ name=name, checked=True,
+ cmd=cmd)
+ name = nameOrig
else:
llist.AddLayer(ltype='vector',
name=name, checked=True,
@@ -1832,7 +1850,7 @@
"""
pass
- def OnCmdDone(self, cmd, returncode):
+ def OnCmdDone(self, event):
"""Do what has to be done after importing"""
pass
@@ -1869,13 +1887,10 @@
ogr = ogr, link = link)
self.dsnInput.reloadDataRequired.connect(lambda data: self.list.LoadData(data))
- mightNotWork = _("this might not work for multiple bands")
if link:
- self.add.SetLabel(_("Add linked layers into layer tree"
- " ({mightNotWork})".format(mightNotWork=mightNotWork)))
+ self.add.SetLabel(_("Add linked layers into layer tree"))
else:
- self.add.SetLabel(_("Add imported layers into layer tree"
- " ({mightNotWork})".format(mightNotWork=mightNotWork)))
+ self.add.SetLabel(_("Add imported layers into layer tree"))
self.add.SetValue(UserSettings.Get(group = 'cmd', key = 'addNewLayer', subkey = 'enabled'))
@@ -1885,7 +1900,7 @@
else:
self.btn_run.SetLabel(_("&Import"))
self.btn_run.SetToolTipString(_("Import selected layers"))
-
+
self.doLayout()
def OnRun(self, event):
@@ -1910,6 +1925,7 @@
os.environ['GRASS_VECTOR_OGR'] = '1'
for layer, output in data:
+ userData = {}
if self.importType == 'ogr':
if ext and layer.rfind(ext) > -1:
layer = layer.replace('.' + ext, '')
@@ -1934,7 +1950,23 @@
idsn = os.path.join(dsn, layer)
else:
idsn = dsn
-
+
+ # check number of bands
+ nBandsStr = RunCommand('r.in.gdal',
+ flags = 'p',
+ input = idsn, read = True)
+ nBands = -1
+ if nBandsStr:
+ try:
+ nBands = int(nBandsStr.rstrip('\n'))
+ except:
+ pass
+ if nBands < 0:
+ GWarning(_("Unable to determine number of raster bands"),
+ parent = self)
+ nBands = 1
+
+ userData['nbands'] = nBands
if self.link:
cmd = ['r.external',
'input=%s' % idsn,
@@ -1943,6 +1975,8 @@
cmd = ['r.in.gdal',
'input=%s' % idsn,
'output=%s' % output]
+ if nBands > 1:
+ cmd.append('-k')
if self.overwrite.IsChecked():
cmd.append('--overwrite')
@@ -1960,19 +1994,19 @@
cmd.append('--overwrite')
# run in Layer Manager
- self._giface.RunCmd(cmd, onDone=self.OnCmdDone)
+ self._giface.RunCmd(cmd, onDone = self.OnCmdDone, userData = userData)
- def OnCmdDone(self, cmd, returncode):
+ def OnCmdDone(self, event):
"""Load layers and close if required"""
if not hasattr(self, 'AddLayers'):
return
- self.AddLayers(cmd, returncode)
+ self.AddLayers(event.returncode, event.cmd, event.userData)
if self.popOGR:
os.environ.pop('GRASS_VECTOR_OGR')
- if returncode == 0 and self.closeOnFinish.IsChecked():
+ if event.returncode == 0 and self.closeOnFinish.IsChecked():
self.Close()
def _getCommand(self):
@@ -2132,12 +2166,12 @@
# run in Layer Manager
self._giface.RunCmd(cmd, onDone=self.OnCmdDone)
- def OnCmdDone(self, cmd, returncode):
+ def OnCmdDone(self, event):
"""Load layers and close if required"""
if not hasattr(self, 'AddLayers'):
return
- self.AddLayers(cmd, returncode)
+ self.AddLayers(event.returncode, event.cmd)
if self.closeOnFinish.IsChecked():
self.Close()
Modified: grass/branches/releasebranch_7_0/gui/wxpython/gui_core/forms.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/gui_core/forms.py 2015-08-17 11:47:30 UTC (rev 65947)
+++ grass/branches/releasebranch_7_0/gui/wxpython/gui_core/forms.py 2015-08-18 02:43:07 UTC (rev 65948)
@@ -629,13 +629,10 @@
if event:
event.Skip()
- def OnDone(self, cmd, returncode):
+ def OnDone(self, event):
"""This function is launched from OnRun() when command is
finished
-
- :param returncode: command's return code (0 for success)
"""
-
if hasattr(self, "btn_cancel"):
self.btn_cancel.Enable(True)
@@ -652,7 +649,7 @@
self.get_dcmd is None and \
hasattr(self, "closebox") and \
self.closebox.IsChecked() and \
- (returncode == 0):
+ (event.returncode == 0):
# was closed also when aborted but better is leave it open
wx.FutureCall(2000, self.Close)
Modified: grass/branches/releasebranch_7_0/gui/wxpython/lmgr/frame.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/lmgr/frame.py 2015-08-17 11:47:30 UTC (rev 65947)
+++ grass/branches/releasebranch_7_0/gui/wxpython/lmgr/frame.py 2015-08-18 02:43:07 UTC (rev 65948)
@@ -490,7 +490,7 @@
win.Show()
- def OnDone(self, cmd, returncode):
+ def OnDone(self, event):
"""Command execution finished"""
if hasattr(self, "model"):
self.model.DeleteIntermediateData(log = self._gconsole)
Modified: grass/branches/releasebranch_7_0/gui/wxpython/modules/extensions.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/modules/extensions.py 2015-08-17 11:47:30 UTC (rev 65947)
+++ grass/branches/releasebranch_7_0/gui/wxpython/modules/extensions.py 2015-08-18 02:43:07 UTC (rev 65948)
@@ -231,8 +231,8 @@
if cmd:
log.RunCmd(cmd, onDone = self.OnDone)
- def OnDone(self, cmd, returncode):
- if returncode == 0:
+ def OnDone(self, event):
+ if event.returncode == 0:
if not os.getenv('GRASS_ADDON_BASE'):
SetAddOnPath(key = 'BASE')
Modified: grass/branches/releasebranch_7_0/gui/wxpython/modules/mcalc_builder.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/modules/mcalc_builder.py 2015-08-17 11:47:30 UTC (rev 65947)
+++ grass/branches/releasebranch_7_0/gui/wxpython/modules/mcalc_builder.py 2015-08-18 02:43:07 UTC (rev 65948)
@@ -593,12 +593,12 @@
RunCommand(self.cmd,
**params)
- def OnDone(self, cmd, returncode):
+ def OnDone(self, event):
"""Add create map to the layer tree
Sends the mapCreated signal from the grass interface.
"""
- if returncode != 0:
+ if event.returncode != 0:
return
name = self.newmaptxt.GetValue().strip(' "') + '@' + grass.gisenv()['MAPSET']
ltype = 'raster'
Modified: grass/branches/releasebranch_7_0/gui/wxpython/modules/vclean.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/modules/vclean.py 2015-08-17 11:47:30 UTC (rev 65947)
+++ grass/branches/releasebranch_7_0/gui/wxpython/modules/vclean.py 2015-08-18 02:43:07 UTC (rev 65948)
@@ -440,7 +440,7 @@
else:
self.selected = -1
- def OnDone(self, cmd, returncode):
+ def OnDone(self, event):
"""Command done"""
self.SetStatusText('')
Modified: grass/branches/releasebranch_7_0/gui/wxpython/vnet/vnet_core.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/vnet/vnet_core.py 2015-08-17 11:47:30 UTC (rev 65947)
+++ grass/branches/releasebranch_7_0/gui/wxpython/vnet/vnet_core.py 2015-08-18 02:43:07 UTC (rev 65948)
@@ -282,15 +282,15 @@
return True
- def _createTtbDone(self, cmd, returncode):
+ def _createTtbDone(self, event):
- if returncode != 0:
+ if event.returncode != 0:
GMessage(parent = self.guiparent,
message = _("Creation of turntable failed."))
return
else:
params = {}
- for c in cmd:
+ for c in event.cmd:
spl_c = c.split("=")
if len(spl_c) != 2:
continue
@@ -302,7 +302,7 @@
self.vnet_data.SetParams(params, {})
- self.ttbCreated.emit(returncode = returncode)
+ self.ttbCreated.emit(returncode = event.returncode)
def SaveTmpLayer(self, layer_name):
"""Permanently saves temporary map of analysis result"""
@@ -460,24 +460,24 @@
else:
self.goutput.RunCmd(command = cmdParams, onDone = self._vnetPathRunAnDone)
- def _vnetPathRunTurnsAnDone(self, cmd, returncode):
+ def _vnetPathRunTurnsAnDone(self, event):
#TODO
#self.tmp_maps.DeleteTmpMap(self.tmpTurnAn)
- self._vnetPathRunAnDone(cmd, returncode)
+ self._vnetPathRunAnDone(event)
- def _vnetPathRunAnDone(self, cmd, returncode):
+ def _vnetPathRunAnDone(self, event):
"""Called when v.net.path analysis is done"""
try_remove(self.coordsTmpFile)
- self._onDone(cmd, returncode)
+ self._onDone(event)
- def _onDone(self, cmd, returncode):
- for c in cmd:
+ def _onDone(self, event):
+ for c in event.cmd:
if "output=" in c:
output = c.split("=")[1]
break
- self.onAnDone(cmd, returncode, output)
+ self.onAnDone(event.cmd, event.returncode, output)
def _runTurnsAn(self, analysis, output, params, flags, catPts):
@@ -585,11 +585,11 @@
try_remove(sqlFile)
- def _runTurnsAnDone(self, cmd, returncode):
+ def _runTurnsAnDone(self, event):
"""Called when analysis is done"""
#self.tmp_maps.DeleteTmpMap(self.tmpTurnAn) #TODO remove earlier (OnDone lambda?)
- self._onDone(cmd, returncode)
+ self._onDone(event)
def _runAn(self, analysis, output, params, flags, catPts):
@@ -691,7 +691,7 @@
self._prepareCmd(cmdParams)
self.goutput.RunCmd(command = cmdParams, onDone = self._runAnDone)
- def _runAnDone(self, cmd, returncode):
+ def _runAnDone(self, event):
"""Called when analysis is done"""
self.tmp_maps.DeleteTmpMap(self.tmpInPts) #TODO remove earlier (OnDone lambda?)
self.tmp_maps.DeleteTmpMap(self.tmpInPtsConnected)
@@ -700,7 +700,7 @@
if cmd[0] == "v.net.flow":
self.tmp_maps.DeleteTmpMap(self.vnetFlowTmpCut)
- self._onDone(cmd, returncode)
+ self._onDone(event)
def _setInputParams(self, analysis, params, flags):
"""Return list of chosen values (vector map, layers).
More information about the grass-commit
mailing list