-
-
Notifications
You must be signed in to change notification settings - Fork 369
GUI: Included Mapvalidator in forms.py to check valid raster output names #6433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
gui/wxpython/gui_core/forms.py
Outdated
for p in self.task.params: | ||
if p.get("age", "") == "new" and p.get("prompt", "") in ( | ||
"raster", | ||
"raster_3d" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[ruff] reported by reviewdog 🐶
"raster_3d" | |
"raster_3d", |
gui/wxpython/gui_core/forms.py
Outdated
valid = validator.Validate(textWin) | ||
except Exception: | ||
valid = True | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[ruff] reported by reviewdog 🐶
gui/wxpython/gui_core/forms.py
Outdated
valid = True | ||
|
||
# Return to first notebook page so user can fix output map name | ||
self.notebookpanel.notebook.SetSelection(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[ruff] reported by reviewdog 🐶
self.notebookpanel.notebook.SetSelection(0) | |
self.notebookpanel.notebook.SetSelection(0) |
gui/wxpython/gui_core/forms.py
Outdated
#Attach MapValidator to gselect.Select | ||
if p.get("age","") == "new": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[ruff] reported by reviewdog 🐶
#Attach MapValidator to gselect.Select | |
if p.get("age","") == "new": | |
# Attach MapValidator to gselect.Select | |
if p.get("age", "") == "new": |
gui/wxpython/gui_core/forms.py
Outdated
"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())), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[ruff] reported by reviewdog 🐶
"values": list(utils.str2rgb.keys()) + list(map(str, utils.str2rgb.values())), | |
"values": list(utils.str2rgb.keys()) | |
+ list(map(str, utils.str2rgb.values())), |
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 |
…nd adding validator member to g.select.Select in forms.py
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.