From: cedlemo <ce...@gm...> - 2017-02-28 14:43:56
|
John, try this (it works for me, I hope it will works for you) : require "glib2" require "gobject-introspection" require "gtk3" module Keybinder class Loader < GObjectIntrospection::Loader end loader = Loader.new(self) loader.load("Keybinder") end win = Gtk::Window.new win.signal_connect("destroy") { Gtk.main_quit } win.show Keybinder.init Keybinder.bind('<Ctrl>p') do puts "ctrl + p" end Keybinder.bind('XF86AudioNext') do puts "keysoundnext" end Gtk.main Two things here: * Keybinder need to be initialized with (#init) * the bind method only take one argument, the callback is transformed in ruby the block do ... end. cedlemo you could find this trick in On 28/02/2017 12:36, John Lane wrote: > On 27/02/17 16:56, cedlemo wrote: >> Maybe look here https://github.com/ruby-gnome2/ggit this is a loader for >> the gobject-libgit2. It is very simple, it should be a good starting point. >> >> Look in the ruby-gnome2 gems too; the atk gem, for example, has been >> recently updated in order to use gobject-introspection instead of the C >> bindings. >> > Hey Cedelmo, well I have something partially working with GI! > > I know the library is hooked up because I have a call that works and it > outputs text that is in the library. However, this: > > Keybinder.bind('Menu', Callback, 'Key pressed') > > fails with this error: > > > /usr/lib/ruby/gems/2.3.0/gems/gobject-introspection-3.1.1/lib/gobject-introspection/loader.rb:651:in > `validate_arguments': Keybinder.bind: wrong number of arguments (3 for > 1) (ArgumentError) > > I have looked at the source[1] and studied the annotation > documentation[2]. I can see that the actual bind function is skipped but > `keybinder_bind_full` is renamed to `keybinder_bind`. The header for > that function shows four parameters of which the last is optional, so my > call passing three parameters ought to be ok: > > /** > * keybinder_bind_full: (rename-to keybinder_bind) > * @keystring: an accelerator description (gtk_accelerator_parse() format) > * @handler: (scope notified): callback function > * @user_data: (closure) (allow-none): data to pass to @handler > * @notify: (allow-none): called when @handler is unregistered > * > * Grab a key combination globally and register a callback to be called each > * time the key combination is pressed. > * > * Since: 0.3.0 > * > * Returns: %TRUE if the accelerator could be grabbed > */ > gboolean > keybinder_bind_full (const char *keystring, > KeybinderHandler handler, > void *user_data, > GDestroyNotify notify) > > So I must have done something wrong, but I actually did very little. > Here's my GI module: > > module Keybinder > > class Loader < GObjectIntrospection::Loader > end > > loader = Loader.new(self) > loader.load("Keybinder") > end > > I'm not sure where to go from here... > > Thanks for your help, > John > > > > [1] > https://github.com/kupferlauncher/keybinder/blob/master/libkeybinder/bind.c#L547 > [2] https://wiki.gnome.org/Projects/GObjectIntrospection/Annotations > > > ------------------------------------------------------------------------------ > Check out the vibrant tech community on one of the world's most > engaging tech sites, SlashDot.org! http://sdm.link/slashdot > _______________________________________________ > ruby-gnome2-devel-en mailing list > rub...@li... > https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en |