[Go to site: main page, start]

Input Value Checking and Transfer

wxPython provides a system of "Validators" and certain controls which are aware of Validators. When available, these controls allow your system to use an approach similar to a DocumentViewArchitecture, where data is acquired and updated automatically from data objects by the UI elements.

Using Basic Validators

  • wxValidator class and customisation points Value checking
    • Informing the user of failures/warnings Focusing on the failing control
    Value transfer Binding validators to controls

Using validators with "non validator" controls

  • Rewriting TransferDataFromWindow and TransferDataToWindow

Recursive validation (automatically validating child windows)

  • Currently broken

Limitations and coverage

  • Only available automatically in wxDialog subclasses (need to write something to call Validate, and Transfer if using another class). (Re-)writing dialog close/update methods to handle mixed Validator/non-validator controls

Example

(Re-)writing dialog close/update methods to handle mixed Validator/non-validator controls

  • Note that the following is untested (copied from working code and modified in the documentation). should test

        def Validate( self, event ):
                '''Process an event for the okay button...'''
                # do validation for normal "Validator" controls
                if not wxWindow.Validate( self ):
                        return false
                # now walk through the other controls (
                for editor in self.controls:
                        if hasattr( editor, 'Validate') and not editor.Validate( self ):
                                return false
        def TransferDataFromWindow( self, ):
                if not wxWindow.TransferDataFromWindow( self ):
                        return false
                for editor in self.controls:
                        if hasattr( editor, 'TransferDataFromWindow'):
                                if not editor.TransferDataFromWindow():
                                        return false
        def TransferDataToWindow( self, ):
                if not wxWindow.TransferDataToWindow( self ):
                        return false
                for editor in self.controls:
                        if hasattr( editor, 'TransferDataToWindow'):
                                if not editor.TransferDataToWindow():
                                        return false

Display

xxx

InputValueCheckingAndTransfer (last edited 2008-03-11 10:50:23 by localhost)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.