validator not in a dialog

Hello,

I am trying to understand the use of validators
for validating control not located in a dialog.

I am reading the Dunn/Rappin book.
For doing that:
"call the parent window's Validate() method"

For example let's talk about 2 wx.TextCtrl in a panel = wx.Panel in
wx.Frame.

Is "the parent window's" the parent of the widget I want to validate?

In this example the panel? that's it?

So I have to call the method Validate on the parent: panel.Validate()
That's it.

And when (=? where ) do I have to put panel.Validate()?
I though that if I have a wx.Button I can bind an event
on that button to a methode with "panel.Validate()".
Am I in the right direction?

Thanks

laurent FRANCOIS wrote:

Hello,

I am trying to understand the use of validators for validating control not located in a dialog.

I am reading the Dunn/Rappin book. For doing that:
"call the parent window's Validate() method"

For example let's talk about 2 wx.TextCtrl in a panel = wx.Panel in
wx.Frame.

Is "the parent window's" the parent of the widget I want to validate?

In this example the panel? that's it?

So I have to call the method Validate on the parent: panel.Validate()
That's it.

And when (=? where ) do I have to put panel.Validate()?
I though that if I have a wx.Button I can bind an event on that button to a methode with "panel.Validate()".
Am I in the right direction?

Thanks

I don't have my copy of the book handy as it is at work, but normally you use Validators to validate data in widgets, not the containers. See the following links for examples:

http://lists.wxwidgets.org/pipermail/wxpython-users/2009-February/083983.html
http://wiki.wxpython.org/Validator%20for%20Object%20Attributes

I do see Validator listed in the wx.Window docs, but I guess I don't know what that is for.

···

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org
Python Extension Building Network: http://www.pythonlibrary.org

__________ Information from ESET NOD32 Antivirus, version of virus signature database 4018 (20090418) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

Bonjour Laurent,

I’m not that far in my study of wxPython but I just looked at Section 9.5 (p. 282 & ss) and I must admit it is not easy reading / understanding, much less even for a non-English speaker. Anyway, reading on p.285:

“The code that explicitly tells the dialog to check the validators is not in the listing - it is part of the wxPython event system. Another difference between dialogs and frames is that dialogs have the validator behavior built-in and frames do not. If you would like to use validators for validating controls not located in a dialog, call the parent window’s Validate() method. If the wx.WS_EX_VALIDATE_RECURSIVELY extra style is set for window, Validate() of all the child windows is also called. If any of the validations fail, Validate returns False.”

My understanding of the above is the following:

  1. Dialogs (via their event system) will automatically call validator(s) if a validator is specified as in the example (validator=NotEmptyValidator()).

  2. This is true for controls (e.g. TextCtrl) that are within the dialog box.

  3. If the control is placed in another container, say a TextCtrl within a panel belonging to the top level frame, that you must call the Validate() method of the container of that control. In this case the Validate() method of the panel.

  4. Frames are different from dialogs and thus there is no automatic check by the frame event system that verifies if there is a need to validate something. In that case you need to call yourself the Validate() method of the widget that contains the control you wish to validate.

I’m not sure if this is clearer for you, neither if it is the correct interpreation.

I just hope it helps a bit.

Bonne journée,

René

···

On Sat, Apr 18, 2009 at 2:01 PM, laurent FRANCOIS lau.francois@worldonline.fr wrote:

Hello,

I am trying to understand the use of validators
for validating control not located in a dialog.

I am reading the Dunn/Rappin book.
For doing that:
“call the parent window’s Validate() method”

For example let’s talk about 2 wx.TextCtrl in a panel = wx.Panel in
wx.Frame.

Is “the parent window’s” the parent of the widget I want to validate?

In this example the panel? that’s it?

So I have to call the method Validate on the parent: panel.Validate()
That’s it.

And when (=? where ) do I have to put panel.Validate()?
I though that if I have a wx.Button I can bind an event

on that button to a methode with “panel.Validate()”.
Am I in the right direction?

Thanks


wxpython-users mailing list
wxpython-users@lists.wxwidgets.org

http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

laurent FRANCOIS wrote:

Hello,

I am trying to understand the use of validators for validating control not located in a dialog.

I am reading the Dunn/Rappin book. For doing that:
"call the parent window's Validate() method"

For example let's talk about 2 wx.TextCtrl in a panel = wx.Panel in
wx.Frame.

Is "the parent window's" the parent of the widget I want to validate?

In this example the panel? that's it?

So I have to call the method Validate on the parent: panel.Validate()
That's it.

And when (=? where ) do I have to put panel.Validate()?
I though that if I have a wx.Button I can bind an event on that button to a methode with "panel.Validate()".
Am I in the right direction?
  

Set wx.WS_EX_VALIDATE_RECURSIVELY on your panel(s) and then call frame.Validate() (e.g. in a button event which would save the data to a database) and this will then call validate on the panel and due to the style you set on the panel it will call validate on every child control which has a validator.

Werner

laurent FRANCOIS wrote:

Hy Werner,

If the wx.TextCtrl's are in a panel, the panel in a frame.
You are sure that I have to call the frame Valide() method.

I though that I have to call the parent of the wx.TextCtrl's so the
panel Validate() method

I know that you manage well validators, I've been reading your code that you send some time ago. I just need a confirmation frame.Validate() versus panel.Validate()
  

Did not notice that this came off-list. So here again, just to keep in on the list for the archive.

I would call frame.Validate(), however you have to consider your own app.

I.e. if you had a splitter with two panels and some controls on each panel calling frame.Validate() will validate all the controls. But in some situations you might only want to validate some controls, in which case you would call e.g. panel2.Validate().

By the way the same goes for "TransferDataFromWindow" and "TransferDataToWindow".

Werner