rgonzalez72/pytrainer — comment on commit 4234291653c4447c5cae56a45c1844f93798eb37
File:  line 0
By ncjones:

Yes, a class hierachy is the OO alternative to a type code.

For each field that needs to be validated you can just instantiate the appropriate type of validator. The validator can probably be made capable of generating sensible localised error messages.

My thoughts on a custom widget were to create a new abstract subclass of gkt.Widget which wraps another widget and provides validation state and validation events. Then there will be very minimal wiring together for the UI - there just needs to be the same validation state change listener added to each widget which will add or remove an error message from the UI. As you point out though, either there will need to be multiple error messages displayed at a time or, while errors still exist, previous error messages need to be restored after errors are resolved so this approach requires a bit more thought. Maybe the validation state change handler needs to iterate over all known inputs and revalidate them when one of the inputs validation state returns to "valid". The Eclipse IDE presents input validation messages in this way (one message per screen, updated as you type, relevant to the earliest invalid field on the screen) so it could be worthwhile looking at the source code to see what pattern is used there.

Whether we use custom widgets or not though there will still need to be the string input validation type hierarchy so I suggest going ahead with that and seeing how it looks.