+class TextObjectValidator(wxPyValidator):
+ """ This validator is used to ensure that the user has entered something
+ into the text object editor dialog's text field.
+ """
+ def __init__(self):
+ """ Standard constructor.
+ """
+ wxPyValidator.__init__(self)
+
+
+
+ def Clone(self):
+ """ Standard cloner.
+
+ Note that every validator must implement the Clone() method.
+ """
+ return TextObjectValidator()
+
+
+ def Validate(self, win):
+ """ Validate the contents of the given text control.
+ """
+ textCtrl = self.GetWindow()
+ text = textCtrl.GetValue()
+
+ if len(text) == 0:
+ wxMessageBox("A text object must contain some text!", "Error")
+ textCtrl.SetBackgroundColour("pink")
+ textCtrl.SetFocus()
+ textCtrl.Refresh()
+ return False
+ else:
+ 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.
+ """
+ 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.
+ """
+ return True # Prevent wxDialog from complaining.