ruby-****@sourc*****
ruby-****@sourc*****
2012年 9月 28日 (金) 10:18:56 JST
------------------------- REMOTE_ADDR = 184.145.80.187 REMOTE_HOST = URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-treev-rr ------------------------- @@ -207,30 +207,17 @@ If you want to remove all rows you can use Gtk::ListStore#clear and Gtk::TreeStore#clear. -The following summary example demonstrates some of the points learned here: +{{image_right "TreeStore-n-Refs.png"}} -((*Example employing some of the items discussed on this page:*)) +The following summary example demonstrates some of the points we learned in this 'Referencing Rows' chapter. (1) We manually created three levels deep tree view. (2) implemented the 'set_cell_data_func' code block for 'Age' tree view column which maps to model's column three, however, this is not explicitly stated when column is instantiated. Nevertheless, we obtain the age value from model via((*year_born=iter[2]*)), and generate the age of the person if it is a valid value. More interesting feature is how we handle foreground colour with the Gtk::CellRendererText#forefround_set and Gtk::CellRendererText#forgeground= methods. (3) Use virtual tree view column with title or header 'Path & Depth', which has no corresponding model column. In it we display depth and path values for each row. And lastly: (4) in the button we test, if we can access a row in the tree view by providing a string value "2:0:1" for path by retrieving its tree row reference. -{{image_right "TreeStore-n-Refs.png"}} +((*manually-build-multilevel-tview-depthNpath.rb*)) +{{br}} #!/usr/bin/env ruby require 'gtk2' - - =begin - 1. create 3 levels deep TreeStore - - 2. Implement {{ set_cell_data_func }} - - 3. Demonstrate how a renderer property (foreground) is handled - via {{r.foreground="red"}}, and {{fu_r.foreground_set=false}} - inside (as well as outside) the {{ set_cell_data_func }} - - 4. Use a virtual view column to dynamically display path and depth - - 5. Test the feature showing how to obtain an iter from a tree reference - =end - + treestore = Gtk::TreeStore.new(String, String, Integer) # Append a toplevel row and fill in some data @@ -304,7 +291,-6 @@ # Create a cell data function to calculate age col.set_cell_data_func(renderer) do |col, renderer, model, iter| - year_now = 2012 # To save code not relevent to the example + year_now = 2012 # To save code not relevant to the example year_born = iter[2] if (year_born <= year_now) && (year_born > 0)