-
-
Save Kiirani/2db1b3d715ab15a1ae48 to your computer and use it in GitHub Desktop.
example of using ruby and gtkbuilder together
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 'rubygems' | |
require 'gtk2' | |
def gtk_main_quit | |
puts "Called quit" | |
Gtk.main_quit() | |
end | |
def something | |
puts "I made something happen!" | |
end | |
def zzz | |
Thread.new{ | |
puts "Going to sleep..." | |
sleep 3 | |
puts "Done sleeping!" | |
} | |
end | |
TheGUI = 'test.ui' | |
builder = Gtk::Builder.new | |
builder.add_from_file(TheGUI) | |
builder.connect_signals{|handler| method(handler)} | |
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"?> | |
<interface> | |
<!-- interface-requires gtk+ 3.0 --> | |
<object class="GtkWindow" id="window1"> | |
<property name="visible">True</property> | |
<property name="can_focus">False</property> | |
<property name="default_width">440</property> | |
<property name="default_height">250</property> | |
<signal name="destroy" handler="gtk_main_quit" swapped="no"/> | |
<child> | |
<object class="GtkLayout" id="layout1"> | |
<property name="visible">True</property> | |
<property name="can_focus">False</property> | |
<child> | |
<object class="GtkButton" id="somethingbutton"> | |
<property name="label" translatable="yes">Something!</property> | |
<property name="use_action_appearance">False</property> | |
<property name="width_request">100</property> | |
<property name="height_request">80</property> | |
<property name="visible">True</property> | |
<property name="can_focus">True</property> | |
<property name="receives_default">True</property> | |
<property name="use_action_appearance">False</property> | |
<signal name="clicked" handler="something" swapped="no"/> | |
</object> | |
<packing> | |
<property name="x">151</property> | |
<property name="y">33</property> | |
</packing> | |
</child> | |
<child> | |
<object class="GtkButton" id="quitbutton"> | |
<property name="label" translatable="yes">QUIT</property> | |
<property name="use_action_appearance">False</property> | |
<property name="width_request">100</property> | |
<property name="height_request">80</property> | |
<property name="visible">True</property> | |
<property name="can_focus">True</property> | |
<property name="receives_default">True</property> | |
<property name="use_action_appearance">False</property> | |
<signal name="clicked" handler="gtk_main_quit" swapped="no"/> | |
</object> | |
<packing> | |
<property name="x">21</property> | |
<property name="y">31</property> | |
</packing> | |
</child> | |
<child> | |
<object class="GtkButton" id="sleep"> | |
<property name="label" translatable="yes">zZz</property> | |
<property name="use_action_appearance">False</property> | |
<property name="width_request">100</property> | |
<property name="height_request">80</property> | |
<property name="visible">True</property> | |
<property name="can_focus">True</property> | |
<property name="receives_default">True</property> | |
<property name="use_action_appearance">False</property> | |
<signal name="clicked" handler="zzz" swapped="no"/> | |
</object> | |
<packing> | |
<property name="x">278</property> | |
<property name="y">33</property> | |
</packing> | |
</child> | |
</object> | |
</child> | |
</object> | |
</interface> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment