Last active
November 4, 2019 19:11
-
-
Save gpr/3512c3e66022249c833f to your computer and use it in GitHub Desktop.
How to use Glade resource with Ruby Gtk3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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
Thanks for doing this.Very helpful.