Skip to content
Open
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
9 changes: 8 additions & 1 deletion gui/wxpython/gui_core/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
FormListbook,
FormNotebook,
PlacementValidator,
MapNameValidator,
)
from core.giface import Notification, StandaloneGrassInterface
from gui_core.widgets import LayersList
Expand Down Expand Up @@ -1509,6 +1510,7 @@ def __init__(self, parent, giface, task, id=wx.ID_ANY, frame=None, *args, **kwar
selection = gselect.Select(
parent=which_panel,
id=wx.ID_ANY,
validator=MapNameValidator(),
size=globalvar.DIALOG_GSELECT_SIZE,
type=elem,
multiple=multiple,
Expand All @@ -1525,6 +1527,10 @@ def __init__(self, parent, giface, task, id=wx.ID_ANY, frame=None, *args, **kwar
# A gselect.Select is a combobox with two children: a textctl
# and a popupwindow; we target the textctl here
textWin = selection.GetTextCtrl()
'''# Attach MapValidator to gselect.Select
if p.get("age", "") == "new":
validator = MapValidator()
textWin.SetValidator(validator)'''
if globalvar.CheckWxVersion([3]):
p["wxId"] = [
selection.GetId(),
Expand Down Expand Up @@ -3350,7 +3356,8 @@ def OnInit(self):
"gisprompt": False,
"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())),
"key_desc": ["value"],
"values_desc": [],
},
Expand Down
25 changes: 25 additions & 0 deletions gui/wxpython/gui_core/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- widgets::EmailValidator
- widgets::TimeISOValidator
- widgets::MapValidator
- widgets::MapNameValidator
- widgets::NTCValidator
- widgets::SimpleValidator
- widgets::GenericValidator
Expand Down Expand Up @@ -889,6 +890,30 @@ def _mapNameValidationFailed(ctrl):
GenericValidator.__init__(self, grass.legal_name, _mapNameValidationFailed)


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

See G_legal_filename()
"""

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()

class GenericMultiValidator(Validator):
"""This validator checks conditions and calls callbacks
in case the condition is not fulfilled.
Expand Down