Skip to content

Commit

Permalink
wxGUI/history: Add time/status icons in front of browser nodes (#3679)
Browse files Browse the repository at this point in the history
  • Loading branch information
lindakarlovska committed May 9, 2024
1 parent 1feb86d commit fe06bd4
Show file tree
Hide file tree
Showing 17 changed files with 383 additions and 36 deletions.
Binary file added gui/icons/grass/circle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions gui/icons/grass/circle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui/icons/grass/cross.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 52 additions & 0 deletions gui/icons/grass/cross.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui/icons/grass/exclamation-mark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions gui/icons/grass/exclamation-mark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui/icons/grass/question-mark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions gui/icons/grass/question-mark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui/icons/grass/success.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions gui/icons/grass/success.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui/icons/grass/time-period.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions gui/icons/grass/time-period.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 27 additions & 15 deletions gui/wxpython/core/gconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from grass.pydispatch.signal import Signal

from grass.grassdb import history
from grass.grassdb.history import Status

from core import globalvar
from core.gcmd import CommandThread, GError, GException
Expand Down Expand Up @@ -446,6 +447,26 @@ def WriteError(self, text):
"""Write message in error style"""
self.writeError.emit(text=text)

def UpdateHistory(self, status, runtime=None):
"""Update command history.
:param enum status: status of command run
:param int runtime: duration of command run
"""
if runtime:
cmd_info = {"runtime": runtime, "status": status.value}
else:
cmd_info = {"status": status.value}
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 @@ -593,6 +614,7 @@ def RunCmd(
GUI(
parent=self._guiparent, giface=self._giface
).ParseCommand(command)
self.UpdateHistory(status=Status.SUCCESS)
except GException as e:
print(e, file=sys.stderr)

Expand Down Expand Up @@ -662,6 +684,7 @@ def RunCmd(
if task:
# process GRASS command without argument
GUI(parent=self._guiparent, giface=self._giface).ParseCommand(command)
self.UpdateHistory(status=Status.SUCCESS)
else:
self.cmdThread.RunCmd(
command,
Expand Down Expand Up @@ -736,29 +759,18 @@ def OnCmdDone(self, event):
)
)
msg = _("Command aborted")
status = "aborted"
status = Status.ABORTED
elif event.returncode != 0:
msg = _("Command ended with non-zero return code {returncode}").format(
returncode=event.returncode
)
status = "failed"
status = Status.FAILED
else:
msg = _("Command finished")
status = "success"

cmd_info = {"runtime": int(ctime), "status": status}
status = Status.SUCCESS

# update command history log by status and runtime duration
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))
self.UpdateHistory(status=status, runtime=int(ctime))

self.WriteCmdLog(
"(%s) %s (%s)" % (str(time.ctime()), msg, stime),
Expand Down
Loading

0 comments on commit fe06bd4

Please sign in to comment.