Skip to content

Instantly share code, notes, and snippets.

@arjunmenon
Forked from gpr/gui.rb
Created August 17, 2016 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arjunmenon/03ac68d410f3d4370cae489062ef1521 to your computer and use it in GitHub Desktop.
Save arjunmenon/03ac68d410f3d4370cae489062ef1521 to your computer and use it in GitHub Desktop.
How to use Glade resource with Ruby Gtk3
#!/usr/bin/env ruby
require 'gtk3'
def not_yet_implemented(object)
puts "#{object.class.name} sent a signal!"
end
def on_main_window_destroy(object)
Gtk.main_quit()
end
main_window_res = 'main_window.xml'
builder = Gtk::Builder.new
builder.add_from_file(main_window_res)
# Attach signals handlers
builder.connect_signals do |handler|
begin
method(handler)
rescue
puts "#{handler} not yet implemented!"
method('not_yet_implemented')
end
end
main_window = builder.get_object('main_window')
main_window.show()
Gtk.main
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.16.1 -->
<interface>
<requires lib="gtk+" version="3.10"/>
<object class="GtkWindow" id="main_window">
<property name="width_request">100</property>
<property name="height_request">40</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<signal name="destroy" handler="on_main_window_destroy" swapped="no"/>
<child>
<object class="GtkButton" id="button">
<property name="label">gtk-execute</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
<signal name="clicked" handler="on_button_clicked" swapped="no"/>
</object>
</child>
</object>
</interface>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment