<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: glade code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 27 Jul 2008 03:28:34 GMT</pubDate>
    <description>DZone Snippets: glade code</description>
    <item>
      <title>A Glade 'Hello World' application</title>
      <link>http://snippets.dzone.com/posts/show/5251</link>
      <description>- getting started - (Using Ubuntu Linux 7.10)&lt;br /&gt;1) Installed glade-3,libglade2-ruby&lt;br /&gt;2) Executed glade-3&lt;br /&gt;&lt;br /&gt;- Within glade-3 -&lt;br /&gt;1) Selected from the glade-3 top menu View -&gt; Palette appearance -&gt; Text beside icons&lt;br /&gt;2) Created a window (Toplevels)&lt;br /&gt;3) Created a button on the window (Control and Display)&lt;br /&gt;3) With button selected, from the properties panel I selected the Signals tab and chose 'clicked', then for the Handler -&gt; on_button1_clicked and pressed enter.&lt;br /&gt;4) With window select, from the properties panel I select the Signals tab and chose GtkWidget-&gt;delete-event, then for the Handler I typed on_quit and pressed enter.&lt;br /&gt;&lt;br /&gt;- Generating and editing the code&lt;br /&gt;&lt;br /&gt;-- From the command line -&lt;br /&gt;1) Typed ruby-glade-create-template helloworld3.glade &gt; helloworld3.rb&lt;br /&gt;&lt;br /&gt;-- From the file helloworld3.rb - (see helloworld3.rb and how it relates to helloworld3.glade)&lt;br /&gt;1) Implemented the initialise window routine&lt;br /&gt;2) Implemented the button event handler&lt;br /&gt;&lt;br /&gt;- Running the application&lt;br /&gt;1) From the command line I typed ruby helloworld3.rb&lt;br /&gt;2) stretched the window to a comfortable dimension.&lt;br /&gt;3) clicked the button and observed the Window title change to 'Hello World!'&lt;br /&gt;&lt;br /&gt;file: helloworld3.glade&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/env ruby&lt;br /&gt;#&lt;br /&gt;# This file is generated by ruby-glade-create-template 1.1.4.&lt;br /&gt;#&lt;br /&gt;require 'libglade2'&lt;br /&gt;&lt;br /&gt;class Helloworld3Glade&lt;br /&gt;  include GetText&lt;br /&gt;&lt;br /&gt;  attr :glade&lt;br /&gt;  &lt;br /&gt;  def initialize(path_or_data, root = nil, domain = nil, localedir = nil, flag = GladeXML::FILE)&lt;br /&gt;    bindtextdomain(domain, localedir, nil, "UTF-8")&lt;br /&gt;    @glade = GladeXML.new(path_or_data, root, domain, localedir, flag) {|handler| method(handler)}&lt;br /&gt;    @window1 = @glade.get_widget("window1") # hand coded&lt;br /&gt;    @window1.show # hand coded      &lt;br /&gt;  end&lt;br /&gt;  &lt;br /&gt;  def on_button1_clicked(widget)&lt;br /&gt;    #puts "on_button1_clicked() is not implemented yet." # removed this code by hand&lt;br /&gt;    @window1.title = 'Hello World!' # hand coded  &lt;br /&gt;  end&lt;br /&gt;  def on_quit(widget, arg0)&lt;br /&gt;    #puts "on_quit() is not implemented yet." # removed this code by hand&lt;br /&gt;    Gtk.main_quit # hand coded&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;# Main program&lt;br /&gt;if __FILE__ == $0&lt;br /&gt;  # Set values as your own application. &lt;br /&gt;  PROG_PATH = "helloworld3.glade"&lt;br /&gt;  PROG_NAME = "YOUR_APPLICATION_NAME"&lt;br /&gt;  Helloworld3Glade.new(PROG_PATH, nil, PROG_NAME)&lt;br /&gt;  Gtk.main&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;file: helloworld3.glade&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;?xml version="1.0" encoding="UTF-8" standalone="no"?&gt;&lt;br /&gt;&lt;!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd"&gt;&lt;br /&gt;&lt;!--Generated with glade3 3.4.0 on Tue Mar 18 17:39:53 2008 --&gt;&lt;br /&gt;&lt;glade-interface&gt;&lt;br /&gt;  &lt;widget class="GtkWindow" id="window1"&gt;&lt;br /&gt;    &lt;property name="events"&gt;GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK&lt;/property&gt;&lt;br /&gt;    &lt;signal name="delete_event" handler="on_quit"/&gt;&lt;br /&gt;    &lt;child&gt;&lt;br /&gt;      &lt;widget class="GtkButton" id="button1"&gt;&lt;br /&gt;        &lt;property name="visible"&gt;True&lt;/property&gt;&lt;br /&gt;        &lt;property name="can_focus"&gt;True&lt;/property&gt;&lt;br /&gt;        &lt;property name="receives_default"&gt;True&lt;/property&gt;&lt;br /&gt;        &lt;property name="events"&gt;GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK&lt;/property&gt;&lt;br /&gt;        &lt;property name="label" translatable="yes"&gt;button&lt;/property&gt;&lt;br /&gt;        &lt;property name="response_id"&gt;0&lt;/property&gt;&lt;br /&gt;        &lt;signal name="clicked" handler="on_button1_clicked"/&gt;&lt;br /&gt;      &lt;/widget&gt;&lt;br /&gt;    &lt;/child&gt;&lt;br /&gt;  &lt;/widget&gt;&lt;br /&gt;&lt;/glade-interface&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;</description>
      <pubDate>Tue, 18 Mar 2008 19:29:06 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5251</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
  </channel>
</rss>
