visualruby 1.0.19 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (182) hide show
  1. checksums.yaml +4 -4
  2. data/Splash.rb +40 -0
  3. data/bin/editor/VR_Document.rb +81 -74
  4. data/bin/editor/VR_TabSearch.rb +5 -7
  5. data/bin/editor/VR_Tabs.rb +57 -36
  6. data/bin/editor/VR_TextShell.rb +12 -34
  7. data/bin/editor/VR_TextViewCommon.rb +9 -28
  8. data/bin/main/NewProjectGUI.rb +14 -13
  9. data/bin/main/OpenProject.rb +69 -0
  10. data/bin/main/ProjectChooserView.rb +3 -2
  11. data/bin/main/ProjectTree.rb +25 -0
  12. data/bin/main/RubygemsAPI.rb +15 -11
  13. data/bin/main/VR_ENV.rb +38 -60
  14. data/bin/main/VR_ENV_GLOBAL.rb +45 -44
  15. data/bin/main/VR_File_Tree.rb +29 -21
  16. data/bin/main/VR_Local_Gem_Tree.rb +4 -19
  17. data/bin/main/VR_Main.rb +128 -144
  18. data/bin/main/VR_Remote_Gem_Tree.rb +6 -19
  19. data/bin/main/glade/NewProjectGUI.glade +94 -98
  20. data/bin/main/glade/OpenProject.glade +259 -0
  21. data/bin/main/glade/RubygemsAPI.glade +98 -62
  22. data/bin/main/glade/VR_ENV.glade +46 -55
  23. data/bin/main/glade/VR_ENV_GLOBAL.glade +251 -180
  24. data/bin/main/glade/VR_File_Tree.glade +25 -16
  25. data/bin/main/glade/VR_Local_Gem_Tree.glade +16 -8
  26. data/bin/main/glade/VR_Main.glade +410 -449
  27. data/bin/main/glade/VR_Remote_Gem_Tree.glade +33 -31
  28. data/bin/tools/VR_Tools.rb +60 -46
  29. data/{visualruby_examples → examples}/active_record/active_record.rb +16 -10
  30. data/{visualruby_examples → examples}/active_record/bin/ChoosePerson.rb +7 -0
  31. data/examples/active_record/bin/Person.rb +21 -0
  32. data/examples/active_record/bin/glade/ChoosePerson.glade +89 -0
  33. data/examples/active_record/bin/glade/Person.glade +197 -0
  34. data/{visualruby_examples → examples}/active_record/db/development.sqlite3 +0 -0
  35. data/{visualruby_examples → examples}/active_record2/bin/CompanyGUI.rb +7 -7
  36. data/{visualruby_examples → examples}/active_record2/bin/Employee.rb +0 -0
  37. data/{visualruby_examples → examples}/active_record2/bin/Employer.rb +0 -0
  38. data/{visualruby_examples → examples}/active_record2/bin/Paycheck.rb +0 -0
  39. data/examples/active_record2/bin/glade/CompanyGUI.glade +149 -0
  40. data/examples/active_record2/bin/glade/Employee.glade +126 -0
  41. data/{visualruby_examples → examples}/active_record2/bin/glade/Employer.glade +0 -0
  42. data/{visualruby_examples → examples}/active_record2/bin/glade/Paycheck.glade +0 -0
  43. data/{visualruby_examples → examples}/active_record2/db/development.sqlite3 +0 -0
  44. data/{visualruby_examples → examples}/active_record2/main.rb +15 -9
  45. data/examples/alert_box/bin/AlertBoxDemo.rb +80 -0
  46. data/examples/alert_box/bin/glade/AlertBoxDemo.glade +234 -0
  47. data/examples/alert_box/main.rb +12 -0
  48. data/{visualruby_examples → examples}/all_widgets/bin/AllWidgets.rb +18 -10
  49. data/{visualruby_examples → examples}/all_widgets/bin/glade/AllWidgets.glade +52 -16
  50. data/{visualruby_examples → examples}/all_widgets/bin/splash.png +0 -0
  51. data/examples/all_widgets/main.rb +12 -0
  52. data/{visualruby_examples → examples}/calculator/bin/Calculator.rb +23 -22
  53. data/{visualruby_examples → examples}/calculator/bin/glade/Calculator.glade +81 -51
  54. data/examples/calculator/main.rb +13 -0
  55. data/examples/child_window/bin/ChildWindowDemo.rb +52 -0
  56. data/examples/child_window/bin/ModalWindow.rb +9 -0
  57. data/examples/child_window/bin/ModelessWindow.rb +9 -0
  58. data/examples/child_window/bin/MyChildClass.rb +21 -0
  59. data/examples/child_window/bin/glade/ChildWindowDemo.glade +87 -0
  60. data/examples/child_window/bin/glade/ModalWindow.glade +61 -0
  61. data/examples/child_window/bin/glade/ModelessWindow.glade +61 -0
  62. data/{visualruby_examples → examples}/child_window/bin/glade/MyChildClass.glade +14 -12
  63. data/examples/child_window/main.rb +12 -0
  64. data/{visualruby_examples → examples}/drag_drop/bin/DragDropDemo.rb +9 -10
  65. data/examples/drag_drop/bin/glade/DragDropDemo.glade +161 -0
  66. data/{visualruby_examples → examples}/drag_drop/img/folder.png +0 -0
  67. data/{visualruby_examples → examples}/drag_drop/img/glade.png +0 -0
  68. data/{visualruby_examples → examples}/drag_drop/img/gtk-edit.png +0 -0
  69. data/{visualruby_examples → examples}/drag_drop/img/obj.png +0 -0
  70. data/{visualruby_examples → examples}/drag_drop/img/png.png +0 -0
  71. data/{visualruby_examples → examples}/drag_drop/img/rb.png +0 -0
  72. data/{visualruby_examples → examples}/drag_drop/img/ruby.png +0 -0
  73. data/{visualruby_examples → examples}/drag_drop/img/unknown.png +0 -0
  74. data/examples/drag_drop/main.rb +11 -0
  75. data/examples/filetreeview/bin/ProjectTree.rb +32 -0
  76. data/examples/filetreeview/bin/ProjectTreeGUI.rb +28 -0
  77. data/examples/filetreeview/bin/glade/ProjectTreeGUI.glade +156 -0
  78. data/examples/filetreeview/main.rb +13 -0
  79. data/{visualruby_examples → examples}/listview/bin/SongListView.rb +24 -20
  80. data/{visualruby_examples → examples}/listview/bin/SongListViewGUI.rb +12 -11
  81. data/{visualruby_examples → examples}/listview/bin/audio-x-generic.png +0 -0
  82. data/examples/listview/bin/glade/SongListViewGUI.glade +195 -0
  83. data/examples/listview/main.rb +10 -0
  84. data/examples/listview_objects/bin/DataObject.rb +53 -0
  85. data/{visualruby_examples → examples}/listview_objects/bin/ListViewObjects.rb +7 -4
  86. data/examples/listview_objects/bin/ListViewObjectsGUI.rb +26 -0
  87. data/examples/listview_objects/bin/glade/DataObject.glade +196 -0
  88. data/examples/listview_objects/bin/glade/ListViewObjectsGUI.glade +87 -0
  89. data/examples/listview_objects/main.rb +12 -0
  90. data/examples/settings_file/bin/MainApp.rb +38 -0
  91. data/examples/settings_file/bin/SavableSettings.rb +39 -0
  92. data/examples/settings_file/bin/glade/MainApp.glade +87 -0
  93. data/examples/settings_file/bin/glade/SavableSettings.glade +162 -0
  94. data/examples/settings_file/main.rb +14 -0
  95. data/examples/settings_file/settings.yaml +15 -0
  96. data/examples/simple_ruby_gui/bin/DataObjectGUI.rb +21 -0
  97. data/examples/simple_ruby_gui/bin/glade/DataObjectGUI.glade +195 -0
  98. data/examples/simple_ruby_gui/main.rb +16 -0
  99. data/{visualruby_examples → examples}/treeview/bin/MyClass.rb +1 -5
  100. data/examples/treeview/bin/glade/MyClass.glade +24 -0
  101. data/examples/treeview/main.rb +13 -0
  102. data/skeleton/document/New.glade +3 -4
  103. data/skeleton/document/NewWindow.rb +1 -1
  104. data/skeleton/project/bin/MyClass.rb +2 -2
  105. data/skeleton/project/bin/glade/MyClass.glade +12 -26
  106. data/skeleton/project/main.rb +4 -8
  107. data/vr +41 -37
  108. data/vrlib/lib/Alert.rb +67 -0
  109. data/vrlib/lib/DragDrop.rb +90 -0
  110. data/vrlib/lib/GladeGUI.rb +433 -0
  111. data/vrlib/lib/IconHash.rb +18 -0
  112. data/vrlib/lib/SavableClass.rb +56 -0
  113. data/vrlib/lib/SimpleComboBoxEntry.rb +8 -0
  114. data/vrlib/lib/glade/Alert.glade +119 -0
  115. data/vrlib/lib/treeview/FileTreeView.rb +113 -0
  116. data/vrlib/lib/treeview/IterMethods.rb +82 -0
  117. data/vrlib/lib/treeview/ListView.rb +85 -0
  118. data/vrlib/lib/treeview/TreeView.rb +43 -0
  119. data/vrlib/lib/treeview/ViewCommon.rb +370 -0
  120. data/vrlib/lib/treeview/columns/CalendarCol.rb +89 -0
  121. data/vrlib/lib/treeview/columns/CellRendererCombo.rb +66 -0
  122. data/vrlib/lib/treeview/columns/CellRendererDate.rb +45 -0
  123. data/vrlib/lib/treeview/columns/CellRendererObject.rb +57 -0
  124. data/vrlib/lib/treeview/columns/CellRendererPhone.rb +45 -0
  125. data/vrlib/lib/treeview/columns/CellRendererPixbuf.rb +16 -0
  126. data/vrlib/lib/treeview/columns/CellRendererProgress.rb +17 -0
  127. data/vrlib/lib/treeview/columns/CellRendererSpin.rb +37 -0
  128. data/vrlib/lib/treeview/columns/CellRendererText.rb +38 -0
  129. data/vrlib/lib/treeview/columns/CellRendererToggle.rb +47 -0
  130. data/vrlib/lib/treeview/columns/ComboCol.rb +43 -0
  131. data/vrlib/lib/treeview/columns/CurrencyCol.rb +23 -0
  132. data/vrlib/lib/treeview/columns/DateCol.rb +20 -0
  133. data/vrlib/lib/treeview/columns/ImageCol.rb +27 -0
  134. data/vrlib/lib/treeview/columns/ProgressCol.rb +27 -0
  135. data/vrlib/lib/treeview/columns/SpinCol.rb +11 -0
  136. data/vrlib/lib/treeview/columns/TextCol.rb +65 -0
  137. data/vrlib/lib/treeview/columns/TreeViewColumn.rb +93 -0
  138. data/{bin/main/glade/ProjectChooserGUI.glade → vrlib/lib/treeview/columns/glade/CalendarCol.glade} +71 -63
  139. data/{bin/main/glade/Splash.glade → vrlib/lib/treeview/columns/glade/ImageCol.glade} +5 -6
  140. data/vrlib/lib/treeview/columns/glade/TextCol.glade +82 -0
  141. data/vrlib/rdoc_replace.yaml +77 -0
  142. data/vrlib/vrlib.rb +7 -0
  143. metadata +163 -136
  144. data/bin/editor/glade/VR_Document.glade +0 -160
  145. data/bin/main/ProjectChooserGUI.rb +0 -41
  146. data/bin/main/Splash.rb +0 -22
  147. data/visualruby_examples/active_record/.vr_settings.yaml +0 -47
  148. data/visualruby_examples/active_record/bin/Person.rb +0 -13
  149. data/visualruby_examples/active_record/bin/glade/ChoosePerson.glade +0 -61
  150. data/visualruby_examples/active_record/bin/glade/Person.glade +0 -148
  151. data/visualruby_examples/active_record2/.vr_settings.yaml +0 -16
  152. data/visualruby_examples/active_record2/bin/glade/CompanyGUI.glade +0 -167
  153. data/visualruby_examples/active_record2/bin/glade/Employee.glade +0 -123
  154. data/visualruby_examples/all_widgets/.vr_settings.yaml +0 -13
  155. data/visualruby_examples/all_widgets/main.rb +0 -14
  156. data/visualruby_examples/calculator/.vr_settings.yaml +0 -11
  157. data/visualruby_examples/calculator/main.rb +0 -13
  158. data/visualruby_examples/child_window/.vr_settings.yaml +0 -16
  159. data/visualruby_examples/child_window/bin/ChildWindowDemo.rb +0 -39
  160. data/visualruby_examples/child_window/bin/MyChildClass.rb +0 -40
  161. data/visualruby_examples/child_window/bin/glade/ChildWindowDemo.glade +0 -101
  162. data/visualruby_examples/child_window/main.rb +0 -13
  163. data/visualruby_examples/drag_drop/.vr_settings.yaml +0 -12
  164. data/visualruby_examples/drag_drop/bin/glade/DragDropDemo.glade +0 -143
  165. data/visualruby_examples/drag_drop/main.rb +0 -14
  166. data/visualruby_examples/listview/.vr_settings.yaml +0 -12
  167. data/visualruby_examples/listview/bin/glade/SongListViewGUI.glade +0 -220
  168. data/visualruby_examples/listview/main.rb +0 -19
  169. data/visualruby_examples/listview_objects/.vr_settings.yaml +0 -16
  170. data/visualruby_examples/listview_objects/bin/DataObject.rb +0 -32
  171. data/visualruby_examples/listview_objects/bin/DataObjectGUI.rb +0 -41
  172. data/visualruby_examples/listview_objects/bin/ListViewObjectsGUI.rb +0 -18
  173. data/visualruby_examples/listview_objects/bin/glade/DataObject.glade +0 -198
  174. data/visualruby_examples/listview_objects/bin/glade/ListViewObjectsGUI.glade +0 -102
  175. data/visualruby_examples/listview_objects/main.rb +0 -13
  176. data/visualruby_examples/simple_ruby_gui/.vr_settings.yaml +0 -16
  177. data/visualruby_examples/simple_ruby_gui/bin/DataObjectGUI.rb +0 -20
  178. data/visualruby_examples/simple_ruby_gui/bin/glade/DataObjectGUI.glade +0 -163
  179. data/visualruby_examples/simple_ruby_gui/main.rb +0 -16
  180. data/visualruby_examples/treeview/.vr_settings.yaml +0 -12
  181. data/visualruby_examples/treeview/bin/glade/MyClass.glade +0 -48
  182. data/visualruby_examples/treeview/main.rb +0 -14
