-
-
Notifications
You must be signed in to change notification settings - Fork 524
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ui: restrict allowed characters in the rule name
Since the name of the rule is used for the file name on the disk, certain characters caused issues when saving the rule, like '/'. Now if the user types or pastes '/' in the name field, a warning is displayed, indicating that some characters are not allowed. (2e90f38)
- Loading branch information
1 parent
9e660e1
commit 25e9268
Showing
2 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
from PyQt5 import QtCore, QtGui | ||
|
||
class RestrictChars(QtGui.QValidator): | ||
result = QtCore.pyqtSignal(object) | ||
|
||
def __init__(self, restricted_chars, *args, **kwargs): | ||
QtGui.QValidator.__init__(self, *args, **kwargs) | ||
self._restricted_chars = restricted_chars | ||
|
||
def validate(self, value, pos): | ||
# allow to delete all characters | ||
if len(value) == 0: | ||
return QtGui.QValidator.Intermediate, value, pos | ||
|
||
# user can type characters or paste them. | ||
# pos value when pasting can be any number, depending on where did the | ||
# user paste the characters. | ||
for char in self._restricted_chars: | ||
if char in value: | ||
self.result.emit(QtGui.QValidator.Invalid) | ||
return QtGui.QValidator.Invalid, value, pos | ||
|
||
self.result.emit(QtGui.QValidator.Acceptable) | ||
return QtGui.QValidator.Acceptable, value, pos |