Refactored validated input widgets to be more extensible #42
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR refactors validated input widgets to a more object-oriented system that makes them easier to extend and change. Fixes #41.
To add a new input widget, the user should create a subclass of
BaseInputWidget
which has one method and three class attributes defined:and then register the widget and its relevant type in the
class_widgets
dictionary in a newget_validated_input
function. This will produce an input widget which has methodseditor
for its editor,get_data
for its data getter,set_data
for its data setter andedited_signal
for its change signal as before.Accessing the validated input widgets is almost the same: we just change
widget = ValidatedInputWidget(field_info)
towidget = get_validated_input(field_info)
.This means that the creation of editors is more encapsulated for each type, rather than the previous system of "just get the type of widget from the data type and then use this big if/elif/elif... block to sort out the relevant validation"