Ruby-gnome2: emit key press


#1

I’m trying to have a listbox page up/down based on keys pressed. so I
thought this could maybe done by using something similar to this:
event = Gdk::EventKey.new( Gdk::Event::KEY_PRESS )
event.set_keyval(65366) # page_down
widget.signal_emit(‘key-press-event’, event)

Clayton


#2

Hi,

On Fri, 18 Nov 2005 02:07:18 +0900
removed_email_address@domain.invalid wrote:

I’m trying to have a listbox page up/down based on keys pressed. so I
thought this could maybe done by using something similar to this:
event = Gdk::EventKey.new( Gdk::Event::KEY_PRESS )
event.set_keyval(65366) # page_down
widget.signal_emit(‘key-press-event’, event)

If you want to emit a GDK event, you need to allow to accept the event
to the widget which the event is emitted.

Here is an example which Gtk::Window emits the key-press-event.


require ‘gtk2’
Gtk.init
window = Gtk::Window.new
window.add_events(Gdk::Event::KEY_PRESS_MASK)
window.set_default_size(300,200)
window.signal_connect(“key-press-event”) do |w, e|
p “key pressed : #{e.keyval}”
end
window.show_all
Gtk.main


#3

Hi,

On Fri, 18 Nov 2005 02:42:18 +0900
removed_email_address@domain.invalid wrote:

    end
end

end

How about the sample below?


require ‘gtk2’
Gtk.init
model = Gtk::ListStore.new(String)
tv = Gtk::TreeView.new(model)
tv.append_column(Gtk::TreeViewColumn.new(“TITLE”,
Gtk::CellRendererText.new,
:text => 0))
tv.enable_search = false
model.append[0] = “LINE 1”
model.append[0] = “LINE 2”
model.append[0] = “LINE 3”

tv.signal_connect(“key-press-event”) do |widget, event|
if Gdk::Window::ModifierType::CONTROL_MASK == event.state &
Gdk::Window::CONTROL_MASK
case event.keyval
when Gdk::Keyval::GDK_u # ctrl-u
tv.move_cursor(Gtk::MOVEMENT_DISPLAY_LINES, -1)
tv.selection.select_path(tv.cursor[0])
when Gdk::Keyval::GDK_d # ctrl-d
tv.move_cursor(Gtk::MOVEMENT_DISPLAY_LINES, 1)
tv.selection.select_path(tv.cursor[0])
end
end
end

Gtk::Window.new.add(tv).show_all

Gtk.main


#4

I’ve something similar to that already… but… let me try to rephrase.
here is what I have so far:
tree.signal_connect(“key-press-event”) do |widget, event|
if Gdk::Window::ModifierType::CONTROL_MASK == event.state &
Gdk::Window::CONTROL_MASK
case event.keyval
when 117 then # ctrl-u
# scroll my widget up
when 100 then # ctrl-d
# scroll my widget down
end
end
end

my initial phrasing of the question / approach may not have been poor.
I just want to force it to scroll up or down. Thanks for the prompt
reply…

Clayton