@@ -0,0 +1,433 @@
1
+ #
2
+ # GladeGUI connects your class to a glade form.
3
+ # 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
+ # include GladeGUI
21
+ # end
22
+ #
23
+ # GladeGUI will load a corresponding
24
+ # glade file for this class. It knows which glade file to load by using a naming
25
+ # convention:
26
+ #
27
+ # /home/me/visualruby/projectname/bin/MyClass.rb
28
+ #
29
+ # Will load this glade file:
30
+ #
31
+ # /home/me/visualrubyprojectname/bin/glade/MyClass.glade
32
+ #
33
+ # Note: it will use this format: /my/path/glade/<class_name>.glade.
34
+ # In the example, the class and the file have the same name,
35
+ # MyClass. You should always name your class, script, and glade file
36
+ # the same name (case sensitive).
37
+ #
38
+ # ==@builder holds all your widgets
39
+ #
40
+ # So when you "load" your class's glade file where is it loaded?
41
+ #
42
+ # GladeGUI adds an instance variable, @builder to your class.
43
+ # It loads all the windows and widgets from your glade file into @builder.
44
+ # So, you use @builder to manipulate everything in you class's GUI.
45
+ # @builder is set when you call the show_glade() method, as this code shows:
46
+ #
47
+ # class MyClass
48
+ #
49
+ # include GladeGUI
50
+ #
51
+ # def initialize()
52
+ # puts @builder.to_s # => nil
53
+ # end
54
+ #
55
+ # def before_show()
56
+ # puts @builder.to_s # => Gtk::Builder
57
+ # end
58
+ #
59
+ # end
60
+ #
61
+ # After show_glade() is called, you can access any of your form's windows or widgets
62
+ # using the @builder variable:
63
+ #
64
+ # @builder["window1"].title = "This is the title that appears at the top."
65
+ #
66
+ #
67
+ # Here's another example: Suppose you have a glade form with a Gtk::Entry box on it named "email."
68
+ # You could set the text that appears in the Gtk::Entry by setting the Gtk::Entry#text property:
69
+ #
70
+ # @builder["email"].text = "harvey@harveyserver.com"
71
+ #
72
+ # Now the email adddess is set with a new value:
73
+ #
74
+ # http://visualruby.net/img/gladegui_simple.jpg
75
+ #
76
+ # ==Auto fill your glade form
77
+ # You can streamline the process of setting-up your forms by
78
+ # auto-filling the widgets from instance variables with the same name.
79
+ #
80
+ # When assigning names to widgets in glade, give them names that
81
+ # correspond to your instance variables. For example, if you want
82
+ # to edit an email address on the glade form, create an instance
83
+ # variable named @email in your class. Then, in glade, you
84
+ # add a Gtk::Entry widget to your form and set its name to
85
+ # “email”. The advantage of this is that GladeGUI will populate
86
+ # the “email” widget in glade using the @email variable. so
87
+ # you don’t need to include the above line of code. (see
88
+ # set_glade_variables() method.)
89
+
90
+
91
+ module GladeGUI
92
+
93
+ attr_accessor :builder
94
+
95
+ ##
96
+ #
97
+ # drag_to() will make it so you can drag-n-drop the source_widget onto the target widget.
98
+ # You may pass a reference to a widget object, or a String that gives the name of the
99
+ # widget on your glade form. So, it functions the same as this statement:
100
+ #
101
+ # widget_source.drag_to(widget_target)
102
+ #
103
+ # It also functions the same as this statement:
104
+ #
105
+ # @builder["widget_source"].drag_to(@builder["widget_target"])
106
+ #
107
+ #
108
+
109
+ def set_drag_drop(hash)
110
+ hash.each do |key,val|
111
+ src = key.is_a?(Gtk::Widget) ? key : @builder[key]
112
+ target = @builder[val]
113
+ src.extend(VR::Draggable) unless src.is_a?(VR::Draggable)
114
+ src.add_target_widget(target)
115
+ end
116
+ end
117
+
118
+
119
+
120
+ ##
121
+ # This will Load the glade form.
122
+ # It will create a Gtk::Builder object from your glade file.
123
+ # The Gtk::Builder object is stored in the instance variable, @builder.
124
+ # You can get a reference to any of the widgets on the glade form by
125
+ # using the @builder object:
126
+ #
127
+ # widget = @builder["name"]
128
+ #
129
+ # Normally, you should give your widgets names of instance variables: i.e. "MyClass.var"
130
+ # so they can be autoloaded using the set_glade_all() method.
131
+ #
132
+ # You can also pass a reference to a parent class that also includes GladeGUI.
133
+ # Then the child window will run simultaniously with the parent.
134
+ #
135
+
136
+ def load_glade()
137
+ caller__FILE__ = my_class_file_path()
138
+ file_name = File.split(caller__FILE__)[0] + '/glade/' + class_name(self) + ".glade"
139
+ @builder = Gtk::Builder.new
140
+ @builder << file_name
141
+ @builder.connect_signals{ |handle| method(handle) }
142
+ # parse_signals() should be called after before_show()
143
+ end
144
+
145
+ def class_name(obj) # :nodoc:
146
+ /.*\b(\w+)$/.match(obj.class.name)[1]
147
+ end
148
+
149
+ def parse_signals() # :nodoc:
150
+ meths = self.class.instance_methods()
151
+ meths.each do |meth|
152
+ meth = meth.to_s #bug fix ruby 1.9 gives stmbol
153
+ glade_name, signal_name = *(meth.split("__"))
154
+ next if (signal_name.to_s == "" or glade_name.to_s == "") #covers nil
155
+ if @builder
156
+ @builder.objects.each do |obj|
157
+ next unless obj.respond_to?(:builder_name)
158
+ if obj.builder_name == glade_name or obj.builder_name =~ /^(?:#{class_name(self)}\.|)#{glade_name}\[\d+\]$/ #arrays
159
+ obj.signal_connect(signal_name) { |*args| method(meth.to_sym).call(*args) }
160
+ end
161
+ end
162
+ end
163
+ obj = glade_name == "self" ? self : self.instance_variable_get("@" + glade_name)
164
+ obj ||= eval(glade_name) if respond_to?(glade_name) and method(glade_name.to_sym).arity == 0 # no arguments!
165
+ obj.signal_connect(signal_name) { |*args| method(meth.to_sym).call(*args) } if obj.respond_to?("signal_connect")
166
+ end
167
+ end
168
+
169
+ # This method is the most useful method to populate 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
+ # set_glade_active_record()
174
+ # set_glade_variables()
175
+ #
176
+ # So, to set all the values of a form, simply call the set_glade_all() method instead.
177
+
178
+ def set_glade_all(obj = self)
179
+ set_glade_active_record(obj)
180
+ set_glade_variables(obj)
181
+ # set_glade_hash(obj) if obj.is_a?(Hash) #only needed for Hash subclass. needed?
182
+ end
183
+
184
+ # This method is the most useful method to retreive values from a glade form. It will
185
+ # populate from active_record fields and instance variables. It will simply
186
+ # call both of these methods:
187
+ #
188
+ # get_glade_active_record()
189
+ # get_glade_variables()
190
+ #
191
+ # 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.
192
+
193
+ def get_glade_all(obj = self)
194
+ get_glade_active_record(obj)
195
+ get_glade_variables(obj)
196
+ end
197
+
198
+ # Populates the glade form from the fields of an ActiveRecord object.
199
+ # So instead of having to assign each widget a value:
200
+ #
201
+ # @builder["ARObject.name"].text = @name
202
+ # @builder["ARObject.address"].text = @address
203
+ # @builder["ARObject.email"].text = @eamil
204
+ # @builder["ARObject.phone"].text = @phone
205
+ #
206
+ # you can write one line of code:
207
+ #
208
+ # set_glade_active_record()
209
+ #
210
+ # The optional parameter is seldom used because you usually want the
211
+ # glade form to populate from the calling class. If you passed another object,
212
+ # the form would populate from it.
213
+ #
214
+ # obj - type ActiveRecord::Base
215
+ #
216
+
217
+ def set_glade_active_record(obj = self)
218
+ return if not defined? @attributes
219
+ obj.attributes.each_pair { |key, val| fill_control(class_name(obj) + "." + key, val) }
220
+ end
221
+
222
+ def set_glade_hash(hash)
223
+ return unless hash.is_a?(Hash)
224
+ hash.each { |key,val| fill_control( key.to_s, val.to_s) }
225
+ end
226
+
227
+ #Populates the glade form from the instance variables of the class.
228
+ #This works for Gtk:Button, Gtk::Entry, Gtk::Label and Gtk::Checkbutton.
229
+ #So instead of having to assign each widget a value:
230
+ #
231
+ # @builder["DataObjectGUI.name"].text = @name
232
+ # @builder["DataObjectGUI.address"].text = @address
233
+ # @builder["DataObjectGUI.email"].text = @eamil
234
+ # @builder["DataObjectGUI.phone"].text = @phone
235
+ #
236
+ #you can write one line of code:
237
+ #
238
+ # set_glade_variables()
239
+ #
240
+ #The optional parameter is seldom used because you usually want the
241
+ #glade form to populate from the calling class. If you passed another object,
242
+ #the form would populate from it.
243
+ #
244
+ #obj - type Object
245
+ #
246
+
247
+
248
+
249
+ def set_glade_variables(obj = self)
250
+ # set_glade_hash(obj) if obj.is_a?(Hash)
251
+ obj.instance_variables.each do |name|
252
+ name = name.to_s #ruby 1.9 passes symbol!
253
+ v = obj.instance_variable_get(name)
254
+ x = v.to_s
255
+ if v.class == Array
256
+ (0..v.size-1).each do |i|
257
+ fill_control(class_name(obj) + "." + name.gsub("@", "") + "[" + i.to_s + "]", v[i] )
258
+ end
259
+ else
260
+ fill_control(class_name(obj) + "." + name.gsub("@", ""), v)
261
+ end
262
+ end
263
+ end
264
+
265
+
266
+
267
+ def fill_control(glade_name, val) # :nodoc:
268
+ control = @builder[glade_name]
269
+ control_name = glade_name.split(".")[1]
270
+ control ||= @builder[control_name] if control_name
271
+ case control
272
+ when Gtk::Window then control.title = val
273
+ when Gtk::CheckButton then control.active = val
274
+ when Gtk::TextView then control.buffer.text = val.to_s
275
+ when Gtk::Entry then control.text = val.to_s
276
+ when Gtk::FontButton then control.font_name = val.to_s
277
+ when Gtk::LinkButton then control.uri = control.label = val.to_s
278
+ when Gtk::Label, Gtk::Button then control.label = val.to_s
279
+ when Gtk::Image then control.file = val.to_s
280
+ when Gtk::SpinButton then control.value = val.to_f
281
+ when Gtk::ProgressBar then control.fraction = val.to_f
282
+ when Gtk::Calendar then control.select_month(val.month, val.year) ; control.select_day(val.day) ; control.mark_day(val.day)
283
+ when Gtk::Adjustment then control.value = val.to_f
284
+ when Gtk::ScrolledWindow, Gtk::Frame, Gtk::VBox, Gtk::HBox then control.add(val)
285
+ end
286
+ end
287
+
288
+
289
+ #
290
+ # def fill_control(glade_name, val) # :nodoc:
291
+ # return unless glade_name and val
292
+ #puts glade_name + val.to_s
293
+ # control = @builder[glade_name]
294
+ #puts control.class
295
+ # control_name = glade_name.split(".")[1]
296
+ # control ||= @builder[control_name] unless control_name.nil?
297
+ # return if control.nil?
298
+ # case control.class
299
+ # when Gtk::Window then control.title = val
300
+ # when Gtk::CheckButton then control.active = val
301
+ # when Gtk::TextView then control.buffer.text = val.to_s
302
+ # when Gtk::Entry then control.text = val.to_s
303
+ # when Gtk::FontButton then control.font_name = val.to_s
304
+ # when Gtk::LinkButton then control.uri = control.label = val.to_s
305
+ # when Gtk::Label, Gtk::Button then control.label = val.to_s
306
+ # when Gtk::Image then control.file = val.to_s
307
+ # when Gtk::SpinButton then control.value = val.to_f
308
+ # when Gtk::ProgressBar then control.fraction = val.to_f
309
+ # when Gtk::Calendar then control.select_month(val.month, val.year) ; control.select_day(val.day) ; control.mark_day(val.day)
310
+ # when Gtk::Adjustment then control.value = val.to_f
311
+ # when Gtk::ScrolledWindow, Gtk::Frame, Gtk::Box then control.add(val)
312
+ # end
313
+ # end
314
+ #
315
+ # Populates the instance variables from the glade form.
316
+ # This works for Gtk:Button, Gtk::Entry, Gtk::Label and Gtk::Checkbutton.
317
+ # So instead of having to assign instance variable:
318
+ #
319
+ # @name = @builder["DataObjectGUI.name"].text
320
+ # @address = @builder["DataObjectGUI.address"].text
321
+ # @eamil = @builder["DataObjectGUI.email"].text
322
+ # @phone = @builder["DataObjectGUI.phone"].text
323
+ #
324
+ # you can write one line of code:
325
+ #
326
+ # get_glade_variables()
327
+ #
328
+ # The optional parameter is seldom used because you usually want the
329
+ # glade form to populate from the calling class. If you passed another object,
330
+ # the form would populate from it.
331
+ #
332
+ # obj - type Object
333
+ #
334
+
335
+ def get_glade_variables(obj = self)
336
+ obj.instance_variables.each do |v|
337
+ v = v.to_s #fix for ruby 1.9 giving symbols
338
+ control = @builder[class_name(obj) + v.gsub("@", ".")]
339
+ control ||= @builder[v.gsub("@", "")]
340
+ case control
341
+ when Gtk::CheckButton then obj.instance_variable_set(v, control.active?)
342
+ when Gtk::Entry then obj.instance_variable_set(v, control.text)
343
+ when Gtk::TextView then obj.instance_variable_set(v, control.buffer.text)
344
+ when Gtk::FontButton then obj.instance_variable_set(v, control.font_name)
345
+ when Gtk::Label, Gtk::Button then obj.instance_variable_set(v, control.label)
346
+ when Gtk::SpinButton then obj.instance_variable_set(v, control.value)
347
+ when Gtk::Image then obj.instance_variable_set(v, control.file)
348
+ when Gtk::ProgressBar then obj.instance_variable_set(v, control.fraction)
349
+ when Gtk::Calendar then obj.instance_variable_set(v, DateTime.new(*control.date))
350
+ when Gtk::Adjustment then obj.instance_variable_set(v, control.value)
351
+ end
352
+ end
353
+ end
354
+
355
+
356
+ def get_glade_active_record(obj) # :nodoc:
357
+ return if not defined? @attributes
358
+ obj.attributes.each_pair do |key, val|
359
+ control = @builder[class_name(obj) + "." + key]
360
+ control ||= @builder[key]
361
+ case control
362
+ when Gtk::CheckButton then self.send("#{key}=", control.active?)
363
+ when Gtk::Entry then self.send("#{key}=", control.text)
364
+ when Gtk::TextView then self.send("#{key}=", control.buffer.text)
365
+ when Gtk::FontButton then self.send("#{key}=", control.font_name)
366
+ when Gtk::Label, Gtk::Button then self.send("#{key}=", control.label)
367
+ when Gtk::SpinButton then self.send("#{key}=", control.value)
368
+ when Gtk::Image then self.send("#{key}=", control.file)
369
+ when Gtk::ProgressBar then self.send("#{key}=", control.fraction)
370
+ when Gtk::Calendar then self.send("#{key}=", DateTime.new(*control.date))
371
+ when Gtk::Adjustment then self.send("#{key}=", control.value)
372
+ end
373
+ end
374
+ end
375
+
376
+
377
+
378
+ def self.included(obj)
379
+ temp = caller[0].split(":") #correct for windows C:\Users\george etc.
380
+ caller_path_to_class_file, = temp[0].size == 1 ? temp[0] + ":" + temp[1] : temp[0]
381
+ obj.class_eval do
382
+ define_method :my_class_file_path do
383
+ return caller_path_to_class_file
384
+ end
385
+ end
386
+ end
387
+
388
+
389
+ #
390
+ #This shows the window and will start the Gtk.main loop (for top level windows.)
391
+ #Using show_glade() is better than using Gtk.main and
392
+ #Gtk.main.quit because visualruby automatically opens and closes all windows properly.
393
+ #
394
+ #
395
+ def show_glade(parent = nil)
396
+ load_glade()
397
+ if parent then
398
+ @builder[:window1].transient_for = parent.builder[:window1]
399
+ # @builder[:window1].modal = true
400
+ end
401
+ before_show() if respond_to? :before_show
402
+ parse_signals()
403
+ set_glade_all()
404
+ @builder[:window1].show #show_all can't hide widgets in before_show
405
+ @top_level_window = Gtk.main_level == 0 ? true : false
406
+ Gtk.main if @top_level_window or @builder[:window1].modal? #need new Gtk.main for blocking!
407
+ end
408
+
409
+
410
+
411
+
412
+ def window1__destroy(*args)
413
+ Gtk.main_quit if @top_level_window or @builder["window1"].modal?
414
+ end
415
+
416
+ def buttonCancel__clicked(*a)
417
+ @builder[:window1].destroy
418
+ end
419
+
420
+
421
+ def active_record_valid?(show_errors = true)
422
+ get_glade_all
423
+ if not self.valid?
424
+ alset(self.errors.full_messages.join("\n\n")) if show_errors
425
+ self.reload
426
+ return false
427
+ end
428
+ return true
429
+ end
430
+
431
+ end
432
+
433
+
@@ -0,0 +1,18 @@
1
+ module VR
2
+
3
+ class IconHash < Hash # :nodoc:
4
+
5
+ def initialize(path)
6
+ Dir.glob(path + "/*.png").each do |f|
7
+ ext = File.basename(f, ".png")
8
+ self[ext] = Gdk::Pixbuf.new(f)
9
+ end
10
+ end
11
+
12
+ def get_icon(file_name)
13
+ ext = File.extname(file_name).gsub(".", "")
14
+ self.has_key?(ext) ? self[ext] : self["unknown"]
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,56 @@
1
+ module VR
2
+
3
+ def self.load_yaml(flags)
4
+ me = nil
5
+ if File.file?(flags[:file_name])
6
+ me = YAML.load(File.open(flags[:file_name]).read)
7
+ elsif flags[:class]
8
+ me = flags[:class].new()
9
+ end
10
+ me.instance_variable_set(:@vr_yaml_file, flags[:file_name])
11
+ me.defaults() if me.respond_to?(:defaults)
12
+ VR::save_yaml(me)
13
+ return me
14
+ end
15
+
16
+ # todo create folders if don't exist
17
+ def self.save_yaml(obj, filename = nil)
18
+ filename ||= obj.instance_variable_get(:@vr_yaml_file)
19
+ data = YAML.dump(obj)
20
+ File.open(filename, "w") {|f| f.puts(data)}
21
+ end
22
+
23
+ end
24
+
25
+ #
26
+ #class VR::SavableClass
27
+ #
28
+ # def initialize(filename = nil)
29
+ # @filename = filename
30
+ # defaults
31
+ # end
32
+ #
33
+ # def self.load_yaml(filename)
34
+ # if File.file?(filename)
35
+ # me = YAML.load(File.open(filename).read)
36
+ # me.filename = filename
37
+ # me.defaults()
38
+ # return me
39
+ # else
40
+ # return nil
41
+ # end
42
+ # end
43
+ #
44
+ # def save_yaml(new_filename = nil)
45
+ # @filename = new_filename if new_filename
46
+ # data = YAML.dump(self)
47
+ # File.open(@filename, "w") {|f| f.puts(data)}
48
+ # end
49
+ #
50
+ #
51
+ #end
52
+
53
+
54
+
55
+
56
+
@@ -0,0 +1,8 @@
1
+
2
+ #This is for backwards compatibility. Before, there was an instance of
3
+ #SimpleComboBoxEntry in the VR_ENV_GLOBAL yaml file. Older projects try to
4
+ #load this instance.
5
+ module VR
6
+ class SimpleComboBoxEntry
7
+ end
8
+ end
@@ -0,0 +1,119 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!-- Generated with glade 3.16.1 -->
3
+ <interface>
4
+ <requires lib="gtk+" version="3.0"/>
5
+ <object class="GtkWindow" id="window1">
6
+ <property name="width_request">300</property>
7
+ <property name="can_focus">False</property>
8
+ <property name="title" translatable="yes">Visual Ruby</property>
9
+ <property name="modal">True</property>
10
+ <property name="window_position">center</property>
11
+ <property name="destroy_with_parent">True</property>
12
+ <property name="type_hint">dialog</property>
13
+ <property name="urgency_hint">True</property>
14
+ <child>
15
+ <object class="GtkBox" id="box1">
16
+ <property name="visible">True</property>
17
+ <property name="can_focus">False</property>
18
+ <property name="margin_left">20</property>
19
+ <property name="margin_right">20</property>
20
+ <property name="margin_top">20</property>
21
+ <property name="margin_bottom">20</property>
22
+ <property name="orientation">vertical</property>
23
+ <child>
24
+ <object class="GtkLabel" id="headline">
25
+ <property name="can_focus">False</property>
26
+ <property name="label" translatable="yes">label</property>
27
+ <attributes>
28
+ <attribute name="size" value="18000"/>
29
+ </attributes>
30
+ </object>
31
+ <packing>
32
+ <property name="expand">False</property>
33
+ <property name="fill">True</property>
34
+ <property name="position">0</property>
35
+ </packing>
36
+ </child>
37
+ <child>
38
+ <object class="GtkLabel" id="message">
39
+ <property name="visible">True</property>
40
+ <property name="can_focus">False</property>
41
+ <property name="margin_top">10</property>
42
+ <property name="label" translatable="yes">label</property>
43
+ <property name="use_markup">True</property>
44
+ <property name="wrap">True</property>
45
+ </object>
46
+ <packing>
47
+ <property name="expand">True</property>
48
+ <property name="fill">True</property>
49
+ <property name="position">1</property>
50
+ </packing>
51
+ </child>
52
+ <child>
53
+ <object class="GtkEntry" id="input_text">
54
+ <property name="can_focus">True</property>
55
+ <property name="margin_top">10</property>
56
+ </object>
57
+ <packing>
58
+ <property name="expand">False</property>
59
+ <property name="fill">True</property>
60
+ <property name="position">2</property>
61
+ </packing>
62
+ </child>
63
+ <child>
64
+ <object class="GtkButtonBox" id="buttonbox1">
65
+ <property name="visible">True</property>
66
+ <property name="can_focus">False</property>
67
+ <property name="margin_top">10</property>
68
+ <property name="margin_bottom">5</property>
69
+ <property name="spacing">15</property>
70
+ <property name="layout_style">end</property>
71
+ <child>
72
+ <object class="GtkButton" id="button_cancel">
73
+ <property name="label" translatable="yes">button</property>
74
+ <property name="can_focus">True</property>
75
+ <property name="receives_default">True</property>
76
+ </object>
77
+ <packing>
78
+ <property name="expand">False</property>
79
+ <property name="fill">True</property>
80
+ <property name="position">0</property>
81
+ </packing>
82
+ </child>
83
+ <child>
84
+ <object class="GtkButton" id="button_no">
85
+ <property name="label" translatable="yes">button</property>
86
+ <property name="can_focus">True</property>
87
+ <property name="receives_default">True</property>
88
+ </object>
89
+ <packing>
90
+ <property name="expand">True</property>
91
+ <property name="fill">True</property>
92
+ <property name="position">1</property>
93
+ </packing>
94
+ </child>
95
+ <child>
96
+ <object class="GtkButton" id="button_yes">
97
+ <property name="label" translatable="yes">Ok</property>
98
+ <property name="visible">True</property>
99
+ <property name="can_focus">True</property>
100
+ <property name="receives_default">True</property>
101
+ </object>
102
+ <packing>
103
+ <property name="expand">True</property>
104
+ <property name="fill">True</property>
105
+ <property name="position">2</property>
106
+ </packing>
107
+ </child>
108
+ </object>
109
+ <packing>
110
+ <property name="expand">False</property>
111
+ <property name="fill">True</property>
112
+ <property name="pack_type">end</property>
113
+ <property name="position">3</property>
114
+ </packing>
115
+ </child>
116
+ </object>
117
+ </child>
118
+ </object>
119
+ </interface>