- getting started - (Using Ubuntu Linux 7.10)
1) Installed glade-3,libglade2-ruby
2) Executed glade-3
- Within glade-3 -
1) Selected from the glade-3 top menu View -> Palette appearance -> Text beside icons
2) Created a window (Toplevels)
3) Created a button on the window (Control and Display)
3) With button selected, from the properties panel I selected the Signals tab and chose 'clicked', then for the Handler -> on_button1_clicked and pressed enter.
4) With window select, from the properties panel I select the Signals tab and chose GtkWidget->delete-event, then for the Handler I typed on_quit and pressed enter.
- Generating and editing the code
-- From the command line -
1) Typed ruby-glade-create-template helloworld3.glade > helloworld3.rb
-- From the file helloworld3.rb - (see helloworld3.rb and how it relates to helloworld3.glade)
1) Implemented the initialise window routine
2) Implemented the button event handler
- Running the application
1) From the command line I typed ruby helloworld3.rb
2) stretched the window to a comfortable dimension.
3) clicked the button and observed the Window title change to 'Hello World!'
file: helloworld3.glade
1
2
3
4
5
6 require 'libglade2'
7
8 class Helloworld3Glade
9 include GetText
10
11 attr :glade
12
13 def initialize(path_or_data, root = nil, domain = nil, localedir = nil, flag = GladeXML::FILE)
14 bindtextdomain(domain, localedir, nil, "UTF-8")
15 @glade = GladeXML.new(path_or_data, root, domain, localedir, flag) {|handler| method(handler)}
16 @window1 = @glade.get_widget("window1")
17 @window1.show
18 end
19
20 def on_button1_clicked(widget)
21
22 @window1.title = 'Hello World!'
23 end
24 def on_quit(widget, arg0)
25
26 Gtk.main_quit
27 end
28 end
29
30
31 if __FILE__ == $0
32
33 PROG_PATH = "helloworld3.glade"
34 PROG_NAME = "YOUR_APPLICATION_NAME"
35 Helloworld3Glade.new(PROG_PATH, nil, PROG_NAME)
36 Gtk.main
37 end
file: helloworld3.glade
1
2 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
3 <!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
4 <!--Generated with glade3 3.4.0 on Tue Mar 18 17:39:53 2008 -->
5 <glade-interface>
6 <widget class="GtkWindow" id="window1">
7 <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
8 <signal name="delete_event" handler="on_quit"/>
9 <child>
10 <widget class="GtkButton" id="button1">
11 <property name="visible">True</property>
12 <property name="can_focus">True</property>
13 <property name="receives_default">True</property>
14 <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
15 <property name="label" translatable="yes">button</property>
16 <property name="response_id">0</property>
17 <signal name="clicked" handler="on_button1_clicked"/>
18 </widget>
19 </child>
20 </widget>
21 </glade-interface>