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,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) { |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) { |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
+ VR.msg("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) { |x,y| x[@model_col] <=> y[@model_col] }
28
+ @show_block = Proc.new { |obj| obj.show() if obj.respond_to? "show" }
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[@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) { |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
+ VR.msg("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) { |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