[GRASS-SVN] r61024 - in grass/branches/releasebranch_7_0/gui/wxpython: core iscatt mapwin

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Jun 28 06:24:01 PDT 2014


Author: martinl
Date: 2014-06-28 06:24:01 -0700 (Sat, 28 Jun 2014)
New Revision: 61024

Added:
   grass/branches/releasebranch_7_0/gui/wxpython/core/gthread.py
Modified:
   grass/branches/releasebranch_7_0/gui/wxpython/iscatt/controllers.py
   grass/branches/releasebranch_7_0/gui/wxpython/mapwin/buffered.py
Log:
wxGUI: move gThread to core package
       (merge r60864 from trunk)


Copied: grass/branches/releasebranch_7_0/gui/wxpython/core/gthread.py (from rev 60864, grass/trunk/gui/wxpython/core/gthread.py)
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/core/gthread.py	                        (rev 0)
+++ grass/branches/releasebranch_7_0/gui/wxpython/core/gthread.py	2014-06-28 13:24:01 UTC (rev 61024)
@@ -0,0 +1,120 @@
+"""
+ at package core.gthread
+
+ at brief Threading
+
+Classes:
+ - gthread::gThread
+
+(C) 2013-2014 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 Stepan Turek <stepan.turek seznam.cz> (mentor: Martin Landa)
+"""
+
+import threading
+import time
+
+import wx
+
+import Queue
+
+from core.gconsole import EVT_CMD_DONE, wxCmdDone
+
+class gThread(threading.Thread, wx.EvtHandler):
+    """Thread for various backends"""
+    requestId = 0
+
+    def __init__(self, requestQ=None, resultQ=None, **kwds):
+        wx.EvtHandler.__init__(self)
+        self.terminate = False
+
+        threading.Thread.__init__(self, **kwds)
+
+        if requestQ is None:
+            self.requestQ = Queue.Queue()
+        else:
+            self.requestQ = requestQ
+
+        if resultQ is None:
+            self.resultQ = Queue.Queue()
+        else:
+            self.resultQ = resultQ
+
+        self.setDaemon(True)
+
+        self.Bind(EVT_CMD_DONE, self.OnDone)
+        self.start()
+
+    def Run(self, *args, **kwds):
+        """Run command in queue
+
+        :param args: unnamed command arguments
+        :param kwds: named command arguments, keyword 'callable'
+                     represents function to be run, keyword 'ondone'
+                     represents function to be called after the
+                     callable is done
+
+        :return: request id in queue
+        """
+        gThread.requestId += 1
+        self.requestQ.put((gThread.requestId, args, kwds))
+
+        return gThread.requestId
+
+    def GetId(self):
+         """Get id for next command"""
+         return gThread.requestId + 1
+
+    def SetId(self, id):
+        """Set starting id"""
+        gThread.requestId = id
+
+    def run(self):
+        while True:
+            requestId, args, kwds = self.requestQ.get()
+            for key in ('callable', 'ondone', 'userdata'):
+                if key in kwds:
+                    vars()[key] = kwds[key]
+                    del kwds[key]
+                else:
+                    vars()[key] = None
+
+            requestTime = time.time()
+
+            ret = None
+            exception = None
+            time.sleep(.01)
+
+            if self.terminate:
+                return
+
+            ret = vars()['callable'](*args, **kwds)
+
+            if self.terminate:
+                return
+            #except Exception as e:
+            #    exception  = e;
+
+            self.resultQ.put((requestId, ret))
+
+            event = wxCmdDone(ondone=vars()['ondone'],
+                              kwds=kwds,
+                              args=args, #TODO expand args to kwds
+                              ret=ret,
+                              exception=exception,
+                              userdata=vars()['userdata'],
+                              pid=requestId)
+
+            # send event
+            wx.PostEvent(self, event)
+
+    def OnDone(self, event):
+        if event.ondone:
+            event.ondone(event)
+
+    def Terminate(self):
+        """Abort command(s)"""
+        self.terminate = True

Modified: grass/branches/releasebranch_7_0/gui/wxpython/iscatt/controllers.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/iscatt/controllers.py	2014-06-28 09:07:24 UTC (rev 61023)
+++ grass/branches/releasebranch_7_0/gui/wxpython/iscatt/controllers.py	2014-06-28 13:24:01 UTC (rev 61024)
@@ -11,7 +11,6 @@
  - controllers::IClassDigitConnection
  - controllers::IMapDispConnection
  - controllers::IClassConnection
