wxGUI/history: Display saved region name if stored by saket0187 · Pull Request #7095 · OSGeo/grass · GitHub
Skip to content

wxGUI/history: Display saved region name if stored#7095

Open
saket0187 wants to merge 4 commits into
OSGeo:mainfrom
saket0187:Add-region-name
Open

wxGUI/history: Display saved region name if stored#7095
saket0187 wants to merge 4 commits into
OSGeo:mainfrom
saket0187:Add-region-name

Conversation

@saket0187

@saket0187 saket0187 commented Feb 16, 2026

Copy link
Copy Markdown
Contributor

This PR adds the feature referred in #5283

Here are the outputs:

  • When it matches in MAPSET/windows
Screenshot 2026-02-16 184215
  • When it doesn't match in MAPSET/windows
Screenshot 2026-02-16 182910

Added two new methods to support region name display:

  • _get_saved_region_name(): Searches MAPSET/windows for matching saved regions
  • _compare_regions(): Compares regions with epsilon tolerance for floating-point precision

These methods are separate from the existing region match logic to avoid modifying
working functionality and keep changes minimal and isolated.
Let me know if this needs any changes.

@github-actions github-actions Bot added GUI wxGUI related Python Related code is in Python labels Feb 16, 2026

@wenzeslaus wenzeslaus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comparison needs more reasoning (epsilon, 3D, ...). Similarly, please describe behavior for the different situations.

As for the details here, user may still want to update to the named (saved) region. The GUI element alignment is wrong.

Comment thread gui/wxpython/history/browser.py Outdated
Comment thread gui/wxpython/history/browser.py Outdated
Comment thread gui/wxpython/history/browser.py Outdated
@saket0187

Copy link
Copy Markdown
Contributor Author

@wenzeslaus

Copy link
Copy Markdown
Member

Yes, you should also compare the values for 3D.

@saket0187

Copy link
Copy Markdown
Contributor Author

I know there are still some changes needed, but I wanted to check if I’m heading in the right direction or just overcomplicating things.

Currently, history.py command info provides 2D region values as far as i was able to understand. I modified it to return 3D values by using region3d=True.

I also switched to format="shell" instead of JSON because the JSON output was returning verbose keys like "north" instead of short keys like "n", which simplifies parsing.

Additionally, I added translation keys for the new 3D fields, although these can be removed if not needed.

From what I could find , when region 3D values aren’t present, they are set to defaults automatically, so converting from a 2D region to 3D will provide reasonable default values right?

Comment thread gui/wxpython/history/browser.py Outdated
Comment thread gui/wxpython/history/browser.py Outdated
Comment thread gui/wxpython/history/browser.py Outdated
Comment thread gui/wxpython/history/browser.py Outdated

@petrasovaa petrasovaa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order of the items should be 2D first and 3D at the bottom. Now the ordering follows the default g.region print order, but here it would be better to start with the 2D.

Image

@petrasovaa

Copy link
Copy Markdown
Contributor

I also switched to format="shell" instead of JSON because the JSON output was returning verbose keys like "north" instead of short keys like "n", which simplifies parsing.

Ideally we will get these unified. The idea is to use the json for everything. So the history could be using the g.region format=json for writing instead of the gs.region() function. But maybe we could skip these changes now.

@saket0187 saket0187 requested a review from petrasovaa March 19, 2026 11:44
@saket0187

Copy link
Copy Markdown
Contributor Author

@petrasovaa Can you check this? I have removed _region_settings_filter since we are not using it anymore (let me know if we still need to keep it). Other than that, it seems to work fine on my end.

@lindakarlovska

Copy link
Copy Markdown
Contributor

From testing.. : This part works only for saved regions in the current mapset, if you are in another mapset, it fails:

                    saved_region = self.tools.g_region(
                        region=region_name, flags="u3", format="shell"
                    ).keyval

_Traceback (most recent call last):
File "/home/linduska/grass/dist.x86_64-pc-linux-
gnu/gui/wxpython/gui_core/prompt.py", line 465, in
OnKeyPressed

self._runCmd(self.GetCurLine()[0].strip())
File "/home/linduska/grass/dist.x86_64-pc-linux-
gnu/gui/wxpython/gui_core/prompt.py", line 101, in _runCmd

self.promptRunCmd.emit(cmd={"cmd": cmd, "cmdString":
str(cmdString)})
File "/home/linduska/grass/dist.x86_64-pc-linux-
gnu/etc/python/grass/pydispatch/signal.py", line 230, in
emit

dispatcher.send(signal=self, *args, **kwargs)
File "/home/linduska/grass/dist.x86_64-pc-linux-
gnu/etc/python/grass/pydispatch/dispatcher.py", line 340, in
send

