Ruby bindings for Loudmouth

Last week I sat down and wrote bindings for Loudmouth. This means that anyone who want to write an XMPP enabled application with GTK+/Ruby now have an asynchronous library that integrates perfectly with the GLib mainloop.

It also gives me access to testing and writing small scripts using Loudmouth with the beauty of Ruby.

Here is a small example showing the bindings in the current state:

require 'loudmouth'

conn = LM::Connection.new
conn.jid = 'myjid@mydomain.com'

conn.open do |open_result|
  if open_result
    conn.authenticate('username', 'password', 'resource') do |auth_result|
      if result
         puts "Authenticated, do your stuff"
       end
    end
  end
end

GLib::MainLoop.new.run

So far I have only bound the asynchronous calls and I am not sure whether I will bind synchronous ones in the future.

If you want to try them out or even better, help out by improving them or write example code. Create an account at Github and watch/clone the repository. It’s named loudmouth-ruby.

Type registering your own widgets in Ruby/GTK+

I ran into a slight problem when I tried to create a type registered subclass in Ruby/GTK+. This is done by adding type_register in your class definition. This worked fine until I tried to pass arguments to the super class constructor through the super() call.

In my previous example, I passed the arguments like usual to the super call. It turns out that when you have registered your class with the GObject type system (which I didn’t do in that example) it overloads the super() call and you need to pass the arguments as a hash instead.

Here is an example subclassing Gtk::Button that sets the button up defaulting to underline mnemonics.

require 'gtk2'

class MyButton < Gtk::Button
  type_register

  def initialize(label)
    super({:label => label, :use_underline => true})
  end

  def signal_do_clicked(*args)
    puts “Clicked”
  end
end

w = Gtk::Window.new

b = MyButton.new(”My _Button”)
w.add(b)

w.signal_connect(:delete_event) do
  Gtk.main_quit
end

w.show_all
Gtk.main

Kudos to Kou for showing how to do it.

Ars Technica about GTK+ 3.0

Guess most people have seen this by now but being on vacation last week I just managed to catch up and read the Ars Technica article “Reinventing GTK: envisioning the future of the toolkit” which is a nice and well informed summary of discussions that have been going on around GTK+.

If you haven’t already, you should read it.

Next Page »

Close
E-mail It