Who's `EndModal`ing my dialog?

Hello,

I am raising a dialog in which a user inputs some data. When you press
"okay", it does check on the validity of the data. I there's a problem
it raises an error dialog. (Subclass of `wx.MessageDialog`.) After
that, of course, it does *not* `EndModal` itself, because the user
needs to fix the data.

However, I found that when I press "Okay" on the error dialog, it not
only ends it but the big dialog too! Why could this happen?

To debug it, I overridden `EndModal` on my dialog subclass and put a
breakpoint there, but when I test it, (i.e. run the program, raise the
dialog, enter erroneous data and press okay, get the error dialog, and
press okay,) both dialogs get closed and my debugger is not stopping
on the breakpoint. So I conclude that `EndModal` is not being called
at all, but somehow the dialog gets closed.

What could be hapenning?

Thanks,
Ram.

Solved-- I was doing event.Skip in the handler for the okay button. A bad idea apparently.

Ram.

···

On Sun, Nov 28, 2010 at 5:15 PM, cool-RR ram.rachum@gmail.com wrote:

Hello,

I am raising a dialog in which a user inputs some data. When you press

“okay”, it does check on the validity of the data. I there’s a problem

it raises an error dialog. (Subclass of wx.MessageDialog.) After

that, of course, it does not EndModal itself, because the user

needs to fix the data.

However, I found that when I press “Okay” on the error dialog, it not

only ends it but the big dialog too! Why could this happen?

To debug it, I overridden EndModal on my dialog subclass and put a

breakpoint there, but when I test it, (i.e. run the program, raise the

dialog, enter erroneous data and press okay, get the error dialog, and

press okay,) both dialogs get closed and my debugger is not stopping

on the breakpoint. So I conclude that EndModal is not being called

at all, but somehow the dialog gets closed.

What could be hapenning?

Thanks,

Ram.

Ram,
Have you considered using a validator as in the demo, I think that you will find that it provides almost exactly what you are looking for.

Gadget/Steve

···

-----Original Message----- From: cool-RR
Sent: Sunday, November 28, 2010 3:15 PM
To: wxPython-users
Subject: [wxPython-users] Who's `EndModal`ing my dialog?

Hello,

I am raising a dialog in which a user inputs some data. When you press
"okay", it does check on the validity of the data. I there's a problem
it raises an error dialog. (Subclass of `wx.MessageDialog`.) After
that, of course, it does *not* `EndModal` itself, because the user
needs to fix the data.

However, I found that when I press "Okay" on the error dialog, it not
only ends it but the big dialog too! Why could this happen?

To debug it, I overridden `EndModal` on my dialog subclass and put a
breakpoint there, but when I test it, (i.e. run the program, raise the
dialog, enter erroneous data and press okay, get the error dialog, and
press okay,) both dialogs get closed and my debugger is not stopping
on the breakpoint. So I conclude that `EndModal` is not being called
at all, but somehow the dialog gets closed.

What could be hapenning?

Thanks,
Ram.

I looked at it now; It seems kind of weird, so I think I’ll stick with checking validity myself.

Ram.

···

On Mon, Nov 29, 2010 at 10:14 AM, Steve Barnes GadgetSteve@live.co.uk wrote:

-----Original Message----- From: cool-RR

Sent: Sunday, November 28, 2010 3:15 PM

To: wxPython-users

Subject: [wxPython-users] Who’s EndModaling my dialog?

Hello,

I am raising a dialog in which a user inputs some data. When you press

“okay”, it does check on the validity of the data. I there’s a problem

it raises an error dialog. (Subclass of wx.MessageDialog.) After

that, of course, it does not EndModal itself, because the user

needs to fix the data.

However, I found that when I press “Okay” on the error dialog, it not

only ends it but the big dialog too! Why could this happen?

To debug it, I overridden EndModal on my dialog subclass and put a

breakpoint there, but when I test it, (i.e. run the program, raise the

dialog, enter erroneous data and press okay, get the error dialog, and

press okay,) both dialogs get closed and my debugger is not stopping

on the breakpoint. So I conclude that EndModal is not being called

at all, but somehow the dialog gets closed.

What could be hapenning?

Thanks,

Ram.

Ram,

Have you considered using a validator as in the demo, I think that you will find that it provides almost exactly what you are looking for.

Gadget/Steve

    Hello,

    I am raising a dialog in which a user inputs some data. When you press
    "okay", it does check on the validity of the data. I there's a problem
    it raises an error dialog. (Subclass of `wx.MessageDialog`.) After
    that, of course, it does *not* `EndModal` itself, because the user
    needs to fix the data.

    However, I found that when I press "Okay" on the error dialog, it not
    only ends it but the big dialog too! Why could this happen?

    To debug it, I overridden `EndModal` on my dialog subclass and put a
    breakpoint there, but when I test it, (i.e. run the program, raise the
    dialog, enter erroneous data and press okay, get the error dialog, and
    press okay,) both dialogs get closed and my debugger is not stopping
    on the breakpoint. So I conclude that `EndModal` is not being called
    at all, but somehow the dialog gets closed.

