Sunday, February 14, 2016

Building Ruby App using GTK3 with Glade3 on Linux Mint 17.2

I have created a simple ruby program using gtk3 with Glade3.

1. References

Installing GTK3 on Linux
Installing Glade3 on Linux
How to use Glade resource with Ruby Gtk3

2. Create a Glade file

I have created a simple Glade file. For this simple test, I just added a main window ('window1') and specified a signal handler ('quit') for destroy event of the main window.

3. Write a Ruby code using the glade file

Here is my ruby program that load the glade file that I created above and use it for user interface.
(1) Create a Gtk Builder object ('')
(2) Attach ui elements by loading the glade file ('add_from_file')
(3) Connect all signals to their handlers ('connect_signals {...}')
(4) Define signal handler method ('quit')
(5) Get object id for main window ('get_object')
(6) Show all widgets of the main window ('show')
(7) Finally call main loop ('Gtk.main')


4. Run the ruby program

$ ruby glade_test.rb

5. Display

Here is the window that this Ruby program displays.

6. Conclusion

I found it extremely difficult to find good tutorials or sample codes that use GTK3, especially ones with Glade3. Luckily I found one small sample codes by Gregory Romé. It turned out to be quite simple to load a glade (xml) file and use it.

Saturday, February 6, 2016

Installing Glade3 on Linux Mint 17.2

I have installed Glade3 on my Linux Mint 17.2.

1. Using Synaptic Package Manager

I used Synaptic Package Manager to install Glade.

2. Related packages installed automatically

The following two packages were installed automatically when installing Glade (3.16.10).
  • libgladeui-2-6
  • libgladeui-common

3. After Installation

Glade item appears in Menu under the Programming group

4. Test Launching Glade

5. Conclusion

Installing Glade3 on my Linux Mint 17.2 was simple and easy.

Installing gtk3 on Linux Mint 17.2

1. Check my ruby installation (Looks good)

$ ruby -v
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]

2. Check if gtk3 is already installed (Not installed yet)

$ gem list gtk3

*** LOCAL GEMS ***


3. Check available gtk3 gems (Found one)

$ gem list gtk3 --remote


gtk3 (3.0.7 ruby x64-mingw32 x86-mingw32)
gtk3app (1.5.1)
gtk3assist (0.0.9)
gtk3webtable (0.0.0)

4. Install gtk3

$ gem install gtk3
11 gems installed

5. Test the installation (Works!)

$ irb
irb(main):001:0> require 'gtk3'  => True
irb(main):002:0> win =
irb(main):003:0> win.signal_connect("destroy") { Gtk::main_quit }
irb(main):004:0> win.show_all
irb(main):005:0> Gtk.main      # see below

6. Result (An empty window)

7. Conclusion

Installing gtk3 on my Mint 17.2 (with Ruby 2.2) was easy and flawless.