Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 31 additions & 11 deletions gui/wxpython/history/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
@author Tomas Zigo
"""

import math
from datetime import datetime

import wx
Expand All @@ -25,7 +26,7 @@
from history.tree import HistoryBrowserTree
from icons.icon import MetaIcon

import grass.script as gs
from grass.tools import Tools

from grass.grassdb import history

Expand All @@ -40,10 +41,10 @@
"status": _("Status:"),
"mask2d": _("Mask 2D:"),
"mask3d": _("Mask 3D:"),
"n": _("North:"),
"s": _("South:"),
"w": _("West:"),
"e": _("East:"),
"north": _("North:"),
"south": _("South:"),
"west": _("West:"),
"east": _("East:"),
"nsres": _("North-south resolution:"),
"ewres": _("East-west resolution:"),
"rows": _("Number of rows:"),
Expand All @@ -69,13 +70,26 @@ def make_label(key):
return TRANSLATION_KEYS.get(key, "")


# Region keys in the shell format of g.region, which are also the names of the g.region parameters
REGION_KEYS = {"n": "north", "s": "south", "w": "west", "e": "east"}


def normalize_region(region):
"""Return region settings with the keys used by g.region format=json.

History entries recorded by older versions use the keys of the shell format.
"""
return {REGION_KEYS.get(key, key): value for key, value in region.items()}


class HistoryInfoPanel(SP.ScrolledPanel):
def __init__(self, parent, giface, title=("Command Info"), style=wx.TAB_TRAVERSAL):
super().__init__(parent=parent, id=wx.ID_ANY, style=style)

self.parent = parent
self.giface = giface
self.title = title
self.tools = Tools()

self.region_settings = None

Expand Down Expand Up @@ -166,7 +180,7 @@ def _general_info_filter(self, key, value):
return key in filter_keys or ((key in {"mask2d", "mask3d"}) and value is True)

def _region_settings_filter(self, key):
return key not in {"projection", "zone", "cells"}
return key not in {"crs", "projection", "zone", "cells"}

def _updateGeneralInfoBox(self, command_info):
"""Update a static box for displaying general info about the command.
Expand Down Expand Up @@ -213,7 +227,7 @@ def _updateRegionSettingsGrid(self, command_info):
"""
self.sizer_region_settings_grid.Clear(True)

self.region_settings = command_info["region"]
self.region_settings = normalize_region(command_info["region"])
idx = 0
for key, value in self.region_settings.items():
if self._region_settings_filter(key):
Expand Down Expand Up @@ -248,9 +262,12 @@ def _updateRegionSettingsMatch(self):
self.sizer_region_settings_match.Clear(True)

# Region condition
history_region = self.region_settings
history_region = self._get_history_region()
current_region = self._get_current_region()
region_matches = history_region == current_region
region_matches = all(
math.isclose(value, current_region[key], rel_tol=0, abs_tol=1e-8)
for key, value in history_region.items()
)

# Icon and button according to the condition
if region_matches:
Expand Down Expand Up @@ -320,7 +337,7 @@ def hideCommandInfo(self):

def _get_current_region(self):
"""Get current computational region settings."""
return gs.region()
return self.tools.g_region(flags="p", format="json").json

def _get_history_region(self):
"""Get computational region settings of executed command."""
Expand All @@ -332,8 +349,11 @@ def _get_history_region(self):

def OnUpdateRegion(self, event):
"""Set current region to the region of executed command."""
parameters = {value: key for key, value in REGION_KEYS.items()}
history_region = self._get_history_region()
gs.run_command("g.region", **history_region)
self.tools.g_region(
**{parameters.get(key, key): value for key, value in history_region.items()}
)
self.giface.updateMap.emit(render=False, renderVector=False)
self._updateRegionSettingsMatch()
self.Layout()
Expand Down
4 changes: 3 additions & 1 deletion python/grass/grassdb/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,9 @@ def get_initial_command_info(env_run):
mask3d_name = f"RASTER3D_MASK@{env['MAPSET']}"

# Computational region settings
region_settings = gs.region(env=env_run)
region_settings = gs.parse_command(
"g.region", flags="p", format="json", env=env_run
)

# Finalize the command info dictionary
return {
Expand Down
Loading