[ruby-gnome2-doc-cvs] [Ruby-GNOME2 Project Website] update - tut-gtk2-treev-trees

Back to archive index

ruby-****@sourc***** ruby-****@sourc*****
2012年 8月 27日 (月) 10:11:58 JST


-------------------------
REMOTE_ADDR = 70.49.49.99
REMOTE_HOST = 
        URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-treev-trees
-------------------------
@@ -333,6 +333,71 @@
  Gtk.main
 
 
+{{image_right("modelNview_demo.png")}}
+
+As previously announced, in the following example program entire row is manipulated with their respective ((*set_cell_data_funcs'*)) blocks. That is all columns (i.e. cell renderers) trigger execution of their pertinent((*set_cell_data_func*))functions and code blocks. What is also interesting is how in some of these blocks multiple data from different model columns are consulted. If you understand this program, you should also understand that model columns do not map to view columns.
+
+
+
+((*modelNview_demo.rb*)) ("Model/View Column Demo")
+
+ #!/usr/bin/env ruby
+ require 'gtk2'
+ 
+ def setup_tree_view(treeview)
+   renderer = Gtk::CellRendererText.new
+   column   = Gtk::TreeViewColumn.new("Row Number", renderer, { :text => ROW_NO, :background => ROW_BG_COLOR })
+   column.set_cell_data_func(renderer) do |col, renderer, model, iter|
+     renderer.background = iter[ROW_BG_COLOR]
+   end
+   treeview.append_column(column)
+ 
+   renderer = Gtk::CellRendererText.new
+   column   = Gtk::TreeViewColumn.new("Color Name", renderer, { :text => COLOR_NAME, :foreground => NAME_FG_COLOR })
+   column.set_cell_data_func(renderer) do |col, renderer, model, iter|
+     renderer.foreground  = iter[NAME_FG_COLOR]
+     renderer.background = iter[ROW_BG_COLOR]
+   end
+   treeview.append_column(column)
+ end
+ 
+ window = Gtk::Window.new("Model/View Column Demo")
+ window.resizable = true
+ window.border_width = 10
+ 
+ window.signal_connect('destroy') { Gtk.main_quit }
+ window.set_size_request(300, -1)
+ 
+ class ColorListItem
+   attr_accessor :rno, :bg, :name, :fg
+   def initialize(rno, bg, name, fg); @rno, @bg, @name, @fg = rno, bg, name, fg; end
+ end
+ ROW_NO = 0; ROW_BG_COLOR = 1; COLOR_NAME = 2; NAME_FG_COLOR = 3
+ 
+ list = Array.new
+ list[0] = ColorListItem.new(1, "lightblue",   "Red",    "#ff0000") 
+ list[1] = ColorListItem.new(2, "lightgreen",  "Blue",   "#0000ff")
+ list[2] = ColorListItem.new(3, "lightblue",   "Green",  "#00ff00")
+ list[3] = ColorListItem.new(4, "lightgreen",  "Black",  "#000000")
+ list[4] = ColorListItem.new(5, "lightblue",   "Purple", "#9900ff")
+ 
+ treeview = Gtk::TreeView.new(store = Gtk::ListStore.new(Integer, String, String, String))
+ setup_tree_view(treeview)
+ 
+ list.each_with_index do |e, i|
+   iter = store.append
+   iter[ROW_NO]        = list[i].rno  # same as: >>> # store.set_value(iter, ROW_NO, list[i].rno)
+   iter[ROW_BG_COLOR]  = list[i].bg
+   iter[COLOR_NAME]    = list[i].name
+   iter[NAME_FG_COLOR] = list[i].fg
+ end
+ 
+ window.add(treeview)
+ window.show_all
+ Gtk.main
+
+
+
 ###########
 
 == Multidimensional Tree Store




ruby-gnome2-cvs メーリングリストの案内
Back to archive index