Ruby bindings for GTK+ 3? - ruby

I’ve spent some time learning Ruby, and I wanted to move over to some GUI programming. GNOME 3 is the environment most appealing to me at the moment, so I thought I would have a look at GTK+ 3. However, the GTK+ 3 documentation’s Getting Started examples in C were quite off-putting. Are there less scary Ruby bindings (and Hello World examples) available?
Edit: The GTK+ Language Bindings overview does not leave much room for hope.

After a quick chat on #ruby on freenode I learned that there are bindings for GTK+ 3 that are actively developmented:
https://github.com/mvz/ruby-gir-ffi
The project is still young. I'm looking forward to diving in and seeing what I can do too. Here's an introduction by the author: http://www.matijs.net/blog/2011/05/10/girffi-an-introduction

Right now there are gtk3 bindings. In fact there is a rubygem for gtk3. Just do:
$gem install gtk3

Ruby-GNOME2
Supports GTK+ 3 from version 1.2, released in January 2013.

Currently the Ruby Gnome project is only on GTK 2 but work has begun on GTK3 bindings. Take a look at this post on the Ruby Gnome2 forum: http://www.ruby-forum.com/topic/2715042#new (5th one down).
The project website has plenty of tutorials: http://ruby-gnome2.sourceforge.jp/
Installing it is pretty simple on Ubuntu:
sudo apt-get install libgtk2.0-dev
gem install gtk2
I'd start with this and move to GTK3 when there are stable bindings.
Ruby GIR bindings is interesting and I'll be keeping an eye on this but I don't think it'll be as simple to use as Ruby Gnome 2.

I don't know the situation around GNOME 3, sorry. But I do know the situation around KDE and QtRuby. Next stable release of KDE (in July) will contain updated version of QtRuby (it's in active development for now). You could try to start from now, but as for me, well, I'm waiting for the new version because of lack of some features, that I personally need.
There are some helpful IRC channels at Freenode, where you can ask for help: #qtruby, #kde-ruby, #kde-bindings.

Right now the main ruby-gnome project has no GTK 3 bindings.
The problem is lack of manpower.

Related

Packaging ruby gtk app

What is the least headache technique to package a gtk2/gtk3 app built with ruby for distribution as an executable, for windows, linux, macos?
I could not find any guides or helpers to resolve this for ruby gtk. Nor the ruby-gnome gem comes with a packager.
It is my understanding that gtk is cross-platform, so it should not be trivial to do this. Problem is I am unable to find anythin reliable to follow as an example and learn the steps.
I've come across the same problem as you and I've put the question directly to the GTK3 developers.
here is their answer.
Which means that if you choose to use GTK3 today with Ruby, you have to:
Deliver MSYS2 and Ruby with your GEM.
Deliver your gem and tell users to install themselves msys2 (with updates) and ruby and your gem with dependencies.
It seems that the core developers of ruby-gnome2 are unconcerned about app distribution outside the Ruby community.
For example, Mr. Sutou, one of the maintainers of ruby-gnome2, distributes his Ruby/Gtk presentation tool "Rabbit" only as a Ruby Gem.

Does QtRuby work with Qt 5?

Everything I can find online about QtRuby uses Qt 4, but the current version of Qt is 5. Is this simply a matter of documentation not catching up with reality, where Qt 5 would work just fine with QtRuby?
If you assert that this is the case (that Qt5 is unsupported) then please backup your assertion with evidence.
QtRuby
Qtruby and korundum are not maintained for years now. To get a maintained version of qtruby, install qtbindings as ruby gem.
Qtbindings home page: https://github.com/ryanmelt/qtbindings/
Also see https://github.com/ryanmelt/qtbindings/issues/131 for a discussion about supporting Qt5.
Ruby-QML
Ruby-qml is a QML / Qt Quick wrapper for Ruby. It provides bindings between QML and Ruby and enables you to use Qt5 Quick-based GUI from Ruby.
The bindings provided by Ruby-QML are much leaner in comparison to QtRuby. In particular there is no direct access to the Qt classes' methods. That might first seem to be a a disadvantage when coming from QtRuby.
When learning to use use Ruby-QML, it turns out quickly that the advantages outweigh the limitations:
QML and JS greatly complement to describe and model the static and dynamic aspects of the UI
The user community of QML/JS is huge. It is so much easier to find examples or help to solve QML/JS issues, than it was within the tiny QT/Ruby community.
The examples on Ruby-qml are pretty much complete to demonstrate the constructs needed to get started.
JS may be used as flexible 'glue logic' between Ruby and Qt.
QtRuby only supports Qt 4 for the time being. Hopefully, it will change soon, but this seems to be the reality at the time of writing this.
The last release happened two and half a years ago as the time of writing this. That can be seen here:
http://rubyforge.org/projects/korundum/
As you can see, that is also a Qt 4 release as its name says: qt4-qtruby-2.2.0.
That information is also getting from their outdated KDE Wiki in here:
http://techbase.kde.org/Development/Languages/Ruby
If this is still not enough proof, you can look into the code yourself to see it is not actually binding Qt 5 classes added in that major Qt variant.
Here is a quick ls after decompressing the latest tarball:
lpapp ~/Downloads/qt4-qtruby-2.2.0/qtruby/src/lib $ ls
CMakeLists.txt Qt Qt.rb Qt3.rb Qt4.rb

