[GRASS-SVN] r66960 - grass/trunk/gui/wxpython/core
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Nov 28 03:27:44 PST 2015
Author: martinl
Date: 2015-11-28 03:27:44 -0800 (Sat, 28 Nov 2015)
New Revision: 66960
Modified:
grass/trunk/gui/wxpython/core/ws.py
Log:
wxGUI/wms: replace CmdThread by gThread
Modified: grass/trunk/gui/wxpython/core/ws.py
===================================================================
--- grass/trunk/gui/wxpython/core/ws.py 2015-11-28 09:50:52 UTC (rev 66959)
+++ grass/trunk/gui/wxpython/core/ws.py 2015-11-28 11:27:44 UTC (rev 66960)
@@ -9,7 +9,7 @@
- ws::RenderWMSMgr
- ws::GDALRasterMerger
-(C) 2012 by the GRASS Development Team
+(C) 2012-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.
@@ -18,18 +18,18 @@
"""
import sys
import copy
+import time
import wx
from wx.lib.newevent import NewEvent
from grass.script.utils import try_remove
-from grass.script.task import cmdtuple_to_list
from grass.script import core as grass
+from grass.exceptions import CalledModuleError
from core import utils
from core.debug import Debug
-
-from core.gconsole import CmdThread, GStderr, EVT_CMD_DONE, EVT_CMD_OUTPUT
+from core.gthread import gThread
from core.utils import _
try:
@@ -45,7 +45,7 @@
class RenderWMSMgr(wx.EvtHandler):
"""Fetch and prepare WMS data for rendering.
"""
- def __init__(self, layer, env={}):
+ def __init__(self, layer, env):
if not haveGdal:
sys.stderr.write(_("Unable to load GDAL Python bindings.\n"\
"WMS layers can not be displayed without the bindings.\n"))
@@ -55,21 +55,17 @@
wx.EvtHandler.__init__(self)
# thread for d.wms commands
- self.thread = CmdThread(self)
- self.Bind(EVT_CMD_DONE, self.OnDataFetched)
+ self.thread = gThread()
+ self._startTime = None
self.downloading = False
self.renderedRegion = None
self.updateMap = True
self.fetched_data_cmd = None
- self.cmdStdErr = GStderr(self)
-
self.tempMap = grass.tempfile()
self.dstSize = {}
- self.Bind(EVT_CMD_OUTPUT, self.OnCmdOutput)
-
self.dataFetched = Signal('RenderWMSMgr.dataFetched')
self.updateProgress = Signal('RenderWMSMgr.updateProgress')
@@ -124,31 +120,29 @@
try_remove(self.tempMap)
self.currentPid = self.thread.GetId()
- self.thread.abort()
+ ### self.thread.Terminate()
self.downloading = True
self.fetching_cmd = cmd
- cmdList = cmdtuple_to_list(cmd)
- if Debug.GetLevel() < 3:
- cmdList.append('--quiet')
-
env["GRASS_RENDER_FILE"] = self.tempMap
env["GRASS_REGION"] = self._createRegionStr(region)
- self.thread.RunCmd(cmdList, env=env, stderr=self.cmdStdErr)
- self.updateProgress.emit(layer=self.layer)
-
- def OnCmdOutput(self, event):
- """Print cmd output according to debug level.
- """
- if Debug.GetLevel() == 0:
- if event.type == 'error':
- sys.stderr.write(event.text)
- sys.stderr.flush()
- else:
- Debug.msg(1, event.text)
+ cmd_render = copy.deepcopy(cmd)
+ cmd_render[1]['quiet'] = True # be quiet
+
+ self._startTime = time.time()
+ self.thread.Run(callable=self._render, cmd=cmd_render, env=env,
+ ondone=self.OnDataFetched)
+ self.layer.forceRender = False
+ def _render(self, cmd, env):
+ try:
+ return grass.run_command(cmd[0], env=env, **cmd[1])
+ except CalledModuleError as e:
+ grass.error(e)
+ return 1
+
def OnDataFetched(self, event):
"""Fetch data
"""
@@ -175,6 +169,9 @@
self.fetched_data_cmd = self.fetching_cmd
+ Debug.msg(1, "RenderWMSMgr.OnDataFetched(%s): ret=%d time=%f" % \
+ (self.layer, event.ret, time.time() - self._startTime))
+
self.dataFetched.emit(layer=self.layer)
def _getRegionDict(self, env):
@@ -236,11 +233,15 @@
region['n-s resol'] = region['e-w resol']
def Abort(self):
- """Abort process"""
+ """Abort rendering process"""
+ Debug.msg(1, "RenderWMSMgr({}).Abort()".format(self.layer))
+ self.thread.Terminate()
+
+ # force rendering layer next time
+ self.layer.forceRender = True
self.updateMap = False
- self.thread.abort(abortall = True)
+ self.thread.Terminate(False)
-
class GDALRasterMerger:
"""Merge rasters.
More information about the grass-commit
mailing list