[wxPython] validators

I tried to use validators in wxPython but probably I'm doing this in wrong
way. Please look at this and tell me what is wrong:

1. I created dialog box with one edit box
2. in dialog constructor I asigned validator to edit box control
  __init__(self):
    self.Angle = 0
    self.AngleEdit = wxTextCtrl(size = wxSize(72, 21), value =
'', pos = wxPoint(240, 208), ...)
    self.AngleEdit.SetValidator(MyValidator(self.Angle))

3. MyValidator class contains all needed methods: Clone, TransferToWindow,
TransferFromWindow, Validate.

Everything works fine but how can I then fetch data which is stored in
validator?

If validated object is not simple type but a class instance it will work
because only reference is used but in case of string, reals, ints etc.
validator creates its own copy of data. I have some solutions for that but I
belive that there should be a better way to do this.

My solutions:

1. Validator will get as input object and attribute name: MyValidator(self,
'Angle') - then it has only reference to object
2. Overwrite OnOK method and for each control: get its validator and read
data from it

Seems to be crazy, isn't it?

Mariusz

If validated object is not simple type but a class instance it will work
because only reference is used but in case of string, reals, ints etc.
validator creates its own copy of data. I have some solutions for that but

I

belive that there should be a better way to do this.

My solutions:

1. Validator will get as input object and attribute name:

MyValidator(self,

'Angle') - then it has only reference to object

I've had this thought a few times myself but havn't done it yet. It would
be nice to have a general purpose validator like this in the library that
could be derived from in user code to do the actual validation, but have the
transfer mechanics handled in the base class.

2. Overwrite OnOK method and for each control: get its validator and read
data from it

I don' think this is necessary as Transfer[To|From] window should be where
it is done.

Seems to be crazy, isn't it?

No.

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!