Forum: Ruby-Gnome 2 EventBox key press event

Posted by Brad M. (brad_m77)
on 2011-06-26 17:32
Anyone have any ideas why this will not work
been working and googling for hours

It works on Gtk::Window

require 'gtk2'
w  = Gtk::Window.new
eb = Gtk::EventBox.new
w.add(eb)
eb.add_events(Gdk::Event::ALL_EVENTS_MASK)
#eb.add_events(Gdk::Event::KEY_PRESS_MASK)

eb.signal_connect('key-press-event') do |widg, event|
  puts 'pressed'
end

w.show_all
Gtk::main

Thanks In Advance
brad
Posted by Simon Arnaud (sarnaud)
on 2011-08-01 12:42
Brad M. wrote in post #1007709:
> require 'gtk2'
> w  = Gtk::Window.new
> eb = Gtk::EventBox.new
> w.add(eb)
> eb.add_events(Gdk::Event::ALL_EVENTS_MASK)
> #eb.add_events(Gdk::Event::KEY_PRESS_MASK)
>
> eb.signal_connect('key-press-event') do |widg, event|
>   puts 'pressed'
> end
>
> w.show_all
> Gtk::main

The point of Gtk::EventBox is to enable capturing events on widgets 
which can't. If you add the EventBox to Window, it is, more or less, non 
existing.

Try to add a child to your EventBox. For example :
eb.add(Gtk::Button.new("test"))

Try with a vbox, add 2 buttons, one in the event box, focus one or the 
other, and check event is only trigered with the one in the event box.

Simon
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.