X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9416aa89ca06d0fb20b1002e026d2c7ac7aa6a17..80a81a12af49ab6acdaf0b62f4aa55e56f45ac6d:/wxPython/demo/wxValidator.py diff --git a/wxPython/demo/wxValidator.py b/wxPython/demo/wxValidator.py index 4209150905..b2081d9510 100644 --- a/wxPython/demo/wxValidator.py +++ b/wxPython/demo/wxValidator.py @@ -24,14 +24,14 @@ class MyValidator(wxPyValidator): if self.flag == ALPHA_ONLY: for x in val: if x not in string.letters: - return false + return False elif self.flag == DIGIT_ONLY: for x in val: if x not in string.digits: - return false + return False - return true + return True def OnChar(self, event): @@ -58,31 +58,31 @@ class MyValidator(wxPyValidator): class TestValidatorPanel(wxPanel): def __init__(self, parent): wxPanel.__init__(self, parent, -1) - self.SetAutoLayout(true) + self.SetAutoLayout(True) VSPACE = 10 fgs = wxFlexGridSizer(0, 2) - fgs.Add(1,1); + fgs.Add((1,1)) fgs.Add(wxStaticText(self, -1, "These controls have validators that limit\n" "the type of characters that can be entered.")) - fgs.Add(1,VSPACE); fgs.Add(1,VSPACE) + fgs.Add((1,VSPACE)); fgs.Add((1,VSPACE)) label = wxStaticText(self, -1, "Alpha Only: ") fgs.Add(label, 0, wxALIGN_RIGHT|wxCENTER) fgs.Add(wxTextCtrl(self, -1, "", validator = MyValidator(ALPHA_ONLY))) - fgs.Add(1,VSPACE); fgs.Add(1,VSPACE) + fgs.Add((1,VSPACE)); fgs.Add((1,VSPACE)) label = wxStaticText(self, -1, "Digits Only: ") fgs.Add(label, 0, wxALIGN_RIGHT|wxCENTER) fgs.Add(wxTextCtrl(self, -1, "", validator = MyValidator(DIGIT_ONLY))) - fgs.Add(1,VSPACE); fgs.Add(1,VSPACE) - fgs.Add(1,VSPACE); fgs.Add(1,VSPACE) - fgs.Add(0,0) + fgs.Add((1,VSPACE)); fgs.Add((1,VSPACE)) + fgs.Add((1,VSPACE)); fgs.Add((1,VSPACE)) + fgs.Add((0,0)) b = wxButton(self, -1, "Test Dialog Validation") EVT_BUTTON(self, b.GetId(), self.OnDoDialog) fgs.Add(b) @@ -127,28 +127,33 @@ class TextObjectValidator(wxPyValidator): if len(text) == 0: wxMessageBox("A text object must contain some text!", "Error") + textCtrl.SetBackgroundColour("pink") textCtrl.SetFocus() - return false + textCtrl.Refresh() + return False else: - return true + textCtrl.SetBackgroundColour( + wxSystemSettings_GetColour(wxSYS_COLOUR_WINDOW)) + textCtrl.Refresh() + return True def TransferToWindow(self): """ Transfer data from validator to window. - The default implementation returns false, indicating that an error - occurred. We simply return true, as we don't do any data transfer. + The default implementation returns False, indicating that an error + occurred. We simply return True, as we don't do any data transfer. """ - return true # Prevent wxDialog from complaining. + return True # Prevent wxDialog from complaining. def TransferFromWindow(self): """ Transfer data from window to validator. - The default implementation returns false, indicating that an error - occurred. We simply return true, as we don't do any data transfer. + The default implementation returns False, indicating that an error + occurred. We simply return True, as we don't do any data transfer. """ - return true # Prevent wxDialog from complaining. + return True # Prevent wxDialog from complaining. #---------------------------------------------------------------------- @@ -156,25 +161,25 @@ class TestValidateDialog(wxDialog): def __init__(self, parent): wxDialog.__init__(self, parent, -1, "Validated Dialog") - self.SetAutoLayout(true) + self.SetAutoLayout(True) VSPACE = 10 fgs = wxFlexGridSizer(0, 2) - fgs.Add(1,1); + fgs.Add((1,1)); fgs.Add(wxStaticText(self, -1, "These controls must have text entered into them. Each\n" "one has a validator that is checked when the Okay\n" "button is clicked.")) - fgs.Add(1,VSPACE); fgs.Add(1,VSPACE) + fgs.Add((1,VSPACE)); fgs.Add((1,VSPACE)) label = wxStaticText(self, -1, "First: ") fgs.Add(label, 0, wxALIGN_RIGHT|wxCENTER) fgs.Add(wxTextCtrl(self, -1, "", validator = TextObjectValidator())) - fgs.Add(1,VSPACE); fgs.Add(1,VSPACE) + fgs.Add((1,VSPACE)); fgs.Add((1,VSPACE)) label = wxStaticText(self, -1, "Second: ") fgs.Add(label, 0, wxALIGN_RIGHT|wxCENTER) @@ -182,7 +187,9 @@ class TestValidateDialog(wxDialog): buttons = wxBoxSizer(wxHORIZONTAL) - buttons.Add(wxButton(self, wxID_OK, "Okay"), 0, wxALL, 10) + b = wxButton(self, wxID_OK, "Okay") + b.SetDefault() + buttons.Add(b, 0, wxALL, 10) buttons.Add(wxButton(self, wxID_CANCEL, "Cancel"), 0, wxALL, 10) border = wxBoxSizer(wxVERTICAL) @@ -203,12 +210,6 @@ def runTest(frame, nb, log): - - - - - - overview = """\ wxValidator is the base class for a family of validator classes that mediate between a class of control, and application data. @@ -223,3 +224,11 @@ A validator has three major roles: Validators can be plugged into controls dynamically. """ + + + +if __name__ == '__main__': + import sys,os + import run + run.main(['', os.path.basename(sys.argv[0])]) +