simple_ruby_gui 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,11 @@
1
+
2
+ class DataObject
3
+
4
+ def initialize(name, address, email, phone)
5
+ @name = name
6
+ @address = address
7
+ @email = email
8
+ @phone = phone
9
+ end
10
+
11
+ end
@@ -0,0 +1,41 @@
1
+ ##
2
+ # This demonstrates how you can easily add a GUI to any ruby class.
3
+ # The class DataObject holds all the logic for the class and
4
+ # DataObjectGUI holds all the GUI elements. This is a very good
5
+ # way to use visualruby because it keeps your code organized.
6
+ #
7
+ # Also, you can easily add a GUI to any of your existing ruby classes by
8
+ # simply making a class, MyClassGUI, that is a subclass of your existing class.
9
+ #
10
+ # In this example, I've added a button to the glade form with the name, "buttonShow.'
11
+ # The button's "clicked" signal (see 'signal' tab in glade) is set to
12
+ # "buttonShow_clicked." That means when the user clicks the button,
13
+ # the method "buttonShow_clicked" will be called in this file. You can see
14
+ # the code below.
15
+ #
16
+ # Notice that in glade, the entry fields are named:
17
+ #
18
+ # DataObjectGUI.name
19
+ # DataObjectGUI.address ...etc.
20
+ #
21
+ # This is so that set_glade_all() and get_glade_all() will be able to map them to
22
+ # the instance variables.
23
+ #
24
+
25
+ class DataObjectGUI < DataObject
26
+
27
+ include GladeGUI
28
+
29
+ def show()
30
+ load_glade(__FILE__) #loads file, glade/DataObjectGUI.glade into @builder
31
+ set_glade_all() #populates glade controls with insance variables from DataObject
32
+ show_window()
33
+ end
34
+
35
+ def buttonShow_clicked
36
+ get_glade_all() #this sets the instance variables from values in the glade form.
37
+ VR::Dialog.message_box("Curent values:\n\n#{@name}\n#{@address}\n#{@email}\n#{@phone}\n")
38
+ end
39
+
40
+ end
41
+
@@ -0,0 +1,163 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <interface>
3
+ <requires lib="gtk+" version="2.16"/>
4
+ <!-- interface-naming-policy project-wide -->
5
+ <object class="GtkWindow" id="window1">
6
+ <property name="visible">True</property>
7
+ <property name="title" translatable="yes">Basic Object Demo</property>
8
+ <property name="modal">True</property>
9
+ <signal name="destroy" handler="destroy_window"/>
10
+ <child>
11
+ <object class="GtkHBox" id="hbox1">
12
+ <property name="visible">True</property>
13
+ <child>
14
+ <object class="GtkVBox" id="vbox1">
15
+ <property name="visible">True</property>
16
+ <property name="spacing">10</property>
17
+ <child>
18
+ <object class="GtkLabel" id="label5">
19
+ <property name="visible">True</property>
20
+ <property name="label" translatable="yes">&lt;big&gt;&lt;big&gt;Basic Object Demo&lt;/big&gt;&lt;/big&gt;
21
+ This was created with visualruby. See visualruby.net.</property>
22
+ <property name="use_markup">True</property>
23
+ </object>
24
+ <packing>
25
+ <property name="padding">10</property>
26
+ <property name="position">0</property>
27
+ </packing>
28
+ </child>
29
+ <child>
30
+ <object class="GtkTable" id="table1">
31
+ <property name="visible">True</property>
32
+ <property name="n_rows">4</property>
33
+ <property name="n_columns">2</property>
34
+ <property name="column_spacing">7</property>
35
+ <property name="row_spacing">10</property>
36
+ <child>
37
+ <object class="GtkLabel" id="label1">
38
+ <property name="visible">True</property>
39
+ <property name="xalign">1</property>
40
+ <property name="label" translatable="yes">Name:</property>
41
+ </object>
42
+ </child>
43
+ <child>
44
+ <object class="GtkLabel" id="label2">
45
+ <property name="visible">True</property>
46
+ <property name="xalign">1</property>
47
+ <property name="label" translatable="yes">Address:</property>
48
+ </object>
49
+ <packing>
50
+ <property name="top_attach">1</property>
51
+ <property name="bottom_attach">2</property>
52
+ </packing>
53
+ </child>
54
+ <child>
55
+ <object class="GtkLabel" id="label3">
56
+ <property name="visible">True</property>
57
+ <property name="xalign">1</property>
58
+ <property name="label" translatable="yes">Email:</property>
59
+ </object>
60
+ <packing>
61
+ <property name="top_attach">2</property>
62
+ <property name="bottom_attach">3</property>
63
+ </packing>
64
+ </child>
65
+ <child>
66
+ <object class="GtkLabel" id="label4">
67
+ <property name="visible">True</property>
68
+ <property name="xalign">1</property>
69
+ <property name="label" translatable="yes">Phone</property>
70
+ </object>
71
+ <packing>
72
+ <property name="top_attach">3</property>
73
+ <property name="bottom_attach">4</property>
74
+ </packing>
75
+ </child>
76
+ <child>
77
+ <object class="GtkEntry" id="DataObjectGUI.name">
78
+ <property name="visible">True</property>
79
+ <property name="can_focus">True</property>
80
+ <property name="invisible_char">•</property>
81
+ </object>
82
+ <packing>
83
+ <property name="left_attach">1</property>
84
+ <property name="right_attach">2</property>
85
+ </packing>
86
+ </child>
87
+ <child>
88
+ <object class="GtkEntry" id="DataObjectGUI.address">
89
+ <property name="visible">True</property>
90
+ <property name="can_focus">True</property>
91
+ <property name="invisible_char">•</property>
92
+ </object>
93
+ <packing>
94
+ <property name="left_attach">1</property>
95
+ <property name="right_attach">2</property>
96
+ <property name="top_attach">1</property>
97
+ <property name="bottom_attach">2</property>
98
+ </packing>
99
+ </child>
100
+ <child>
101
+ <object class="GtkEntry" id="DataObjectGUI.email">
102
+ <property name="visible">True</property>
103
+ <property name="can_focus">True</property>
104
+ <property name="invisible_char">•</property>
105
+ </object>
106
+ <packing>
107
+ <property name="left_attach">1</property>
108
+ <property name="right_attach">2</property>
109
+ <property name="top_attach">2</property>
110
+ <property name="bottom_attach">3</property>
111
+ </packing>
112
+ </child>
113
+ <child>
114
+ <object class="GtkEntry" id="DataObjectGUI.phone">
115
+ <property name="visible">True</property>
116
+ <property name="can_focus">True</property>
117
+ <property name="invisible_char">•</property>
118
+ </object>
119
+ <packing>
120
+ <property name="left_attach">1</property>
121
+ <property name="right_attach">2</property>
122
+ <property name="top_attach">3</property>
123
+ <property name="bottom_attach">4</property>
124
+ </packing>
125
+ </child>
126
+ </object>
127
+ <packing>
128
+ <property name="position">1</property>
129
+ </packing>
130
+ </child>
131
+ <child>
132
+ <object class="GtkHButtonBox" id="hbuttonbox1">
133
+ <property name="visible">True</property>
134
+ <child>
135
+ <object class="GtkButton" id="buttonShow">
136
+ <property name="label" translatable="yes">Show</property>
137
+ <property name="visible">True</property>
138
+ <property name="can_focus">True</property>
139
+ <property name="receives_default">True</property>
140
+ <signal name="clicked" handler="buttonShow_clicked"/>
141
+ </object>
142
+ <packing>
143
+ <property name="expand">False</property>
144
+ <property name="fill">False</property>
145
+ <property name="position">0</property>
146
+ </packing>
147
+ </child>
148
+ </object>
149
+ <packing>
150
+ <property name="padding">10</property>
151
+ <property name="position">2</property>
152
+ </packing>
153
+ </child>
154
+ </object>
155
+ <packing>
156
+ <property name="padding">15</property>
157
+ <property name="position">0</property>
158
+ </packing>
159
+ </child>
160
+ </object>
161
+ </child>
162
+ </object>
163
+ </interface>
@@ -0,0 +1,16 @@
1
+
2
+ #Global libraries (add your own):
3
+ require 'rubygems'
4
+ require 'gtk2'
5
+ require 'require_all'
6
+ require 'vrlib'
7
+
8
+ #make program output in real time so errors visible in VR.
9
+ STDOUT.sync = true
10
+ STDERR.sync = true
11
+
12
+ #everything in these directories will be included
13
+ my_path = File.expand_path(File.dirname(__FILE__))
14
+ require_all Dir.glob(my_path + "/lib/**/*.rb")
15
+ require_all Dir.glob(my_path + "/bin/**/*.rb")
16
+
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require File.expand_path(File.dirname(__FILE__)) + '/requires.rb'
4
+
5
+ x = DataObjectGUI.new("Harvey Milktoast", "123 Main, Hemet, CA 90090", "harvey@harveyserver.com", "132-243-4323")
6
+ x.show
7
+
8
+
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_ruby_gui
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 3
10
+ version: 0.0.3
11
+ platform: ruby
12
+ authors:
13
+ - Eric Cunningham
14
+ autorequire:
15
+ bindir:
16
+ - .
17
+ cert_chain: []
18
+
19
+ date: 2012-02-29 00:00:00 Z
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: vrlib
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 29
30
+ segments:
31
+ - 0
32
+ - 0
33
+ - 1
34
+ version: 0.0.1
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: gtk2
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 29
46
+ segments:
47
+ - 0
48
+ - 0
49
+ - 1
50
+ version: 0.0.1
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: require_all
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 29
62
+ segments:
63
+ - 0
64
+ - 0
65
+ - 1
66
+ version: 0.0.1
67
+ type: :runtime
68
+ version_requirements: *id003
69
+ description: "This is a simple GUI for a simple ruby class. It demonstrates how easy it is to create GUIs with visualruby. You can try visualruby by going to visualruby.net. There are more examples and tutorials there.\n The best way to install this program is to install visualruby first because it has all the GTK+ graphics packages that this program depends on. Go to visualruby.net to install. After you have visualruby, you can run this program, at the terminal:\n\n\
70
+ $ simple_ruby_gui "
71
+ email: eric@visualruby.net
72
+ executables:
73
+ - simple_ruby_gui
74
+ extensions: []
75
+
76
+ extra_rdoc_files: []
77
+
78
+ files:
79
+ - requires.rb
80
+ - bin/DataObjectGUI.rb
81
+ - bin/DataObject.rb
82
+ - bin/glade/DataObjectGUI.glade
83
+ - ./simple_ruby_gui
84
+ - simple_ruby_gui
85
+ homepage: http://www.visualruby.net/
86
+ licenses: []
87
+
88
+ post_install_message:
89
+ rdoc_options: []
90
+
91
+ require_paths:
92
+ - .
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ hash: 3
99
+ segments:
100
+ - 0
101
+ version: "0"
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ hash: 3
108
+ segments:
109
+ - 0
110
+ version: "0"
111
+ requirements: []
112
+
113
+ rubyforge_project: nowarning
114
+ rubygems_version: 1.8.13
115
+ signing_key:
116
+ specification_version: 3
117
+ summary: Demo of a basic visualruby object. (visualruby.net)
118
+ test_files: []
119
+