Checking types of objects in signal handlers

in the example on
http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3AMenu
it says:

window.signal_connect(“button_press_event”) do |widget, event|
if event.kind_of? Gdk::EventButton
if (event.button == 3)
menu.popup(nil, nil, event.button, event.time)
end
end
end

isn’t the event.kind_of? test redundant, or is this test something
all signal handlers should be doing?

martin

Seems redundant to me since the signal is only emitted
if the button was pressed. But maybe the additional
check is important to ensure that something is a
Gdk::EventButton (but i cant think of a reason, maybe
someone could add a # comment that explains this briefly)

Also I think using :button_press_event would be nicer and
the

if (event.button == 3)

() parens arent needed afaik

Martin P. wrote:

in the example on
http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3AMenu
it says:

window.signal_connect(“button_press_event”) do |widget, event|
if event.kind_of? Gdk::EventButton
if (event.button == 3)
menu.popup(nil, nil, event.button, event.time)
end
end
end

isn’t the event.kind_of? test redundant, or is this test something
all signal handlers should be doing?

martin

Hi,

On Wed, 03 Oct 2007 10:39:16 +0100
Martin P. [email protected] wrote:

isn’t the event.kind_of? test redundant, or is this test something
all signal handlers should be doing?

Sure. You don’t need this here.
I removed this from the tutorial.

BTW, if you use “event” instead of “button_press_event”,
you’ll need to check kind_of?.

window.signal_connect(“event”) do |widget, event|
if event.kind_of? Gdk::EventButton
if (event.button == 3)
menu.popup(nil, nil, event.button, event.time)
end
end
end


.:% Masao M.[email protected]