How can I create debian package (*.deb) from ruby application written with qt4?

I found a lot of tutorials how to build application with Ruby and Qt, but i have no idea how anybody else will be able to run it! I am using Ubuntu 11.10, ruby 1.9.2 with rvm and:
rbqtapi -v output "QtRuby 2.0.5 using Qt-4.7.4"
P.S. I have no idea how to build *.deb, it will be my first desktop app, not web.
please have a look on http://shoesrb.com/ this is the best way I heard off for writing GUI apps.
Shoes has now not it's greatest time, but we put our best time to make it better, give it a try and someone will help you.
In case you are in need of assistance just ask as question on #shoes IRC channel on freenode servers.
If you're sold on QT, then you will need your users to install all the support libraries for QT (and anything else), then you can upload a rubygem to rubygems.org for your users to download.
Once, they've installed the support libraries, you'd only need to update your rubygem, which is fairly quick and easy for updates.
You may also wan to look at visualruby. It uses GTK. Then you'd install the GTK libraries instead of the QT ones.
http://www.visualruby.net
As far as .deb packages go, I tried to research the same thing with little success. The rubygems packaging system is designed to distribute ruby programs, so it is the best way to go. Also, you'll need to install different support libraries for different platforms. If you look at visualruby's install page, you can see how to install GTK for Linux and Windows.
Good Luck.

Ruby GNOME GUIs

With the recent release of GNOME 3 and Ubuntu moving to Unity, what toolkit should rubyists be using to develop their apps? I know that there are bindings to GTK2, are these still ok to use?
It is still OK to use the GTK 2 bindings - GTK 2 and 3 will be installed in parallel on most desktop distributions for several years yet. That said, you should keep in mind while you're writing your application that you should update it to GTK 3 when those bindings become prevalent. Take a look at the differences between GTK 2 and 3 and don't write code that will be hard to port when the time comes.
Take a look at visualruby. It uses GTK2, which has been around for a while, so its stable. Its specifically designed for making ruby GUIs:
http://visualruby.net
I've heard good things about ruby shoes although never tried it myself. Maybe you should check it out?

Learning GUI programming with GTK+2 or GTK+3?

I am new to GUI programming, and I haven't found yet what library is best for my purpose (i want to make desktop environment applications, eg. docks, panels, desklets etc.)
I have started learning basics of GTK, mainly using PyGtk. Most tutorials i found on line are for GTK+2.0. Recently however, GTK+3 has been released. So i am a bit unsure as to what that means for my learning curve:
Should i learn using GTK+3 and forget about GTK+2?
Does using one or the other really makes a difference from the point of view of coding?
Are there PyGTK bindings for GTK+3 already?
Is there any available tutorial for GTK+3?
Since i'm new to this, i'm throwing myself into it blindly, but a bit of guidance may be wiser. So if you have any, you're welcome :)
Definitely go with GTK 3. The 10-minute tutorials on http://developer.gnome.org/ use GTK 3 and are an excellent introduction to programming with GTK in several languages, including Python. In the coming months you will probably see more tutorials appear for GTK 3, and in the meantime, you will still be able to get most tutorials for GTK 2 to work with a minimum of fuss. The basics aren't all that different.
Although late, I would like to share this information in the hope that it will be useful for anyone who have this doubt in future.
As ptomato said, GTK+ 3 is the way to go and much of the GTK+2 knowledge is applicable to GTK+3 also. PyGObject is the way to go with GTK+3, not PyGTK. See: PyGTK, GObject, and GNOME 3 to get an overall idea about this new change.
To know what differs and how to cope up with these changes, see:
Migrating from GTK+ 2.x to GTK+ 3
Porting Documentation
About the tutorials, following ones will be of helpful:
The Python GTK+ 3 Tutorial
GNOME Developer Platform Demos
Screen-casts by daniel g. siegel
GTK+ 3 Reference Manual

Resources