This issue with overriding the C++ methods is explained in the wiki: OverridingMethods - wxPyWiki

    What could be hapenning?

    Thanks,
    Ram.

Solved-- I was doing `event.Skip` in the handler for the okay button. A
bad idea apparently.

EndModal is called from the default event handler for the wx.ID_OK button, so by not Skip()ing it in your handler then the default handler was also called and it called EndModal.

···

On 11/28/10 7:19 AM, cool-RR wrote:

On Sun, Nov 28, 2010 at 5:15 PM, cool-RR <ram.rachum@gmail.com > <mailto:ram.rachum@gmail.com>> wrote:

--
Robin Dunn
Software Craftsman

You may want to look at the section about validators in the book (chapter 9) and/or the validator samples from the book. I think they are explained better there than elsewhere. The confusion usually comes from the fact that you can use validators in 3 different ways, and that one of those ways doesn't actually have anything to do with validation. But once you get past that mental hurdle they are actually pretty useful.

···

On 11/29/10 10:35 AM, cool-RR wrote:

On Mon, Nov 29, 2010 at 10:14 AM, Steve Barnes <GadgetSteve@live.co.uk > <mailto:GadgetSteve@live.co.uk>> wrote:

        -----Original Message----- From: cool-RR
        Sent: Sunday, November 28, 2010 3:15 PM
        To: wxPython-users
        Subject: [wxPython-users] Who's `EndModal`ing my dialog?

        Hello,

        I am raising a dialog in which a user inputs some data. When you
        press
        "okay", it does check on the validity of the data. I there's a
        problem
        it raises an error dialog. (Subclass of `wx.MessageDialog`.) After
        that, of course, it does *not* `EndModal` itself, because the user
        needs to fix the data.

        However, I found that when I press "Okay" on the error dialog,
        it not
        only ends it but the big dialog too! Why could this happen?

        To debug it, I overridden `EndModal` on my dialog subclass and put a
        breakpoint there, but when I test it, (i.e. run the program,
        raise the
        dialog, enter erroneous data and press okay, get the error
        dialog, and
        press okay,) both dialogs get closed and my debugger is not stopping
        on the breakpoint. So I conclude that `EndModal` is not being called
        at all, but somehow the dialog gets closed.

        What could be hapenning?

        Thanks,
        Ram.

    Ram,
    Have you considered using a validator as in the demo, I think that
    you will find that it provides almost exactly what you are looking for.

    Gadget/Steve

I looked at it now; It seems kind of weird, so I think I'll stick with
checking validity myself.

--
Robin Dunn
Software Craftsman

Thanks, I’ll check it out.

Ram.

···

On Mon, Nov 29, 2010 at 9:22 PM, Robin Dunn robin@alldunn.com wrote:

On 11/29/10 10:35 AM, cool-RR wrote:

On Mon, Nov 29, 2010 at 10:14 AM, Steve Barnes <GadgetSteve@live.co.uk > > mailto:GadgetSteve@live.co.uk> wrote:

    -----Original Message----- From: cool-RR

    Sent: Sunday, November 28, 2010 3:15 PM

    To: wxPython-users

    Subject: [wxPython-users] Who's `EndModal`ing my dialog?





    Hello,



    I am raising a dialog in which a user inputs some data. When you

    press

    "okay", it does check on the validity of the data. I there's a

    problem

    it raises an error dialog. (Subclass of `wx.MessageDialog`.) After

    that, of course, it does *not* `EndModal` itself, because the user

    needs to fix the data.



    However, I found that when I press "Okay" on the error dialog,

    it not

    only ends it but the big dialog too! Why could this happen?



    To debug it, I overridden `EndModal` on my dialog subclass and put a

    breakpoint there, but when I test it, (i.e. run the program,

    raise the

    dialog, enter erroneous data and press okay, get the error

    dialog, and

    press okay,) both dialogs get closed and my debugger is not stopping

    on the breakpoint. So I conclude that `EndModal` is not being called

    at all, but somehow the dialog gets closed.



    What could be hapenning?





    Thanks,

    Ram.





Ram,

Have you considered using a validator as in the demo, I think that

you will find that it provides almost exactly what you are looking for.



Gadget/Steve

I looked at it now; It seems kind of weird, so I think I’ll stick with

checking validity myself.

You may want to look at the section about validators in the book (chapter 9) and/or the validator samples from the book. I think they are explained better there than elsewhere. The confusion usually comes from the fact that you can use validators in 3 different ways, and that one of those ways doesn’t actually have anything to do with validation. But once you get past that mental hurdle they are actually pretty useful.
Robin Dunn