Skip to content

Instantly share code, notes, and snippets.

@Kiirani

Kiirani/test.rb Secret

Last active December 14, 2015 23:58
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 Kiirani/2db1b3d715ab15a1ae48 to your computer and use it in GitHub Desktop.
Save Kiirani/2db1b3d715ab15a1ae48 to your computer and use it in GitHub Desktop.
example of using ruby and gtkbuilder together
#!/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
<?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