# Intercepting events with wxRuby/wxWidgets

**URL:** <https://www.ruby-forum.com/t/intercepting-events-with-wxruby-wxwidgets/125181>\
**Category:** Ruby\
**Created:** [January 6, 2008, 7:22pm UTC](https://www.ruby-forum.com/t/intercepting-events-with-wxruby-wxwidgets/125181 "2008-01-06T19:22:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rainer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/58956e/32.png) [@rainer](https://www.ruby-forum.com/u/rainer)\
**Post date:** [January 6, 2008, 7:22pm UTC](https://www.ruby-forum.com/t/intercepting-events-with-wxruby-wxwidgets/125181/1 "2008-01-06T19:22:11Z")

</div>

Hello everybody,

I have a question concerning wxRuby/wxWidgets. I’m getting my feet wet  
with a simple application that holds one Wx::Frame called VwX.

When my application gets closed, I want the user to decide whether the  
app really will shut down. If it shuts down: Save the last changes or  
not? Typical Yes/No/Cancel situation. So I do this: (Remark:  
VwXEvOnClose(event) is the “on\_close” event of my Wx::Frame):

def VwXEvOnClose(event)  
dlg = MessageDialog.new(nil, “Save changes?”, “MyApp”,  
Wx::YES\_DEFAULT|Wx::CANCEL|Wx::YES\_NO|Wx::ICON\_EXCLAMATION)  
command = dlg.show\_modal  
dlg.destroy

```
case command
  when Wx::ID_CANCEL
  event.veto

  when Wx::ID_YES
  save_my_changes
  event.skip

  else
  event.skip
end

```

end

This works as it is supposed to. However, I noticed that the call to  
“event.veto” might just as well be missing without any problems. OTOH,  
the calls to “event.skip” are essential: If I dont call these, the  
application simply won’t shut down. Any ideas why the veto is  
unimportant?

---

<div class="post-metadata">

**Author:** ![rainer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/58956e/32.png) [@rainer](https://www.ruby-forum.com/u/rainer)\
**Post date:** [January 6, 2008, 9:35pm UTC](https://www.ruby-forum.com/t/intercepting-events-with-wxruby-wxwidgets/125181/2 "2008-01-06T21:35:56Z")

</div>

In message  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid),  
Rainer [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes

> Hello everybody,
> 
> I have a question concerning wxRuby/wxWidgets. I’m getting my feet wet  
> with a simple application that holds one Wx::Frame called VwX.

…

wxruby-users is a good place to post this kind of question.

HTH

Alec

---

<div class="post-metadata">

**Author:** ![rainer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/58956e/32.png) [@rainer](https://www.ruby-forum.com/u/rainer)\
**Post date:** [January 6, 2008, 10:20pm UTC](https://www.ruby-forum.com/t/intercepting-events-with-wxruby-wxwidgets/125181/3 "2008-01-06T22:20:35Z")

</div>

Rainer wrote:

> Hello everybody,
> 
> I have a question concerning wxRuby/wxWidgets. I’m getting my feet wet  
> with a simple application that holds one Wx::Frame called VwX.

As noted, wxruby-users is a better place to ask questions specifically  
about wxRuby.

> When my application gets closed, I want the user to decide whether the  
> app really will shut down. If it shuts down: Save the last changes or  
> not? Typical Yes/No/Cancel situation. So I do this: (Remark:  
> VwXEvOnClose(event) is the “on\_close” event of my Wx::Frame):

…

> This works as it is supposed to. However, I noticed that the call to  
> “event.veto” might just as well be missing without any problems. OTOH,  
> the calls to “event.skip” are essential: If I dont call these, the  
> application simply won’t shut down. Any ideas why the veto is  
> unimportant?

The veto method only applies to close events; the documentation explains  
that:

“If you don’t destroy the window, you should call Wx::CloseEvent#veto to  
let the calling code know that you did not destroy the window. This  
allows the Wx::Window#close function to return true or false depending  
on whether the close instruction was honoured or not.”

hth  
alex

---

<div class="post-metadata">

**Author:** ![rainer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/58956e/32.png) [@rainer](https://www.ruby-forum.com/u/rainer)\
**Post date:** [January 6, 2008, 11:15pm UTC](https://www.ruby-forum.com/t/intercepting-events-with-wxruby-wxwidgets/125181/4 "2008-01-06T23:15:36Z")

</div>

On 6 Jan., 22:16, Alex F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> The veto method only applies to close events; the documentation explains  
> that:
> 
> “If you don’t destroy the window, you should call Wx::CloseEvent#veto to  
> let the calling code know that you did not destroy the window. This  
> allows the Wx::Window#close function to return true or false depending  
> on whether the close instruction was honoured or not.”
> 
> hth  
> alex

Hello Alex,

this sounds like the method doesn’t actually perform the veto, it just  
informs the calling code that the window wasn’t destroyed. Makes  
sense, thank you. I only read the “short” documentation which states:

“Call this from your event handler to veto a system shutdown or to  
signal to the calling application that a window close did not happen.  
You can only veto a shutdown if wxCloseEvent::CanVeto returns true.”

This sounded to me that there are cases when you actually perform the  
veto. Case closed anyway: I will leave the method call in, of course.

Alec, thank you, too, for the hint with the wxruby-users mailing list.  
I will reserve this for the harder cases, though, as this newsgroup  
was absolutely fit for the task!

Thanks everybody,

Rainer
