Note that there are some explanatory texts on larger screens.

plurals
  1. POruby glade3/gtkbuilder example
    primarykey
    data
    text
    <p>I'm trying to use glade3 with Ruby, but unfortunately examples of this are few and far between. Looking at what's available, I've come up with the following code, but there's still something missing, as the window does not display. There doesn't seem to be any GtkBuilder 'show' method, so I'm not sure what's needed to make it appear. Does anyone know what I need to do to make this work?</p> <p>"hello.xml" is just a fairly simple glade3 xml file with a GtkWindow and a button.</p> <pre><code>#!/usr/bin/env ruby require 'rubygems' require 'gtk2' class HelloGlade attr :glade def initialize if __FILE__ == $0 Gtk.init builder = Gtk::Builder::new builder.add_from_file("hello.xml") builder.connect_signals{ |handler| method(handler) } # (I don't have any handlers yet, but I will have eventually) Gtk.main() end end def gtk_main_quit puts "Gtk.main_quit" Gtk.main_quit() end end hello = HelloGlade.new </code></pre> <p>hello.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;interface&gt; &lt;requires lib="gtk+" version="2.24"/&gt; &lt;!-- interface-naming-policy project-wide --&gt; &lt;object class="GtkWindow" id="window1"&gt; &lt;property name="can_focus"&gt;False&lt;/property&gt; &lt;child&gt; &lt;object class="GtkButton" id="button1"&gt; &lt;property name="label" translatable="yes"&gt;button&lt;/property&gt; &lt;property name="visible"&gt;True&lt;/property&gt; &lt;property name="can_focus"&gt;True&lt;/property&gt; &lt;property name="receives_default"&gt;True&lt;/property&gt; &lt;property name="use_action_appearance"&gt;False&lt;/property&gt; &lt;/object&gt; &lt;/child&gt; &lt;/object&gt; &lt;/interface&gt; </code></pre> <p>(edit)</p> <p>Ugh, it's always the way. Post a question, and I figure out the answer for myself. I needed to get the window1 object from the GtkBuilder, and call its show() method:</p> <pre><code>... window = builder.get_object("window1") window.show() Gtk.main </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload