[GRASS-SVN] r72301 - grass/trunk/gui/wxpython/gmodeler

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Mar 2 13:19:55 PST 2018


Author: martinl
Date: 2018-03-02 13:19:55 -0800 (Fri, 02 Mar 2018)
New Revision: 72301

Modified:
   grass/trunk/gui/wxpython/gmodeler/frame.py
   grass/trunk/gui/wxpython/gmodeler/model.py
Log:
wxGUI/gmodeler: print model computation finished message

Modified: grass/trunk/gui/wxpython/gmodeler/frame.py
===================================================================
--- grass/trunk/gui/wxpython/gmodeler/frame.py	2018-03-02 20:52:36 UTC (rev 72300)
+++ grass/trunk/gui/wxpython/gmodeler/frame.py	2018-03-02 21:19:55 UTC (rev 72301)
@@ -38,7 +38,8 @@
         import wx.lib.agw.flatnotebook as FN
 else:
     import wx.lib.flatnotebook as FN
-
+from wx.lib.newevent import NewEvent
+    
 from core.utils import _
 from gui_core.widgets import GNotebook
 from core.gconsole        import GConsole, \
@@ -61,6 +62,8 @@
 from gmodeler.model import *
 from gmodeler.dialogs import *
 
+wxModelDone, EVT_MODEL_DONE = NewEvent()
+
 from grass.script.utils import try_remove
 from grass.script import core as grass
 
@@ -148,7 +151,8 @@
         # rewrite default method to avoid hiding progress bar
         self._gconsole.Bind(EVT_CMD_DONE, self.OnCmdDone)
         self.Bind(EVT_CMD_PREPARE, self.OnCmdPrepare)
-
+        self.Bind(EVT_MODEL_DONE, self.OnDone)
+        
         self.notebook.AddPage(page=self.canvas, text=_('Model'), name='model')
         self.notebook.AddPage(
             page=self.itemPanel,
@@ -288,27 +292,37 @@
 
     def OnCmdDone(self, event):
         """Command done (or aborted)"""
-        self.goutput.GetProgressBar().SetValue(0)
+        def time_elapsed(etime):
+            try:
+                ctime = time.time() - etime
+                if ctime < 60:
+                    stime = _("%d sec") % int(ctime)
+                else:
+                    mtime = int(ctime / 60)
+                    stime = _("%(min)d min %(sec)d sec") % {
+                        'min': mtime, 'sec': int(ctime - (mtime * 60))}
+            except KeyError:
+                # stopped deamon
+                stime = _("unknown")
 
-        try:
-            ctime = time.time() - event.time
-            if ctime < 60:
-                stime = _("%d sec") % int(ctime)
-            else:
-                mtime = int(ctime / 60)
-                stime = _("%(min)d min %(sec)d sec") % {
-                    'min': mtime, 'sec': int(ctime - (mtime * 60))}
-        except KeyError:
-            # stopped deamon
-            stime = _("unknown")
+            return stime
+        
+        self.goutput.GetProgressBar().SetValue(0)            
+        self.goutput.WriteCmdLog('({}) {} ({})'.format(
+            str(time.ctime()), _("Command finished"), time_elapsed(event.time)),
+            notification=event.notification)
 
-        self.goutput.WriteCmdLog('({}) {} ({})'.format(str(time.ctime()), _("Command finished"), stime),
-                                 notification=event.notification)
-
         try:
             action = self.GetModel().GetItems()[event.pid]
             if hasattr(action, "task"):
                 action.Update(running=True)
+            if event.pid == self._gconsole.cmdThread.GetId() - 1:
+                self.goutput.WriteCmdLog('({}) {} ({})'.format(
+                    str(time.ctime()), _("Model computation finished"), time_elapsed(self.start_time)),
+                                         notification=event.notification)
+                event = wxModelDone()
+                wx.PostEvent(self, event)
+                
         except IndexError:
             pass
 
@@ -596,13 +610,11 @@
 
     def OnRunModel(self, event):
         """Run entire model"""
+        self.start_time = time.time()
         self.model.Run(self._gconsole, self.OnDone, parent=self)
 
     def OnDone(self, event):
         """Computation finished
-
-        .. todo::
-            not called -- must be fixed
         """
         self.SetStatusText('', 0)
         # restore original files

Modified: grass/trunk/gui/wxpython/gmodeler/model.py
===================================================================
--- grass/trunk/gui/wxpython/gmodeler/model.py	2018-03-02 20:52:36 UTC (rev 72300)
+++ grass/trunk/gui/wxpython/gmodeler/model.py	2018-03-02 21:19:55 UTC (rev 72301)
@@ -569,7 +569,7 @@
     def OnPrepare(self, item, params):
         self._substituteFile(item, params, checkOnly=False)
 
-    def RunAction(self, item, params, log, onDone,
+    def RunAction(self, item, params, log, onDone=None,
                   onPrepare=None, statusbar=None):
         """Run given action
 
@@ -683,7 +683,7 @@
             if isinstance(item, ModelAction):
                 if item.GetBlockId():
                     continue
-                self.RunAction(item, params, log, onDone)
+                self.RunAction(item, params, log)
             elif isinstance(item, ModelLoop):
                 cond = item.GetLabel()
 
@@ -743,7 +743,7 @@
                         varDict['value'] = var
 
                         self.RunAction(item=action, params=params,
-                                       log=log, onDone=onDone)
+                                       log=log)
                 params['variables']['params'].remove(varDict)
 
         if delInterData:



More information about the grass-commit mailing list