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,89 @@
1
+
2
+ module VR
3
+
4
+ # The CalendarCol class is a simple calendar window where you can edit
5
+ # the date:
6
+ #
7
+ # http://visualruby.net/img/calendar.jpg
8
+ #
9
+ # This class is very useful when you want to display and edit dates
10
+ # in a VR::ListView. You can define a column with the type VR::CalendarCol
11
+ # and the column will display as a date, and when the user clicks on the
12
+ # date, a calendar window will appear so he/she can edit it:
13
+ #
14
+ # @view = VR::ListView.new(:name => String, :birthday => VR::CalendarCol)
15
+ # row = @view.add_row
16
+ # row[:name] = "Eric"
17
+ # row[:birthday] = VR::CalendarCol.new(DateTime.new(1966, 7, 14))
18
+ #
19
+ # See the example project, "listview_objects" for more.
20
+
21
+ class CalendarCol
22
+
23
+ include GladeGUI
24
+
25
+ attr_accessor :date, :date_format, :show_time, :show_calendar
26
+ #
27
+ # - datetime - Instance of DateTime class that holds the date value.
28
+ # - date_format - String that holds the Ruby date format. Default: "%d %b %Y %I:%M%p"
29
+ # - show_time - true/false If this is false, the time will not appear in the edit window.
30
+ # - show_calendar - true/false If this is false, Calendar will not appear. Only time will edit.
31
+ #
32
+ def initialize(datetime, flags = {}) #flags = :hide_date => true, hide_time => true, :format => "%d %b %Y %I:%M%p"
33
+ @format = flags[:format]
34
+ @format ||= flags[:hide_date] ? "%I:%M%p" : "%d %b %Y %I:%M%p"
35
+ @format ||= flags[:hide_time] ? "%d %b %Y" : @date_format
36
+ @hide_date = flags[:hide_date]
37
+ @hide_time = flags[:hide_time]
38
+ @show_calendar = show_calendar
39
+ @date = datetime
40
+ @hour = @date.strftime("%I").to_f
41
+ @minute = @date.min()
42
+ @am = (@date.hour < 12)
43
+ @pm = !@am
44
+ end
45
+
46
+ def show_glade(parent = nil)
47
+ super
48
+ @builder["hboxTime"].hide if @hide_time
49
+ @builder["date"].hide if @hide_date
50
+ end
51
+
52
+ # displays time according to the @date_format instance variable. If you want to
53
+ # change the appearance of this object, assign a new vale to @date_format.
54
+
55
+ def to_s
56
+ @date.strftime(@format)
57
+ end
58
+
59
+ def am__toggled(*args) # :nodoc:
60
+ @builder["pm"].active = !@builder["am"].active?
61
+ end
62
+
63
+ def pm__toggled(*args) # :nodoc:
64
+ @builder["am"].active = !@builder["pm"].active?
65
+ end
66
+
67
+ def buttonSave__clicked(*args) # :nodoc:
68
+ get_glade_variables()
69
+ m = @builder["am"].active? ? "AM" : "PM"
70
+ t = DateTime.strptime("#{@hour.to_i.to_s} #{@minute.to_i.to_s} #{m}", "%I %M %p")
71
+ @date = DateTime.new(@date.year, @date.month, @date.day, t.hour, t.min, 0)
72
+ @builder["window1"].destroy
73
+ end
74
+
75
+ def buttonCancel__clicked(*args) # :nodoc:
76
+ @builder["window1"].destroy
77
+ end
78
+
79
+ def <=>(calendar)
80
+ return @date <=> calendar.date
81
+ end
82
+
83
+ def value
84
+ @date
85
+ end
86
+
87
+ end
88
+
89
+ end
@@ -0,0 +1,66 @@
1
+ module VR
2
+
3
+ # This class is a helper to VR::ListView and VR::TreeView. When
4
+ # colums are created, this class is used as the renderer because
5
+ # it adds functionality to the Gtk Renderer.
6
+ #
7
+ # When you call ListView#render(model_col) an instance of this class
8
+ # will be returned. It is a subclass of
9
+ #
10
+ # {Gtk::CellRendererCombo}[http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3ACellRendererCombo]
11
+ #
12
+ # So it has all the functionality of its parent, plus the methods listed here.
13
+ #
14
+
15
+
16
+ class CellRendererCombo < Gtk::CellRendererCombo
17
+
18
+ attr_accessor :edited_callback, :validate_block
19
+ attr_reader :model_col, :column, :model_sym
20
+
21
+ def initialize(model_col, column, view, model_sym) # :nodoc:
22
+ super()
23
+ @model_col = model_col
24
+ @column = column
25
+ @view = view
26
+ @model_sym = model_sym
27
+ @view.model.set_sort_func(@model_col) { |m,x,y| x[@model_col].selected <=> y[@model_col].selected }
28
+ @validate_block = Proc.new { |text, model_sym, row, view | true }
29
+ self.editable = true
30
+ self.has_entry = false
31
+ @edited_callback = nil
32
+ self.signal_connect('edited') do |ren, path, text| # iter for
33
+ iter = @view.model.get_iter(path)
34
+ if @validate_block.call(text, @model_sym, @view.vr_row(iter), @view)
35
+ iter[@model_col].selected = text
36
+ @edited_callback.call(@model_sym, @view.vr_row(iter)) if @edited_callback
37
+ end
38
+ end
39
+ end
40
+
41
+ # This sets the renderer's "editable" property to true, and makes it save
42
+ # the edited value to the model. When a user edits a row in the ListView
43
+ # the value isn't automatically saved by Gtk. This method groups both actions
44
+ # together, so setting edit_save=true, allows both editing and saving of
45
+ # the field.
46
+ #
47
+ # Also, you can use VR::ListView and VR::TreeView's convenience methods to
48
+ # envoke call this method:
49
+ #
50
+ # NAME = 0
51
+ # ADDR = 1
52
+ # @view.set_attr([NAME, ADDR], :edit_save => true) #sets model_col = 0, 1
53
+ # @view.set_edit_save( 0 => true, 1 => false)
54
+ #
55
+ # is_editable = boolean
56
+ #
57
+
58
+ def set_model(vr_combo) # :nodoc:
59
+ self.model = Gtk::ListStore.new(String)
60
+ vr_combo.selections.each { |s| r = self.model.append ; r[0] = s }
61
+ self.text_column = 0
62
+ end
63
+
64
+ end
65
+
66
+ end
@@ -0,0 +1,45 @@
1
+ module VR
2
+
3
+ # This class is a helper to VR::ListView and VR::TreeView. When
4
+ # colums are created, this class is used as the renderer because
5
+ # it adds functionality to the Gtk Renderer.
6
+ #
7
+ # When you call ListView#render(model_col) an instance of this class
8
+ # will be returned. It is a subclass of
9
+ #
10
+ # {Gtk::CellRendererText}[http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3ACellRendererText]
11
+ #
12
+ # So it has all the functionality of its parent, plus the methods listed here.
13
+
14
+ class CellRendererDate < Gtk::CellRendererText
15
+
16
+ attr_accessor :date_format, :edited_callback, :model_col, :column, :model_sym
17
+
18
+ def initialize(model_col, column, view, model_sym) # :nodoc:
19
+ super()
20
+ @model_col = model_col
21
+ @column = column
22
+ @view = view
23
+ @model_sym = model_sym
24
+ @view.model.set_sort_func(@model_col) { |m,x,y| x[@model_col] <=> y[@model_col] }
25
+ @date_format = "%m-%d-%Y"
26
+ @validate_block = Proc.new { |text, model_sym, row, view|
27
+ begin
28
+ Date.strptime(text, @date_format)
29
+ true
30
+ rescue
31
+ alert("Unrecognized date format: " + text)
32
+ false
33
+ end }
34
+ @edited_block = nil
35
+ self.signal_connect('edited') do |ren, path, text|
36
+ next unless iter = @view.model.get_iter(path)
37
+ if @validate_block.call(text, @model_sym, @view.vr_row(iter), @view)
38
+ iter[@model_col] = DateTime.strptime(text, @date_format)
39
+ @edited_callback.call(@model_sym, @view.vr_row(iter)) if @edited_callback
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ end
@@ -0,0 +1,57 @@
1
+ module VR
2
+
3
+ # This class is a helper to VR::ListView and VR::TreeView. When
4
+ # colums are created, this class is used as the renderer because
5
+ # it adds functionality to the Gtk Renderer.
6
+ #
7
+ # When you call ListView#render(model_col) an instance of this class
8
+ # will be returned. It is a subclass of
9
+ #
10
+ # {Gtk::CellRendererText}[http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3ACellRendererText]
11
+ #
12
+ # So it has all the functionality of its parent, plus the methods listed here.
13
+
14
+ class CellRendererObject < Gtk::CellRendererText
15
+
16
+ attr_accessor :model_col, :column, :edited_callback, :visual_attributes_method, :model_sym
17
+
18
+ def initialize(model_col, column, view, model_sym) # :nodoc:
19
+ super()
20
+ @model_col = model_col
21
+ @model_sym = model_sym
22
+ @view = view
23
+ @column = column
24
+ @edit = true
25
+ @edited_callback = nil
26
+ @visual_attributes_method = "visual_attributes"
27
+ @view.model.set_sort_func(@model_col) { |m,x,y| x[@model_col] <=> y[@model_col] }
28
+ @show_block = Proc.new { |obj| obj.show_glade() if obj.respond_to? "show_glade" }
29
+ @view.signal_connect("row_activated") do | view, path, col |
30
+ next if !@edit or !col.eql? @column
31
+ iter = @view.model.get_iter(path)
32
+ obj = iter[@model_col]
33
+ @show_block.call(obj)
34
+ block = @edited_callback ? @edited_callback.call(@model_sym, @view.vr_row(iter)) : true
35
+ @view.signal_emit_stop("row_activated") if block
36
+ end
37
+ end
38
+
39
+ alias :set_editable :editable=
40
+ def editable=(e)
41
+ @edit = e
42
+ end
43
+
44
+ def render_object(iter)
45
+ obj = iter[@view.id(@model_col)]
46
+ self.text = obj.respond_to?(:to_s) ? obj.to_s : "Define to_s!"
47
+ if obj.respond_to? @visual_attributes_method
48
+ return unless attrib = obj.send(@visual_attributes_method)
49
+ attrib.each_pair do | key, val |
50
+ self.send( key.to_s + "=", val)
51
+ end
52
+ end
53
+ end
54
+
55
+ end
56
+
57
+ end
@@ -0,0 +1,45 @@
1
+ module VR
2
+
3
+ # This class is a helper to VR::ListView and VR::TreeView. When
4
+ # colums are created, this class is used as the renderer because
5
+ # it adds functionality to the Gtk Renderer.
6
+ #
7
+ # When you call ListView#render(model_col) an instance of this class
8
+ # will be returned. It is a subclass of
9
+ #
10
+ # {Gtk::CellRendererText}[http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3ACellRendererText]
11
+ #
12
+ # So it has all the functionality of its parent, plus the methods listed here.
13
+
14
+ class CellRendererPhone < Gtk::CellRendererText
15
+
16
+ attr_accessor :phone_format, :edited_callback, :model_col, :column, :model_sym
17
+
18
+ def initialize(model_col, column, view, model_sym) # :nodoc:
19
+ super()
20
+ @model_col = model_col
21
+ @column = column
22
+ @view = view
23
+ @model_sym = model_sym
24
+ @view.model.set_sort_func(@model_col) { |m,x,y| x[@model_col] <=> y[@model_col] }
25
+ @phone_format = "%3-%3-%4"
26
+ @validate_block = Proc.new { |text, model_sym, row, view|
27
+ only_numbers = text.gsub(/[^0-9]/, "")
28
+ if (only_numbers.size == 10)
29
+ true
30
+ else
31
+ alert("Unrecognized phone number: " + text)
32
+ false
33
+ end }
34
+ @edited_block = nil
35
+ self.signal_connect('edited') do |ren, path, text|
36
+ next unless iter = @view.model.get_iter(path)
37
+ if @validate_block.call(text, @model_sym, @view.vr_row(iter), @view)
38
+ iter[@model_col] = DateTime.strptime(text, @date_format)
39
+ @edited_callback.call(@model_sym, @view.vr_row(iter)) if @edited_callback
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ end
@@ -0,0 +1,16 @@
1
+ module VR
2
+
3
+ class CellRendererPixbuf < Gtk::CellRendererPixbuf # :nodoc:
4
+
5
+ attr_reader :model_col, :column, :model_sym
6
+
7
+ def initialize(model_col, column, view, model_sym)
8
+ super()
9
+ @column = column
10
+ @model_col = model_col
11
+ @model_sym = model_sym
12
+ @view = view
13
+ end
14
+ end
15
+
16
+ end
@@ -0,0 +1,17 @@
1
+ module VR
2
+
3
+ class CellRendererProgress < Gtk::CellRendererProgress # :nodoc:
4
+
5
+ attr_reader :model_col, :column, :model_sym
6
+
7
+ def initialize(model_col, column, view, model_sym)
8
+ super()
9
+ @model_col = model_col
10
+ @model_sym = model_sym
11
+ @column = column
12
+ @view = view
13
+ end
14
+
15
+ end
16
+
17
+ end
@@ -0,0 +1,37 @@
1
+ module VR
2
+
3
+ # This class is a helper to VR::ListView and VR::TreeView. When
4
+ # colums are created, this class is used as the renderer because
5
+ # it adds functionality to the Gtk Renderer.
6
+ #
7
+ # When you call ListView#render(column_id) an instance of this class
8
+ # will be returned. It is a subclass of
9
+ #
10
+ # GtkCellRendererSpin
11
+ #
12
+ # So it has all the functionality of its parent, plus the methods listed here.
13
+
14
+ class CellRendererSpin < Gtk::CellRendererSpin
15
+
16
+ attr_reader :model_col, :column, :model_sym
17
+ attr_accessor :edited_callback
18
+
19
+ def initialize(model_col, column, view, model_sym) # :nodoc:
20
+ super()
21
+ @model_col = model_col
22
+ @model_sym = model_sym
23
+ @column = column
24
+ @view = view
25
+ self.editable = true
26
+ @view.model.set_sort_func(@model_col) { |m,x,y| x[@model_col].value <=> y[@model_col].value }
27
+ @edited_callback = nil
28
+ self.signal_connect('edited') do |ren, path, text|
29
+ next unless iter = @view.model.get_iter(path)
30
+ iter[@model_col].value = text.to_f if (iter)
31
+ @edited_callback.call(@model_sym, @view.vr_row(iter)) if @edited_callback
32
+ end
33
+ end
34
+
35
+ end
36
+
37
+ end
@@ -0,0 +1,38 @@
1
+ module VR
2
+
3
+ # This class is a helper to VR::ListView and VR::TreeView. When
4
+ # colums are created, this class is used as the renderer because
5
+ # it adds functionality to the Gtk Renderer.
6
+ #
7
+ # When you call ListView#render(model_col) an instance of this class
8
+ # will be returned. It is a subclass of
9
+ #
10
+ # {Gtk::CellRendererText}[http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3ACellRendererText]
11
+ #
12
+ # So it has all the functionality of its parent, plus the methods listed here.
13
+
14
+ class CellRendererText < Gtk::CellRendererText
15
+
16
+ attr_accessor :validate_block, :edited_callback
17
+ attr_reader :model_col, :column, :model_sym
18
+
19
+ def initialize(model_col, column, view, model_sym) # :nodoc:
20
+ super()
21
+ @column = column
22
+ @model_sym = model_sym
23
+ @model_col = model_col
24
+ @view = view
25
+ @validate_block = Proc.new { |text, model_sym, row, view| true }
26
+ @edited_callback = nil
27
+ self.signal_connect('edited') do |ren, path, text|
28
+ next unless iter = @view.model.get_iter(path)
29
+ if @validate_block.call(text, @model_sym, @view.vr_row(iter), @view)
30
+ iter[@model_col] = (iter[@model_col].is_a? String) ? text : text.to_f
31
+ @edited_callback.call(@model_sym, @view.vr_row(iter)) if @edited_callback
32
+ end
33
+ end
34
+ end
35
+
36
+ end
37
+
38
+ end
@@ -0,0 +1,47 @@
1
+ module VR
2
+
3
+ #
4
+ # This renderer has a slightly different validate_block than the others. Its validate_block will be called with three
5
+ # parameters:
6
+ #
7
+ # @view.renderer(:name).validate_block = Proc.new { | model_sym, row, view |
8
+ # (row[:name].length < 3)
9
+ # }
10
+ #
11
+ # Also, you can use the VR::CellRendererToggle#edited= method to allow editing.
12
+ #
13
+
14
+ class CellRendererToggle < Gtk::CellRendererToggle
15
+
16
+ attr_accessor :validate_block, :edited_callback
17
+ attr_reader :model_col, :column, :model_sym
18
+
19
+ def initialize(model_col, column, view, model_sym)
20
+ super()
21
+ @model_col = model_col
22
+ @model_sym = model_sym
23
+ @column = column
24
+ @view = view
25
+ @edited_callback = nil
26
+ @validate_block = Proc.new { |model_sym, row, view | true }
27
+ self.signal_connect('toggled') do |ren, path|
28
+ @view.model.each { |mod, path, iter| iter[@model_col] = false } if self.radio?
29
+ next unless iter = @view.model.get_iter(path)
30
+ if @validate_block.call(@model_sym, @view.vr_row(iter), @view)
31
+ iter[model_col] = !iter[model_col]
32
+ @edited_callback.call(@model_col, iter) if @edited_callback
33
+ end
34
+ end
35
+ end
36
+
37
+ def editable=(is_editable)
38
+ self.sensitive = is_editable
39
+ end
40
+
41
+ def set_editable(is_editable)
42
+ self.sensitive = is_editable
43
+ end
44
+
45
+ end
46
+
47
+ end
@@ -0,0 +1,43 @@
1
+
2
+
3
+ module VR
4
+
5
+ # The Combo class is for use with VR::ListView and VR::TreeView. It
6
+ # simply holds the values for a combobox to be displayed in the view.
7
+ # It is not a visual component, it just holds data.
8
+ #
9
+ # It is one of the data types that you can pass to the constructors for VR::ListView and
10
+ # VR::TreeView. For example, to make the second column render as a combobox:
11
+ #
12
+ # @view = VR::Treeview.new(Gdk::Pixbuf, VR::Combo, String)
13
+ #
14
+ # Then when you add data to the model:
15
+ #
16
+ # @view.add_row(@pixbuf, VR::Combo.new("Mr", "Mr", "Mrs", "Ms"), "Hello World")
17
+ #
18
+ # This would set the combobox for this row so that "Mr" is selected, and "Mr", "Mrs", and "Ms" are the choices.
19
+
20
+
21
+ class ComboCol # can't subclass String tried twice!!!
22
+
23
+ attr_accessor :selected, :selections
24
+
25
+ # This defines a combobox for a row in VR::ListView or VR::TreeView. You pass three or more strings
26
+ # to the constructor, and the first string is the selected value that appears in the row in the
27
+ # view.
28
+ #
29
+ # - current_selection (type String)
30
+ # - selections (comma separated list of Strings)
31
+ #
32
+ def initialize(current_selection, *selections)
33
+ @selected = current_selection
34
+ @selections = selections
35
+ end
36
+
37
+ def valid?(str)
38
+ @selections.include?(str)
39
+ end
40
+
41
+ end
42
+
43
+ end
@@ -0,0 +1,23 @@
1
+
2
+ module VR
3
+
4
+ class CurrencyCol
5
+
6
+ attr_accessor :value, :format
7
+
8
+ def initialize(value, format = "$%.2f")
9
+ set_value(value, format)
10
+ end
11
+
12
+ def set_value(value, format = "$%.2f")
13
+ @value = value
14
+ @format = format
15
+ end
16
+
17
+ def to_s
18
+ format % @value.to_f
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,20 @@
1
+
2
+
3
+ module VR
4
+
5
+ class DateCol
6
+
7
+ attr_accessor :date
8
+
9
+ def initialize(date, format = "%Y-%m-%d")
10
+ set_date(date, format)
11
+ end
12
+
13
+ def set_date(date, format = "%Y-%m-%d")
14
+ @date = date
15
+ # gsub!(self, @date.strftime(format))
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -0,0 +1,27 @@
1
+
2
+ module VR
3
+
4
+ class ImageCol #< Gdk::Pixbuf
5
+
6
+ include GladeGUI
7
+
8
+ def initialize(image)
9
+ # super(File.dirname(__FILE__) + "/../../../img/image-x-generic.png")
10
+ @image1 = image
11
+ end
12
+
13
+ def before_show()
14
+ @builder["window1"].resize 500, 360
15
+ end
16
+
17
+ def to_s
18
+ "<Img>"
19
+ end
20
+
21
+ # def visual_attributes
22
+ # { :pixbuf => self }
23
+ # end
24
+
25
+ end
26
+
27
+ end
@@ -0,0 +1,27 @@
1
+
2
+ # ==The VR Module hold all the classes of the vrlib gem. The most useful APIs are:
3
+ #
4
+ # ===GladeGUI -- loads glade form
5
+ # ===VR::ListView -- makes Gtk::TreeView easy!
6
+
7
+
8
+ module VR
9
+
10
+ # This class is simply a wrapper for an Integer. It signals VR::Listview's
11
+ # and VR::Treeviews constructor to make this column a progressbar using
12
+ # VR::CellRendererProgress. For example, whwn you create a VR::ListView,
13
+ # you can pass VR::Progress as a column type:
14
+ #
15
+ # @view = VR::ListView.new(String, VR::Progress, Gdk::Pixbif)
16
+ #
17
+ # This makes model_col #1 a progress bar. When you set the value of the column,
18
+ # provide an integer value from 0 to 100:
19
+ #
20
+ # @view.add_row("Hello World", 65, @pixbuf)
21
+ #
22
+ #
23
+
24
+ class ProgressCol < Integer
25
+ end
26
+
27
+ end
@@ -0,0 +1,11 @@
1
+ module VR
2
+
3
+ class SpinCol < Gtk::Adjustment
4
+
5
+ def initialize(val, min, max, step)
6
+ super(val, min, max, step, 0, 0)
7
+ end
8
+
9
+ end
10
+
11
+ end
@@ -0,0 +1,65 @@
1
+
2
+ module VR
3
+
4
+ # The TextCol class is a simple text editor for editing strings of data:
5
+ #
6
+ # http://visualruby.net/img/textcol.jpg
7
+ #
8
+ # It is a very useful class when you want to display and edit long strings
9
+ # of data in a VR::ListView. To create a coulmn of long strings in a VR::ListView,
10
+ # simply define the column type as VR::TextCol:
11
+ #
12
+ # @view = VR::ListView.new(:name => String, :quote => VR::TextCol)
13
+ # row = @view.add_row
14
+ # row[:name] = "Eric"
15
+ # row[:quote] = VR::TextCol.new("I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. - Umberto Eco) ")
16
+ #
17
+ # The above listview will only display the first 20 characters of the quote, so
18
+ # it won't destroy the appearance of the listview. When a user clicks on the
19
+ # quote column, a window like the one above will appear.
20
+ #
21
+ # See the example project, "listview_objects" for more.
22
+
23
+ class TextCol
24
+
25
+ include GladeGUI
26
+
27
+ attr_accessor :text, :length_to_display
28
+ #
29
+ # - text - String value of the field
30
+ # - length_to_display - Integer number of characters to display in the listview. Default: 20
31
+ #
32
+ def initialize(text, length_to_display = 20)
33
+ @length_to_display = length_to_display
34
+ @text = text
35
+ end
36
+
37
+ def before_show()
38
+ @builder["window1"].resize 650, 360
39
+ end
40
+
41
+ # The to_s method outputs the string that is shown in the VR::ListView. By default
42
+ # it will display the first 20 characters of the string. If you
43
+ # want to change the number of characters it displays, change the
44
+ # value of the length_to_display variable.
45
+
46
+ def to_s
47
+ (@text.size > @length_to_display ? @text[0, @length_to_display - 4] + "..." : @text).gsub("\n"," ")
48
+ end
49
+
50
+ def buttonSave__clicked(*args) # :nodoc:
51
+ get_glade_variables()
52
+ @builder["window1"].destroy
53
+ end
54
+
55
+ def buttonCancel__clicked(*args) # :nodoc:
56
+ @builder["window1"].destroy
57
+ end
58
+
59
+ def <=>(text_col)
60
+ self.text <=> text_col.text
61
+ end
62
+
63
+ end
64
+
65
+ end