- - controllers::gThread
 
 (C) 2013 by the GRASS Development Team
 
@@ -25,21 +24,18 @@
 from copy import deepcopy
 import wx
 
-import time
-import threading
-import Queue
-from core.gconsole import EVT_CMD_DONE
 
+
 from core.gcmd import GException, GError, GMessage, RunCommand, GWarning
 from core.settings import UserSettings
-from core.gconsole import wxCmdRun, wxCmdDone, wxCmdPrepare
+from core.gthread import gThread
 from iscatt.iscatt_core import Core, idBandsToidScatt, GetRasterInfo, GetRegion, \
 MAX_SCATT_SIZE, WARN_SCATT_SIZE, MAX_NCELLS, WARN_NCELLS
 from iscatt.dialogs import AddScattPlotDialog, ExportCategoryRaster
-
 from iclass.dialogs import IClassGroupDialog
 
 import grass.script as grass
+
 from grass.pydispatch.signal import Signal
 
 class ScattsManager:
@@ -1110,101 +1106,3 @@
         if res.split('\n')[0]:
             bands = res.split('\n')
             self.scatt_mgr.SetBands(bands)
-
-
-#TODO it uses also BufferedMapWindow class -> move to core?
-class gThread(threading.Thread, wx.EvtHandler):
-    """!Thread for scatter plot backend"""
-    requestId = 0
-
-    def __init__(self, requestQ=None, resultQ=None, **kwds):
-        wx.EvtHandler.__init__(self)
-        self.terminate = False
-
-        threading.Thread.__init__(self, **kwds)
-
-        if requestQ is None:
-            self.requestQ = Queue.Queue()
-        else:
-            self.requestQ = requestQ
-
-        if resultQ is None:
-            self.resultQ = Queue.Queue()
-        else:
-            self.resultQ = resultQ
-
-        self.setDaemon(True)
-
-        self.Bind(EVT_CMD_DONE, self.OnDone)
-        self.start()
-
-    def Run(self, *args, **kwds):
-        """!Run command in queue
-
-        @param args unnamed command arguments
-        @param kwds named command arguments,
-               keyword 'callable' represents function to be run,
-               keyword 'ondone' represents function to be 
-                       called after the callable is done
-
-        @return request id in queue
-        """
-        gThread.requestId += 1
-        self.requestQ.put((gThread.requestId, args, kwds))
-
-        return gThread.requestId
-
-    def GetId(self):
-         """!Get id for next command"""
-         return gThread.requestId + 1
-
-    def SetId(self, id):
-        """!Set starting id"""
-        gThread.requestId = id
-
-    def run(self):
-        while True:
-            requestId, args, kwds = self.requestQ.get()
-            for key in ('callable', 'ondone', 'userdata'):
-                if key in kwds:
-                    vars()[key] = kwds[key]
-                    del kwds[key]
-                else:
-                    vars()[key] = None
-
-            requestTime = time.time()
-
-            ret = None
-            exception = None
-            time.sleep(.01)
-
-            if self.terminate:
-                return
-
-            ret = vars()['callable'](*args, **kwds)
-
-            if self.terminate:
-                return
-            #except Exception as e:
-            #    exception  = e;
-
-            self.resultQ.put((requestId, ret))
-
-            event = wxCmdDone(ondone=vars()['ondone'],
-                              kwds=kwds,
-                              args=args, #TODO expand args to kwds
-                              ret=ret,
-                              exception=exception,
-                              userdata=vars()['userdata'],
-                              pid=requestId)
-
-            # send event
-            wx.PostEvent(self, event)
-
-    def OnDone(self, event):
-        if event.ondone:
-            event.ondone(event)
-
-    def Terminate(self):
-        """!Abort command(s)"""
-        self.terminate = True

Modified: grass/branches/releasebranch_7_0/gui/wxpython/mapwin/buffered.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/mapwin/buffered.py	2014-06-28 09:07:24 UTC (rev 61023)
+++ grass/branches/releasebranch_7_0/gui/wxpython/mapwin/buffered.py	2014-06-28 13:24:01 UTC (rev 61024)
@@ -41,7 +41,7 @@
 from core.utils         import GetGEventAttribsForHandler, _
 import core.utils as utils
 from mapwin.graphics import GraphicsSet
-from iscatt.controllers import gThread
+from core.gthread import gThread
 
 try:
     import grass.lib.gis as gislib



More information about the grass-commit mailing list