How can I preventing a dialog box to close

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How can I preventing a dialog box to close

ignace danneels
I created a 'log in' dialog box to log in.
My goal is to do password validation at the moment the user clicks the OK button.
I started using wx.CreateButtonSize, but could not catch the events; so I reverted to making my own OK and Cancel button.
When I click on the OK button, and the password validation fails, I want to prevent the dialog box to close.

I attempted to create a self.Bind(EVT_CLOSE,validate) on the dialog box itself, hoping the event would get called when the OK (or CANCEL button) are clicked, but it is not even fired.

Then I tried to do the validation when the SET_FOCUS is called on the OK button, then use the event.Veto() .  But the FocusEvent does not support the Veto().
Then I tried to use the event.Skip().  It blocks the first onfocus event, but when I click the OK button again without having left it, the onfocus event is not fired and I cannot prevent the dialog box from closing.

Can anyone give me some support (preferably with a small example)

Many thanks.

 

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How can I preventing a dialog box to close

James Scholes
Blue Flash wrote:
> I attempted to create a self.Bind(EVT_CLOSE,validate) on the dialog box
> itself, hoping the event would get called when the OK (or CANCEL button)
> are clicked, but it is not even fired.

Why are you binding an event handler to wx.EVT_CLOSE if you want to
intercept button clicks?  Rather than trying to prevent the dialog from
closing when it's already decided it's going to, you need to prevent it
from getting to that point in the first place.

Use wx.EVT_BUTTON and perform your validation in your handler.  If it
succeeds, close the dialog.  If not, do nothing, show an error, set
focus to the field which has invalid input, etc.  And if the user does
click Cancel, or decides to close the dialog through some other
mechanism, respect their wishes as they obviously don't want to log in
right now.
--
James Scholes
http://twitter.com/JamesScholes

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How can I preventing a dialog box to close

ignace danneels
Hello James,

Thank you so much for bringing me on the right track with your short, to the point feedback.
I was obviously too focused on a method to prevent the dialog box to close, that I overlooked what was just in front of me.

Blue Flash


On Sunday, April 9, 2017 at 12:46:30 PM UTC+2, James Scholes wrote:
Blue Flash wrote:
> I attempted to create a self.Bind(EVT_CLOSE,validate) on the dialog box
> itself, hoping the event would get called when the OK (or CANCEL button)
> are clicked, but it is not even fired.

Why are you binding an event handler to wx.EVT_CLOSE if you want to
intercept button clicks?  Rather than trying to prevent the dialog from
closing when it's already decided it's going to, you need to prevent it
from getting to that point in the first place.

Use wx.EVT_BUTTON and perform your validation in your handler.  If it
succeeds, close the dialog.  If not, do nothing, show an error, set
focus to the field which has invalid input, etc.  And if the user does
click Cancel, or decides to close the dialog through some other
mechanism, respect their wishes as they obviously don't want to log in
right now.
--
James Scholes
<a href="http://twitter.com/JamesScholes" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ftwitter.com%2FJamesScholes\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH6ZgoUeZElthUwf1lkQibh0cP4sA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ftwitter.com%2FJamesScholes\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH6ZgoUeZElthUwf1lkQibh0cP4sA&#39;;return true;">http://twitter.com/JamesScholes

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Loading...