From fdabb8e0016f16d25c5f84872bdd8437cf521f9e Mon Sep 17 00:00:00 2001 From: lindakladivova Date: Fri, 3 May 2024 17:01:25 +0200 Subject: [PATCH] browser updates in gconsole to avoid Running state in special cases --- gui/wxpython/core/gconsole.py | 35 +++++++++++++++++++++++++++++---- gui/wxpython/history/tree.py | 24 +++++++++++----------- python/grass/grassdb/history.py | 11 ++++++----- 3 files changed, 49 insertions(+), 21 deletions(-) diff --git a/gui/wxpython/core/gconsole.py b/gui/wxpython/core/gconsole.py index cb26b57f0f5..41fa38a50f5 100644 --- a/gui/wxpython/core/gconsole.py +++ b/gui/wxpython/core/gconsole.py @@ -446,6 +446,21 @@ def WriteError(self, text): """Write message in error style""" self.writeError.emit(text=text) + def UpdateHistory(self, status): + """Update command history""" + cmd_info = {"status": status} + + try: + history_path = history.get_current_mapset_gui_history_path() + history.update_entry(history_path, cmd_info) + + # update history model + if self._giface: + entry = history.read(history_path)[-1] + self._giface.entryInHistoryUpdated.emit(entry=entry) + except (OSError, ValueError) as e: + GError(str(e)) + def RunCmd( self, command, @@ -529,14 +544,16 @@ def RunCmd( ): event = gIgnoredCmdRun(cmd=command) wx.PostEvent(self, event) - return + self.UpdateHistory(status=history.STATUS_FAILED) + return else: # other GRASS commands (r|v|g|...) try: task = GUI(show=None).ParseCommand(command) except GException as e: GError(parent=self._guiparent, message=str(e), showTraceback=False) + self.UpdateHistory(status=history.STATUS_FAILED) return hasParams = False @@ -560,6 +577,7 @@ def RunCmd( ) % {"cmd": " ".join(command), "opt": p.get("name", "")}, ) + self.UpdateHistory(status=history.STATUS_FAILED) return if len(command) == 1: @@ -580,6 +598,8 @@ def RunCmd( parent=self._guiparent, message=_("Module <%s> not found.") % command[0], ) + self.UpdateHistory(status=history.STATUS_FAILED) + pymodule = imp.load_source(command[0].replace(".", "_"), pyPath) pymain = inspect.getfullargspec(pymodule.main) if pymain and "giface" in pymain.args: @@ -593,8 +613,11 @@ def RunCmd( GUI( parent=self._guiparent, giface=self._giface ).ParseCommand(command) + self.UpdateHistory(status=history.STATUS_SUCCESS) + except GException as e: print(e, file=sys.stderr) + self.UpdateHistory(status=history.STATUS_FAILED) return @@ -636,6 +659,8 @@ def RunCmd( ): event = gIgnoredCmdRun(cmd=command) wx.PostEvent(self, event) + + self.UpdateHistory(status=history.STATUS_FAILED) return skipInterface = True @@ -649,6 +674,7 @@ def RunCmd( skipInterface = False break except OSError: + self.UpdateHistory(status=history.STATUS_FAILED) pass if len(command) == 1 and not skipInterface: @@ -662,6 +688,7 @@ def RunCmd( if task: # process GRASS command without argument GUI(parent=self._guiparent, giface=self._giface).ParseCommand(command) + self.UpdateHistory(status=history.STATUS_SUCCESS) else: self.cmdThread.RunCmd( command, @@ -736,15 +763,15 @@ def OnCmdDone(self, event): ) ) msg = _("Command aborted") - status = "aborted" + status = history.STATUS_ABORTED elif event.returncode != 0: msg = _("Command ended with non-zero return code {returncode}").format( returncode=event.returncode ) - status = "failed" + status = history.STATUS_FAILED else: msg = _("Command finished") - status = "success" + status = history.STATUS_SUCCESS cmd_info = {"runtime": int(ctime), "status": status} diff --git a/gui/wxpython/history/tree.py b/gui/wxpython/history/tree.py index db0424ca19b..617caa46889 100644 --- a/gui/wxpython/history/tree.py +++ b/gui/wxpython/history/tree.py @@ -116,11 +116,11 @@ def __init__( self._iconTypes = [ TIME_PERIOD, - history.status_aborted, - history.status_failed, - history.status_running, - history.status_success, - history.status_unknown, + history.STATUS_ABORTED, + history.STATUS_FAILED, + history.STATUS_RUNNING, + history.STATUS_SUCCESS, + history.STATUS_UNKNOWN, ] self._initImages() @@ -165,11 +165,11 @@ def _initImages(self): bmpsize = (16, 16) icons = { TIME_PERIOD: MetaIcon(img="time-period").GetBitmap(bmpsize), - history.status_aborted: MetaIcon(img="exclamation-mark").GetBitmap(bmpsize), - history.status_failed: MetaIcon(img="cross").GetBitmap(bmpsize), - history.status_running: MetaIcon(img="circle").GetBitmap(bmpsize), - history.status_success: MetaIcon(img="success").GetBitmap(bmpsize), - history.status_unknown: MetaIcon(img="question-mark").GetBitmap(bmpsize), + history.STATUS_ABORTED: MetaIcon(img="exclamation-mark").GetBitmap(bmpsize), + history.STATUS_FAILED: MetaIcon(img="cross").GetBitmap(bmpsize), + history.STATUS_RUNNING: MetaIcon(img="circle").GetBitmap(bmpsize), + history.STATUS_SUCCESS: MetaIcon(img="success").GetBitmap(bmpsize), + history.STATUS_UNKNOWN: MetaIcon(img="question-mark").GetBitmap(bmpsize), } il = wx.ImageList(bmpsize[0], bmpsize[1], mask=False) for each in self._iconTypes: @@ -268,7 +268,7 @@ def _initHistoryModel(self): entry["command_info"].get("status") if entry.get("command_info") and entry["command_info"].get("status") is not None - else "unknown" + else history.STATUS_UNKNOWN ) # Add command to time period node @@ -396,7 +396,7 @@ def InsertCommand(self, entry): type=COMMAND, name=entry["command"].strip(), timestamp=entry["command_info"]["timestamp"], - status=entry["command_info"].get("status", "in process"), + status=entry["command_info"].get("status", history.STATUS_UNKNOWN), ), ) diff --git a/python/grass/grassdb/history.py b/python/grass/grassdb/history.py index 60c6b32a6e6..0c8076ce167 100644 --- a/python/grass/grassdb/history.py +++ b/python/grass/grassdb/history.py @@ -19,11 +19,11 @@ # global status variables -status_aborted = _("aborted") -status_failed = _("failed") -status_running = _("running") -status_success = _("success") -status_unknown = _("unknown") +STATUS_ABORTED = _("aborted") +STATUS_FAILED = _("failed") +STATUS_RUNNING = _("running") +STATUS_SUCCESS = _("success") +STATUS_UNKNOWN = _("unknown") def get_current_mapset_gui_history_path(): @@ -286,6 +286,7 @@ def get_initial_command_info(env_run): "mask2d": mask2d_present, "mask3d": mask3d_present, "region": region_settings, + "status": STATUS_RUNNING, } return cmd_info