response = robustapply.robustApply(
File "/home/linduska/grass/dist.x86_64-pc-linux-
gnu/etc/python/grass/pydispatch/robustapply.py", line 90, in
robustApply

return receiver(*arguments, **named)
File "/home/linduska/grass/dist.x86_64-pc-linux-
gnu/gui/wxpython/gui_core/goutput.py", line 134, in

lambda cmd: self._gconsole.RunCmd(command=cmd)
File "/home/linduska/grass/dist.x86_64-pc-linux-
gnu/gui/wxpython/core/gconsole.py", line 544, in RunCmd

self._giface.entryToHistoryAdded.emit(entry=entry)
File "/home/linduska/grass/dist.x86_64-pc-linux-
gnu/etc/python/grass/pydispatch/signal.py", line 230, in
emit

dispatcher.send(signal=self, *args, **kwargs)
File "/home/linduska/grass/dist.x86_64-pc-linux-
gnu/etc/python/grass/pydispatch/dispatcher.py", line 340, in
send

response = robustapply.robustApply(
File "/home/linduska/grass/dist.x86_64-pc-linux-
gnu/etc/python/grass/pydispatch/robustapply.py", line 90, in
robustApply

return receiver(*arguments, **named)
File "/home/linduska/grass/dist.x86_64-pc-linux-
gnu/gui/wxpython/history/tree.py", line 177, in

lambda entry: self.InsertCommand(entry)
File "/home/linduska/grass/dist.x86_64-pc-linux-
gnu/gui/wxpython/history/tree.py", line 516, in
InsertCommand

self.infoPanel.showCommandInfo(command_info)
File "/home/linduska/grass/dist.x86_64-pc-linux-
gnu/gui/wxpython/history/browser.py", line 400, in
showCommandInfo

self._updateRegionSettingsMatch()
File "/home/linduska/grass/dist.x86_64-pc-linux-
gnu/gui/wxpython/history/browser.py", line 331, in
_updateRegionSettingsMatch

saved_name = self._get_saved_region_name(history_region)
File "/home/linduska/grass/dist.x86_64-pc-linux-
gnu/gui/wxpython/history/browser.py", line 299, in
_get_saved_region_name

saved_region = self.tools.g_region(
File "/home/linduska/grass/dist.x86_64-pc-linux-
gnu/etc/python/grass/tools/support.py", line 188, in wrapper

return self._run_function(tool_name, **kwargs)
File "/home/linduska/grass/dist.x86_64-pc-linux-
gnu/etc/python/grass/tools/session_tools.py", line 415, in
run

result = self._run_cmd(
File "/home/linduska/grass/dist.x86_64-pc-linux-
gnu/etc/python/grass/tools/session_tools.py", line 505, in
_run_cmd

result = self.call_cmd(
File "/home/linduska/grass/dist.x86_64-pc-linux-
gnu/etc/python/grass/tools/session_tools.py", line 591, in
call_cmd

return gs.handle_errors(
File "/home/linduska/grass/dist.x86_64-pc-linux-
gnu/etc/python/grass/script/core.py", line 470, in
handle_errors

raise exception(module, code, returncode=returncode,
errors=stderr)
grass.tools.session_tools
.
ToolError
:
Run g.region -u3 region=pokus format=shell ended with an
error (return code 1):
ERROR: Region not found_

"ewres3": _("3D east-west resolution:"),
"rows3": _("Number of 3D rows:"),
"cols3": _("Number of 3D cols:"),
"depths": _("Number of depths:"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check if you include all values for the comparison of saved and history region (I can see that e.g. 3D cells are missing)


self.region_settings = command_info["region"]

Display_Order = [

@lindakarlovska lindakarlovska Apr 24, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the Display order could be already part of the TRASLATION_KEYS that could be renamed to REGION_KEYS? Just idea - your current code has basically three different very similar variables here (TRANSLATION_KEYS, Display_Order and valid_keys) so maybe some shortening would be nice. Also what is wrong with region_settings_filter method? As we want to compare mainly numerical values from g.region, I can imagine adding ellipsoid and datum to the filter and get rid of cellls, but otherwise using this filter seems ok for me (maybe I am missing something).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello Linda, apologies for the late response. I think the reason I removed region_settings_filter was that rows3, cols3, and depths caused issues when passed to g.region through the Update current region button. Because of that, I thought we could not use the same filter for both display order and valid keys together. Maybe we can remove valid_keys and use the filter there instead, but I’m not sure how best to handle display order. Do you have a better idea?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petrasovaa any suggestions here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am open to whatever solution here if it works.

Comment on lines +287 to +288
res = self.tools.g_list(type="region", mapset="*", format="json")
region_names = [r["name"] for r in res]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likely this needs the full name including the mapset:

Suggested change
res = self.tools.g_list(type="region", mapset="*", format="json")
region_names = [r["name"] for r in res]
res = self.tools.g_list(type="region", mapset="*", flags="m", format="json")
region_names = [r["fullname"] for r in res]


if self._compare_regions(history_region, saved_region):
return region_name
except AttributeError:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Include ToolError here (from tools).


self.region_settings = command_info["region"]

Display_Order = [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is minor, but this would look better I think:

Suggested change
Display_Order = [
display_order = [

@lindakarlovska

Copy link
Copy Markdown
Contributor

I think that it would worth addressing the missing support for 3D regions in a different PR (users work mainly with 2D rasters so I would prefer showing 3D params in the history pane to be optional, and besides that we also need the backward compability - should be clear for users that history records stored before the 3D support do not have 3D params shown in the pane although they might have been important for a particular history command). I plan to open the PR with 3D support soon (but need your patience - with my newborn daughter it is a slow process 🙂) and I would suggest going back to this PR afterwards. Do you agree with that?

@lindakarlovska

Copy link
Copy Markdown
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

GUI wxGUI related libraries Python Related code is in Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants