vr-corelib 0.0.36

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +7 -0
  2. data/Demo.rb +41 -0
  3. data/doc/images/add.png +0 -0
  4. data/doc/images/brick.png +0 -0
  5. data/doc/images/brick_link.png +0 -0
  6. data/doc/images/bug.png +0 -0
  7. data/doc/images/bullet_black.png +0 -0
  8. data/doc/images/bullet_toggle_minus.png +0 -0
  9. data/doc/images/bullet_toggle_plus.png +0 -0
  10. data/doc/images/date.png +0 -0
  11. data/doc/images/delete.png +0 -0
  12. data/doc/images/find.png +0 -0
  13. data/doc/images/macFFBgHack.png +0 -0
  14. data/doc/images/package.png +0 -0
  15. data/doc/images/page_green.png +0 -0
  16. data/doc/images/page_white_text.png +0 -0
  17. data/doc/images/page_white_width.png +0 -0
  18. data/doc/images/plugin.png +0 -0
  19. data/doc/images/ruby.png +0 -0
  20. data/doc/images/tag_blue.png +0 -0
  21. data/doc/images/tag_green.png +0 -0
  22. data/doc/images/transparent.png +0 -0
  23. data/doc/images/wrench.png +0 -0
  24. data/doc/images/wrench_orange.png +0 -0
  25. data/doc/images/zoom.png +0 -0
  26. data/glade/Demo.glade +52 -0
  27. data/img/image-x-generic.png +0 -0
  28. data/lib/Dialog.rb +157 -0
  29. data/lib/GladeGUI.rb +358 -0
  30. data/lib/IconHash.rb +22 -0
  31. data/lib/SimpleComboBoxEntry.rb +14 -0
  32. data/lib/Thread.rb +59 -0
  33. data/lib/Widget.rb +37 -0
  34. data/lib/treeview/FileTreeView.rb +91 -0
  35. data/lib/treeview/IterMethods.rb +82 -0
  36. data/lib/treeview/ListView.rb +90 -0
  37. data/lib/treeview/ModelRow.rb +31 -0
  38. data/lib/treeview/TreeIter.rb +33 -0
  39. data/lib/treeview/TreeView.rb +43 -0
  40. data/lib/treeview/ViewCommon.rb +351 -0
  41. data/lib/treeview/columns/CalendarCol.rb +88 -0
  42. data/lib/treeview/columns/CellRendererCombo.rb +66 -0
  43. data/lib/treeview/columns/CellRendererDate.rb +45 -0
  44. data/lib/treeview/columns/CellRendererObject.rb +57 -0
  45. data/lib/treeview/columns/CellRendererPhone.rb +45 -0
  46. data/lib/treeview/columns/CellRendererPixbuf.rb +16 -0
  47. data/lib/treeview/columns/CellRendererProgress.rb +17 -0
  48. data/lib/treeview/columns/CellRendererSpin.rb +37 -0
  49. data/lib/treeview/columns/CellRendererText.rb +38 -0
  50. data/lib/treeview/columns/CellRendererToggle.rb +47 -0
  51. data/lib/treeview/columns/ComboCol.rb +43 -0
  52. data/lib/treeview/columns/CurrencyCol.rb +23 -0
  53. data/lib/treeview/columns/DateCol.rb +20 -0
  54. data/lib/treeview/columns/ImageCol.rb +30 -0
  55. data/lib/treeview/columns/ProgressCol.rb +27 -0
  56. data/lib/treeview/columns/SpinCol.rb +11 -0
  57. data/lib/treeview/columns/TextCol.rb +64 -0
  58. data/lib/treeview/columns/TreeViewColumn.rb +108 -0
  59. data/lib/treeview/columns/glade/CalendarCol.glade +133 -0
  60. data/lib/treeview/columns/glade/ImageCol.glade +16 -0
  61. data/lib/treeview/columns/glade/TextCol.glade +77 -0
  62. data/main.rb +3 -0
  63. data/vr-corelib.rb +7 -0
  64. data/vrlib.rb +7 -0
  65. metadata +138 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 72378b086e397a855e84859aa56f6fd688efc2b7
4
+ data.tar.gz: abaa10d0bb20c79fd0b35fce6ebbeb43694a31ec
5
+ SHA512:
6
+ metadata.gz: 45e40d50ebe36c3f2b378005b415d0bf5de1a6eb210064170e84fd44f06a9ba27fdd26091ef3b44457e601040b4537a2cc6766c711c5ad0f99116f676e251d18
7
+ data.tar.gz: 3a24d1054b5dc9ffed0173150ba46b3dc950cb1fecc6076a726ac80f68c5361f42701ee2e1823c8efe6870955731041167894a98bbfe479d5ae017e2ef9ea99a
data/Demo.rb ADDED
@@ -0,0 +1,41 @@
1
+ #require 'vrlib.rb'
2
+ # :nodoc: all
3
+
4
+
5
+
6
+ class Demo # :nodoc:
7
+
8
+
9
+ include GladeGUI
10
+
11
+ def show()
12
+
13
+ @view = VR::FileTreeView.new("/home/eric/vrp/vrx/img")
14
+ # r = @view.add_row()
15
+ # r[0] = Gtk::Adjustment.new(0.to_i,0,100,1,10,0)
16
+ # r[0] = combo
17
+ load_glade(__FILE__)
18
+ @view.refresh
19
+
20
+ @builder["scrolledwindow1"].add_child(@builder, @view)
21
+ @builder["window1"].resize 700, 500
22
+
23
+ show_window()
24
+
25
+ end
26
+
27
+ def but__clicked(button)
28
+ VR::Dialog.message_box("clicked")
29
+ end
30
+
31
+ def button1__clicked(button)
32
+ VR::Dialog.message_box("clicked")
33
+ end
34
+
35
+ def view__row_activated(x,y,z)
36
+ VR::Dialog.message_box("row activated new!")
37
+ end
38
+
39
+ end
40
+
41
+ Demo.new.show
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,52 @@
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">Demo crap</property>
8
+ <property name="modal">True</property>
9
+ <signal name="destroy" handler="destroy_window"/>
10
+ <child>
11
+ <object class="GtkVBox" id="vbox1">
12
+ <property name="visible">True</property>
13
+ <child>
14
+ <object class="GtkScrolledWindow" id="scrolledwindow1">
15
+ <property name="visible">True</property>
16
+ <property name="can_focus">True</property>
17
+ <property name="hscrollbar_policy">automatic</property>
18
+ <property name="vscrollbar_policy">automatic</property>
19
+ <child>
20
+ <placeholder/>
21
+ </child>
22
+ </object>
23
+ <packing>
24
+ <property name="position">0</property>
25
+ </packing>
26
+ </child>
27
+ <child>
28
+ <object class="GtkButton" id="button1">
29
+ <property name="label" translatable="yes">button</property>
30
+ <property name="visible">True</property>
31
+ <property name="can_focus">True</property>
32
+ <property name="receives_default">True</property>
33
+ </object>
34
+ <packing>
35
+ <property name="position">1</property>
36
+ </packing>
37
+ </child>
38
+ <child>
39
+ <object class="GtkButton" id="but[3]">
40
+ <property name="label" translatable="yes">button</property>
41
+ <property name="visible">True</property>
42
+ <property name="can_focus">True</property>
43
+ <property name="receives_default">True</property>
44
+ </object>
45
+ <packing>
46
+ <property name="position">2</property>
47
+ </packing>
48
+ </child>
49
+ </object>
50
+ </child>
51
+ </object>
52
+ </interface>
Binary file
@@ -0,0 +1,157 @@
1
+ module VR
2
+
3
+ def VR.msg(*a) Dialog.message_box(*a) end
4
+
5
+ module Dialog
6
+
7
+ # def Dialog.calendar(datetime)
8
+ # dialog = Gtk::Dialog.new(
9
+ # "Select Date", nil,
10
+ # Gtk::Dialog::MODAL,
11
+ # [Gtk::Stock::OK, Gtk::Dialog::RESPONSE_ACCEPT],
12
+ # [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_REJECT])
13
+ # c = Gtk::Calendar.new
14
+ # c.select_month(datetime.month, datetime.year)
15
+ # c.select_day(datetime.day)
16
+ # c.mark_day(datetime.day)
17
+ # dialog.vbox.add(c)
18
+ # dialog.show_all
19
+ # ret = dialog.run == Gtk::Dialog::RESPONSE_ACCEPT ? DateTime.new(*c.date) : nil
20
+ # dialog.destroy
21
+ # return ret
22
+ # end
23
+
24
+ def Dialog.message_box(message, title = "Visual Ruby")
25
+ dialog = Gtk::MessageDialog.new(
26
+ nil,
27
+ Gtk::Dialog::MODAL,
28
+ Gtk::MessageDialog::INFO,
29
+ Gtk::MessageDialog::BUTTONS_OK,
30
+ message)
31
+ dialog.title = title
32
+ dialog.show_all
33
+ dialog.run
34
+ dialog.destroy
35
+ end
36
+
37
+ def Dialog.input_box(message, default="", title = "Visual Ruby")
38
+ dialog = Gtk::MessageDialog.new(
39
+ nil,
40
+ Gtk::Dialog::MODAL,
41
+ Gtk::MessageDialog::QUESTION,
42
+ Gtk::MessageDialog::BUTTONS_OK_CANCEL,
43
+ message)
44
+ dialog.title = title
45
+ input = Gtk::Entry.new
46
+ dialog.vbox.add(input)
47
+ dialog.show_all
48
+ ret = ""
49
+ dialog.run do |response|
50
+ if response == Gtk::Dialog::RESPONSE_OK
51
+ ret = input.buffer.text
52
+ else
53
+ ret = false
54
+ end
55
+ end
56
+ dialog.destroy
57
+ return ret
58
+ end
59
+
60
+ def Dialog.ok_box(message, title = "Visual Ruby")
61
+ dialog = Gtk::MessageDialog.new(
62
+ nil,
63
+ Gtk::Dialog::MODAL,
64
+ Gtk::MessageDialog::QUESTION,
65
+ Gtk::MessageDialog::BUTTONS_OK_CANCEL,
66
+ message)
67
+ dialog.title = title
68
+ ret = (dialog.run == Gtk::Dialog::RESPONSE_OK)
69
+ dialog.destroy
70
+ return ret
71
+ end
72
+
73
+ def Dialog.folder_box(builder)
74
+ dialog = Gtk::FileChooserDialog.new("Select Folder...",
75
+ builder['window1'],
76
+ Gtk::FileChooser::ACTION_SELECT_FOLDER,
77
+ nil,
78
+ [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL],
79
+ [Gtk::Stock::OPEN, Gtk::Dialog::RESPONSE_ACCEPT])
80
+
81
+ # if pattern != nil
82
+ # filter = Gtk::FileFilter.new
83
+ # filter.add_pattern(pattern)
84
+ # filter.name = "VR Project Folders"
85
+ # dialog.add_filter(filter)
86
+ # end
87
+ if dialog.run == Gtk::Dialog::RESPONSE_ACCEPT
88
+ ret = dialog.current_folder
89
+ else
90
+ ret = false
91
+ end
92
+ dialog.destroy
93
+ return ret
94
+ end
95
+ end
96
+
97
+ def Dialog.yesno(message, title = "Visual Ruby")
98
+ dialog = Gtk::MessageDialog.new(
99
+ nil,
100
+ Gtk::Dialog::MODAL,
101
+ Gtk::MessageDialog::QUESTION,
102
+ Gtk::MessageDialog::BUTTONS_YES_NO,
103
+ message)
104
+ dialog.title = title
105
+ ret = (dialog.run == Gtk::Dialog::RESPONSE_YES)
106
+ dialog.destroy
107
+ return ret
108
+ end
109
+
110
+ def Dialog.userpass(message, title = "Visual Ruby")
111
+ dialog = Gtk::Dialog.new(
112
+ title,
113
+ nil,
114
+ Gtk::Dialog::MODAL,
115
+ [Gtk::Stock::OK,Gtk::Dialog::RESPONSE_ACCEPT],
116
+ [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_REJECT])
117
+ dialog.vbox.add(Gtk::Label.new(message))
118
+ hbox = Gtk::HBox.new
119
+ hbox.add(Gtk::Label.new("Username:"))
120
+ hbox.add(user = Gtk::Entry.new)
121
+ dialog.vbox.add(hbox)
122
+ hbox = Gtk::HBox.new
123
+ hbox.add(Gtk::Label.new("Password:"))
124
+ hbox.add(pass = Gtk::Entry.new)
125
+ dialog.vbox.add(hbox)
126
+ pass.visibility = false
127
+ ret = (dialog.run == Gtk::Dialog::RESPONSE_ACCEPT) ? {:user => user.text, :pass => pass.text } : nil
128
+ dialog.destroy
129
+ return ret
130
+ end
131
+
132
+ def Dialog.listbox(message,list,title="Visual Ruby",icon=Gtk::Stock::DIALOG_QUESTION)
133
+ dialog = Gtk::Dialog.new(
134
+ title,
135
+ nil,
136
+ Gtk::Dialog::MODAL,
137
+ [Gtk::Stock::YES, Gtk::Dialog::RESPONSE_ACCEPT],
138
+ [Gtk::Stock::NO,Gtk::Dialog::RESPONSE_REJECT])
139
+ hbox = Gtk::HBox.new
140
+ hbox.add(Gtk::Image.new(icon,Gtk::IconSize::DIALOG))
141
+ hbox.add(Gtk::Label.new(message))
142
+ dialog.vbox.add(hbox)
143
+ vrlist = VR::ListView.new({:item=>String})
144
+ list.each do |entry|
145
+ vrlist.add_row(:item => entry)
146
+ end
147
+ vrlist.headers_visible = false
148
+ holder = Gtk::ScrolledWindow.new
149
+ holder.add(vrlist)
150
+ dialog.vbox.add(holder)
151
+ dialog.vbox.show_all
152
+ ret = (dialog.run == Gtk::Dialog::RESPONSE_ACCEPT)
153
+ dialog.destroy
154
+ return ret
155
+ end
156
+
157
+ end
@@ -0,0 +1,358 @@
1
+ #
2
+ # GladeGUI connects your class to a glade form using
3
+ # the #load_glade(__FILE__) method. It will load a .glade
4
+ # file into memory, enabling your ruby programs to have a GUI interface.
5
+ #
6
+ # GladeGUI works by adding an instance variable, @builder to your class. The @builder
7
+ # variable is an instance of {Gtk::Builder}[http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3ABuilder]
8
+ # It holds references to all your windows and widgets.
9
+ #
10
+ # ==Include the GladeGUI interface
11
+ #
12
+ # To use the GladeGUI interface, include this line after your
13
+ # “class” declaration:
14
+ #
15
+ # include GladeGUI
16
+ #
17
+ # Here is an example of a class that uses GladeGUI:
18
+ #
19
+ # class MyClass
20
+ #
21
+ # include GladeGUI
22
+ #
23
+ # def show()
24
+ # load_glade(__FILE__) #loads file, /glade/MyClass.glade into @builder
25
+ # show_window()
26
+ # end
27
+ #
28
+ # end
29
+ #
30
+ # The load_glade() method is part of GladeGUI. It will load a corresponding
31
+ # glade file for this class. It knows which glade file to load by using a naming
32
+ # convention:
33
+ #
34
+ # /home/me/project/MyClass.rb
35
+ #
36
+ # Will load this glade file:
37
+ #
38
+ # /home/me/project/glade/MyClass.glade
39
+ #
40
+ # Note: it will use this format: /my/path/glade/<class_name>.glade.
41
+ # In the example, the class and the file have the same name,
42
+ # MyClass. You should always name your class, script, and glade file
43
+ # the same name (case sensitive).
44
+ #
45
+ # ==@builder holds all your widgets
46
+ #
47
+ # So when you "load" your class's glade file where is it loaded?
48
+ #
49
+ # GladeGUI adds an instance variable, @builder to your class.
50
+ # It loads all the windows and widgets from your glade file into @builder.
51
+ # So, you use @builder to manipulate everything in you class's GUI.
52
+ # @builder is set when you call the load_glade() method, as this code shows:
53
+ #
54
+ # class MyClass
55
+ #
56
+ # include GladeGUI
57
+ #
58
+ # def show()
59
+ # puts @builder.to_s # => nil
60
+ # load_glade(__FILE__) #loads file, /glade/MyClass.glade into @builder
61
+ # puts @builder.to_s # => Gtk::Builder
62
+ # show_window()
63
+ # end
64
+ #
65
+ # end
66
+ #
67
+ # After load_glade() is called, you can access any of your form's windows or widgets
68
+ # using the @builder variable:
69
+ #
70
+ # @builder["window1"].title = "This is the title that appears at the top."
71
+ #
72
+ # You use the @builder variable to access everything on your form. In the above example,
73
+ # @builder["window1"] is a reference to the main Gtk::Window of your class.
74
+ # Gtk::Window#title sets the title that appears at the top of the
75
+ # window, So, this will set that property.
76
+ #
77
+ # Here's another example: Suppose you have a glade form with a Gtk::Entry box on it named "email."
78
+ # You could set the text that appears in the Gtk::Entry by setting the Gtk::Entry#text property:
79
+ #
80
+ # @builder["email"].text = "harvey@harveyserver.com"
81
+ #
82
+ # Now the email adddess is set with a new value:
83
+ #
84
+ # http://visualruby.net/img/gladegui_simple.jpg
85
+ #
86
+ # ==Auto fill your glade form
87
+ # You can streamline the process of setting-up your forms by
88
+ # auto-filling the widgets from instance variables with the same name.
89
+ #
90
+ # When assigning names to widgets in glade, give them names that
91
+ # correspond to your instance variables. For example, if you want
92
+ # to edit an email address on the glade form, create an instance
93
+ # variable named @email in your class. Then, in glade, you
94
+ # add a Gtk::Entry widget to your form and set its name to
95
+ # “email”. The advantage of this is that GladeGUI will populate
96
+ # the “email” widget in glade using the @email variable. so
97
+ # you don’t need to include the above line of code. (see
98
+ # set_glade_variables() method.)
99
+
100
+
101
+ module GladeGUI
102
+
103
+ attr_accessor :builder
104
+
105
+ def set_parent(parent) # :nodoc: parent = class derived from class GladeGUI
106
+ @builder["window1"].transient_for = parent.builder["window1"]
107
+ end
108
+
109
+ ##
110
+ # This will Load the glade form.
111
+ # It will create a Gtk::Builder object from your glade file.
112
+ # The Gtk::Builder object is stored in the instance variable, @builder.
113
+ # You can get a reference to any of the widgets on the glade form by
114
+ # using the @builder object:
115
+ #
116
+ # widget = @builder["name"]
117
+ #
118
+ # Normally, you should give your widgets names of instance variables: i.e. "MyClass.var"
119
+ # so they can be autoloaded using the set_glade_all() method.
120
+ #
121
+ # You can also pass a reference to a parent class that also includes GladeGUI.
122
+ # Then the child window will run simultaniously with the parent.
123
+ #
124
+
125
+ def load_glade(caller__FILE__, parent = nil)
126
+ file_name = File.split(caller__FILE__)[0] + '/glade/' + class_name(self) + ".glade"
127
+ @builder = Gtk::Builder.new.add_from_file(file_name)
128
+ @builder.connect_signals{ |handle| method(handle) }
129
+ set_parent(parent) unless parent.nil?
130
+ parse_signals()
131
+ end
132
+
133
+ def class_name(obj) # :nodoc:
134
+ /.*\b(\w+)$/.match(obj.class.name)[1]
135
+ end
136
+
137
+ def parse_signals() # :nodoc:
138
+ meths = self.class.instance_methods()
139
+ meths.each do |meth|
140
+ meth = meth.to_s #bug fix ruby 1.9 gives stmbol
141
+ glade_name, signal_name = *(meth.split("__"))
142
+ next if (signal_name.to_s == "" or glade_name.to_s == "") #covers nil
143
+ @builder.objects.each do |obj|
144
+ next unless obj.respond_to?(:builder_name)
145
+ if obj.builder_name == glade_name or obj.builder_name =~ /^(?:#{class_name(self)}\.|)#{glade_name}\[\d+\]$/ #arrays
146
+ obj.signal_connect(signal_name) { |*args| method(meth.to_sym).call(*args) }
147
+ end
148
+ end
149
+ obj = glade_name == "self" ? self : instance_variable_get("@" + glade_name)
150
+ obj ||= eval(glade_name) if respond_to?(glade_name) and method(glade_name.to_sym).arity == 0 # no arguments!
151
+ obj.signal_connect(signal_name) { |*args| method(meth.to_sym).call(*args) } if obj.respond_to?("signal_connect")
152
+ end
153
+ end
154
+
155
+ # This method is the most useful method to populate a glade form. It will
156
+ # populate from active_record fields and instance variables. It will simply
157
+ # call both of these methods:
158
+ #
159
+ # set_glade_active_record()
160
+ # set_glade_variables()
161
+ #
162
+ # So, to set all the values of a form, simply call the set_glade_all() method instead.
163
+
164
+ def set_glade_all(obj = self)
165
+ set_glade_active_record(obj)
166
+ set_glade_variables(obj)
167
+ end
168
+
169
+ # This method is the most useful method to retreive values from a glade form. It will
170
+ # populate from active_record fields and instance variables. It will simply
171
+ # call both of these methods:
172
+ #
173
+ # get_glade_active_record()
174
+ # get_glade_variables()
175
+ #
176
+ # So, to retreive all the values of a form back into your ActiveRecord object and instance variables, simply call the set_glade_all() method instead.
177
+
178
+ def get_glade_all(obj = self)
179
+ get_glade_active_record(obj)
180
+ get_glade_variables(obj)
181
+ end
182
+
183
+ # Populates the glade form from the fields of an ActiveRecord object.
184
+ # So instead of having to assign each widget a value:
185
+ #
186
+ # @builder["ARObject.name"].text = @name
187
+ # @builder["ARObject.address"].text = @address
188
+ # @builder["ARObject.email"].text = @eamil
189
+ # @builder["ARObject.phone"].text = @phone
190
+ #
191
+ # you can write one line of code:
192
+ #
193
+ # set_glade_active_record()
194
+ #
195
+ # The optional parameter is seldom used because you usually want the
196
+ # glade form to populate from the calling class. If you passed another object,
197
+ # the form would populate from it.
198
+ #
199
+ # obj - type ActiveRecord::Base
200
+ #
201
+
202
+ def set_glade_active_record(obj = self)
203
+ return if not defined? @attributes
204
+ obj.attributes.each_pair { |key, val| fill_control(class_name(obj) + "." + key, val) }
205
+ end
206
+
207
+ #Populates the glade form from the instance variables of the class.
208
+ #This works for Gtk:Button, Gtk::Entry, Gtk::Label and Gtk::Checkbutton.
209
+ #So instead of having to assign each widget a value:
210
+ #
211
+ # @builder["DataObjectGUI.name"].text = @name
212
+ # @builder["DataObjectGUI.address"].text = @address
213
+ # @builder["DataObjectGUI.email"].text = @eamil
214
+ # @builder["DataObjectGUI.phone"].text = @phone
215
+ #
216
+ #you can write one line of code:
217
+ #
218
+ # set_glade_variables()
219
+ #
220
+ #The optional parameter is seldom used because you usually want the
221
+ #glade form to populate from the calling class. If you passed another object,
222
+ #the form would populate from it.
223
+ #
224
+ #obj - type Object
225
+ #
226
+
227
+ def set_glade_variables(obj = self)
228
+ obj.instance_variables.each do |name|
229
+ name = name.to_s #ruby 1.9 passes symbol!
230
+ v = obj.instance_variable_get(name)
231
+ if v.class == Array
232
+ (0..v.size-1).each do |i|
233
+ fill_control(class_name(obj) + "." + name.gsub("@", "") + "[" + i.to_s + "]", v[i] )
234
+ end
235
+ else
236
+ fill_control(class_name(obj) + "." + name.gsub("@", ""), v)
237
+ end
238
+ end
239
+ end
240
+
241
+ def fill_control(glade_name, val) # :nodoc:
242
+ control = @builder[glade_name]
243
+ control ||= @builder[glade_name.split(".")[1]]
244
+ case control
245
+ when Gtk::CheckButton then control.active = val
246
+ when Gtk::TextView then control.buffer.text = val.to_s
247
+ when Gtk::Entry then control.text = val.to_s
248
+ when Gtk::FontButton then control.font_name = val.to_s
249
+ when Gtk::LinkButton then control.uri = control.label = val.to_s
250
+ when Gtk::Label, Gtk::Button then control.label = val.to_s
251
+ when Gtk::Image then control.file = val.to_s
252
+ when Gtk::SpinButton then control.value = val.to_f
253
+ when Gtk::ProgressBar then control.fraction = val.to_f
254
+ when Gtk::Calendar then control.select_month(val.month, val.year) ; control.select_day(val.day) ; control.mark_day(val.day)
255
+ when Gtk::Adjustment then control.value = val.to_f
256
+ end
257
+ end
258
+
259
+ # Populates the instance variables from the glade form.
260
+ # This works for Gtk:Button, Gtk::Entry, Gtk::Label and Gtk::Checkbutton.
261
+ # So instead of having to assign instance variable:
262
+ #
263
+ # @name = @builder["DataObjectGUI.name"].text
264
+ # @address = @builder["DataObjectGUI.address"].text
265
+ # @eamil = @builder["DataObjectGUI.email"].text
266
+ # @phone = @builder["DataObjectGUI.phone"].text
267
+ #
268
+ # you can write one line of code:
269
+ #
270
+ # get_glade_variables()
271
+ #
272
+ # The optional parameter is seldom used because you usually want the
273
+ # glade form to populate from the calling class. If you passed another object,
274
+ # the form would populate from it.
275
+ #
276
+ # obj - type Object
277
+ #
278
+
279
+ def get_glade_variables(obj = self)
280
+ obj.instance_variables.each do |v|
281
+ v = v.to_s #fix for ruby 1.9 giving symbols
282
+ control = @builder[class_name(obj) + v.gsub("@", ".")]
283
+ control ||= @builder[v.gsub("@", "")]
284
+ case control
285
+ when Gtk::CheckButton then obj.instance_variable_set(v, control.active?)
286
+ when Gtk::Entry then obj.instance_variable_set(v, control.text)
287
+ when Gtk::TextView then obj.instance_variable_set(v, control.buffer.text)
288
+ when Gtk::FontButton then obj.instance_variable_set(v, control.font_name)
289
+ when Gtk::Label, Gtk::Button then obj.instance_variable_set(v, control.label)
290
+ when Gtk::SpinButton then obj.instance_variable_set(v, control.value)
291
+ when Gtk::Image then obj.instance_variable_set(v, control.file)
292
+ when Gtk::ProgressBar then obj.instance_variable_set(v, control.fraction)
293
+ when Gtk::Calendar then obj.instance_variable_set(v, DateTime.new(*control.date))
294
+ when Gtk::Adjustment then obj.instance_variable_set(v, control.value)
295
+ end
296
+ end
297
+ end
298
+
299
+
300
+ def get_glade_active_record(obj) # :nodoc:
301
+ return if not defined? @attributes
302
+ obj.attributes.each_pair do |key, val|
303
+ control = @builder[class_name(obj) + "." + key]
304
+ control ||= @builder[key]
305
+ case control
306
+ when Gtk::CheckButton then self.send("#{key}=", control.active?)
307
+ when Gtk::Entry then self.send("#{key}=", control.text)
308
+ when Gtk::TextView then self.send("#{key}=", control.buffer.text)
309
+ when Gtk::FontButton then self.send("#{key}=", control.font_name)
310
+ when Gtk::Label, Gtk::Button then self.send("#{key}=", control.label)
311
+ when Gtk::SpinButton then self.send("#{key}=", control.value)
312
+ when Gtk::Image then self.send("#{key}=", control.file)
313
+ when Gtk::ProgressBar then self.send("#{key}=", control.fraction)
314
+ when Gtk::Calendar then self.send("#{key}=", DateTime.new(*control.date))
315
+ when Gtk::Adjustment then self.send("#{key}=", control.value)
316
+ end
317
+ end
318
+ end
319
+
320
+
321
+
322
+
323
+ #
324
+ #This shows the window and will start the Gtk.main loop (for top level windows.)
325
+ #This is called after calling load_glade() and setting-up all the form widgets.
326
+ #Using show_window() and destroy_window() is better than using Gtk.main and
327
+ #Gtk.main.quit because they automatically open and close windows properly.
328
+ #
329
+ def show_window()
330
+ @builder["window1"].show_all
331
+ Gtk.main if @builder["window1"].transient_for.nil?
332
+ end
333
+ #
334
+ #Destroys window that was opened with show_window(). destroy_window()
335
+ #will check if your window is a parent window or a child, and destroy
336
+ #the window in the proper way. (It will call Gtk.main.quit for
337
+ #parent windows.)
338
+ #
339
+ def destroy_window()
340
+ if @builder["window1"].transient_for.nil?
341
+ Gtk.main_quit
342
+ end
343
+ @builder["window1"].destroy
344
+ end
345
+
346
+ def active_record_valid?(show_errors = true)
347
+ get_glade_all
348
+ if not self.valid?
349
+ VR.msg(self.errors.full_messages.join("\n\n")) if show_errors
350
+ self.reload
351
+ return false
352
+ end
353
+ return true
354
+ end
355
+
356
+ end
357
+
358
+