Create a gist now

Instantly share code, notes, and snippets.

@gpr /gui.rb
Last active Mar 26, 2017

What would you like to do?
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