Skip to content

Conversation

bluedotblue
Copy link

Description

Within the GUI, creating new raster maps with a required output name does not prompt the user of invalid character use on running the module. This feature has been applied already when creating a new vector map, with the MapValidator class within widgets.py. It was asked to use this MapValidator class to handle raster output names similarly in forms.py.

This pull request addresses issue #5978.

How has this been tested?

I overwrote the installation forms.py with my version and ran the GUI to check visually.

@github-actions github-actions bot added GUI wxGUI related Python Related code is in Python labels Sep 30, 2025
for p in self.task.params:
if p.get("age", "") == "new" and p.get("prompt", "") in (
"raster",
"raster_3d"
Copy link
Contributor

Choose a reason for hiding this comment

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

[ruff] reported by reviewdog 🐶

Suggested change
"raster_3d"
"raster_3d",

valid = validator.Validate(textWin)
except Exception:
valid = True

Copy link
Contributor

Choose a reason for hiding this comment

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

[ruff] reported by reviewdog 🐶

Suggested change

valid = True

# Return to first notebook page so user can fix output map name
self.notebookpanel.notebook.SetSelection(0)
Copy link
Contributor

Choose a reason for hiding this comment

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

[ruff] reported by reviewdog 🐶

Suggested change
self.notebookpanel.notebook.SetSelection(0)
self.notebookpanel.notebook.SetSelection(0)

Comment on lines 1559 to 1560
#Attach MapValidator to gselect.Select
if p.get("age","") == "new":
Copy link
Contributor

Choose a reason for hiding this comment

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

[ruff] reported by reviewdog 🐶

Suggested change
#Attach MapValidator to gselect.Select
if p.get("age","") == "new":
# Attach MapValidator to gselect.Select
if p.get("age", "") == "new":

"multiple": "yes",
# values must be an array of strings
"values": utils.str2rgb.keys() + list(map(str, utils.str2rgb.values())),
"values": list(utils.str2rgb.keys()) + list(map(str, utils.str2rgb.values())),
Copy link
Contributor

Choose a reason for hiding this comment

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

[ruff] reported by reviewdog 🐶

Suggested change
"values": list(utils.str2rgb.keys()) + list(map(str, utils.str2rgb.values())),
"values": list(utils.str2rgb.keys())
+ list(map(str, utils.str2rgb.values())),

@petrasovaa
Copy link
Contributor

Thank you! It looks like it's preventing the dialog from running even if the name is correct.

Looking back at the linked issue, I would go with a different approach more consistent with the current usage of validators in the tool dialogs, e.g. see how r.surf.fractal dialog deals with entering some letters instead of numbers in the dimension parameter - it will highlight the field.

For that you need a slightly different validator, something like this would work (in gui_core/widgets.py):

class MapNameValidator(BaseValidator):
    """Validator for map name input"""

    def __init__(self):
        BaseValidator.__init__(self)
        
    def _validate(self, win):
        """Validate input"""
        text = win.GetValue()
        if text:
            if not grass.legal_name(text):
                self._notvalid()
                return False

        self._valid()
        return True

    def Clone(self):
        """Clone validator"""
        return MapNameValidator()

and then you just add it to

https://github.com/OSGeo/grass/blob/main/gui/wxpython/gui_core/forms.py#L1511

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

Labels

GUI wxGUI related Python Related code is in Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants