Skip to content

Commit

Permalink
browser updates in gconsole to avoid Running state in special cases
Browse files Browse the repository at this point in the history
  • Loading branch information
lindakladivova committed May 3, 2024
1 parent 755931f commit 0b538ea
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 22 deletions.
38 changes: 33 additions & 5 deletions gui/wxpython/core/gconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ def run(self):
returncode = self.requestCmd.module.returncode
except AttributeError:
returncode = 0 # being optimistic

try:
aborted = self.requestCmd.aborted
except AttributeError:
Expand Down Expand Up @@ -446,6 +445,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,
Expand Down Expand Up @@ -529,14 +543,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
Expand All @@ -560,6 +576,7 @@ def RunCmd(
)
% {"cmd": " ".join(command), "opt": p.get("name", "")},
)
self.UpdateHistory(status=history.STATUS_FAILED)
return

if len(command) == 1:
Expand All @@ -580,6 +597,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:
Expand All @@ -593,8 +612,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

Expand Down Expand Up @@ -636,6 +658,9 @@ def RunCmd(
):
event = gIgnoredCmdRun(cmd=command)
wx.PostEvent(self, event)

self.UpdateHistory(status=history.STATUS_FAILED)

return

skipInterface = True
Expand All @@ -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:
Expand All @@ -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,
Expand All @@ -674,6 +701,7 @@ def RunCmd(
env=env,
notification=notification,
)

self.cmdOutputTimer.Start(50)

def GetLog(self, err=False):
Expand Down Expand Up @@ -736,15 +764,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}

Expand Down
24 changes: 12 additions & 12 deletions gui/wxpython/history/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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),
),
)

Expand Down
11 changes: 6 additions & 5 deletions python/grass/grassdb/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 0b538ea

Please sign in to comment.