WXWINDOW: CANCEL -button and validation

Cliff Wells logiplexsoftware at earthlink.net
Wed Feb 20 19:08:13 EST 2002


On Wed, 20 Feb 2002 22:55:31 +0200
Pekka Niiranen wrote:

> Hi,
> 
> In code below:
> 
> -  when user enters empty values and presses OK -button, validator
>     warns about the empty values.
> 
> -  when user enters empty values and presses CANCEL -button, validator
>     is not run and I must add "useless checks for empty values" in code
> + default values

I don't understand why you would want to validate user input when cancel is
clicked.  That's the purpose of cancel - to cancel the user action.  If you
want to set default values if the user clicks cancel, that's a different
story - I would have a separate routine that is run when the dialog is
canceled or closed that sets those values.

dlg =  EditConversionParameters(a, bunch, of, args)
retval = dlg.ShowModal()

if retval == wxCANCEL:
	dlg.set_defaults()

values = dlg.GetValues() # or whatever you're doing to get the values from
the dialog
dlg.Destroy()

I didn't bother trying to make much of your code as I don't know what your
many arguments are supposed to be, among other things.  Also, I'm not sure
what your "useless checks" are supposed to do, since they are in fact,
useless.  They get executed before the dialog is even shown onscreen.  They
have nothing to do with user input.

> 1) How can I run Validate(self, parent) -method when CANCEL -button is
> pressed ?
> 2) How can disable the close button (X -button on top right corner of
> window) from wxDialog ?

IIRC, the close button causes the dialog to return wxID_CANCEL just as if
the user clicked the cancel button, so the same logic would apply.

-- 
Cliff Wells, Software Engineer
Logiplex Corporation (www.logiplex.net)
(503) 978-6726 x308  (800) 735-0555 x308




More information about the Python-list mailing list