Forum: Ruby ruby-gnome2: emit key press

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B99242ce26580362afe8333532041d37?d=identicon&s=25 ces.fci.junk (Guest)
on 2005-11-17 18:09
(Received via mailing list)
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
9fe908f5593444a40be14a424c372e58?d=identicon&s=25 mutoh (Guest)
on 2005-11-17 18:18
(Received via mailing list)
Hi,

On Fri, 18 Nov 2005 02:07:18 +0900
ces.fci.junk@gmail.com 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
---
B99242ce26580362afe8333532041d37?d=identicon&s=25 ces.fci.junk (Guest)
on 2005-11-17 18:42
(Received via mailing list)
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
9fe908f5593444a40be14a424c372e58?d=identicon&s=25 mutoh (Guest)
on 2005-11-20 13:51
(Received via mailing list)
Hi,

On Fri, 18 Nov 2005 02:42:18 +0900
ces.fci.junk@gmail.com 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
This topic is locked and can not be replied to.