ruby-****@sourc*****
ruby-****@sourc*****
2012年 9月 21日 (金) 03:23:08 JST
------------------------- REMOTE_ADDR = 184.145.80.187 REMOTE_HOST = URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-treev-parts ------------------------- @@ -292,6 +292,7 @@ Note, that in the second code segment above under subtitle "Columns", you could use either of Gtk::TreeViewColumn#set_attributes or Gtk::TreeViewColumn#add_attribute instance methods to associate the cell renderer with model column number. I should warn you that there are times when you will need to use the longer more verbose (as in second code snippet above) way of creating tree view columns. We will talk about this after we learn the basics (if you wish you can peek ahead to the next page into the section called "((<Multi-item Super Columns|tut-gtk2-treev-trees#Multi-item Super Columns>))".) +:Dissecting the column creation When defining a tree view column we need to provide (1) the text title for the header ("Buy" in our case here), (2) the renderer to be used to render all the cells for this column in every row of this list store, and (3) the value (BUY_IT) either as a parameter (if Gtk::TreeViewColumn#add_attribute is used), or in the event that a statement uses a hash, such as in Gtk::TreeViewColumn.new and in Gtk::TreeViewColumn#set_attributes, any number of attribute name/value pairs in the hash, where the name represents the attribute/property name (:text) and the value (BUY_IT) a column number in the model. The use of word "value" in all these cases is rather mis-fortunate and a bit of a misnomer -((*for any tree column view the value in the name/value pair here represents the column number, not the attribute's value!*))It is very important to realize that you can not set property values here. For instance one can not set((*:foreground*))attribute's value to a desired colour within Gtk ::TreeViewColumn.new code as is shown in the following erroneous code segment: @@ -306,7 +307,8 @@ However, this would only change the tree view but not the model. Also you must know where you can and can not change a renderer's attributes. For instance placing the line((*"renderer.text = 'Yes, buy this product'"*))in "setup_tree_view" method may have no effect, however setting the value of "foreground" attribute there would work. The best place to change renderer's attributes is in the "Cell Data Function" which you do not learn as one of the basic tools here and we only explain it in the next chapter since it is one of more exotic features of tree view management mechanisms but nevertheless used frequently. -To understand why the initialization of the column constructor above in the first of the two code snippets is wrong you must know that the :text and :foreground properties are the render's attributes. As pointed out in the discussion in the previous paragraph the values in the constructor's hash parameter should be integers since they represent the column numbers for the actual values of these attributes in the model. If you recall in the paragraph above entitled((*Navigating tree model*))we mentioned that most of the tree model interface consists of operations on a Gtk::TreeIter. If you look at the "liststore.rb" program listing above you will notice that these iterators are used to access the model as if it were an array: +To understand why the initialization of the column constructor above in the first of the two code snippets is wrong you must know that the :text and :foreground properties are the render's attributes. As pointed out in the discussion under the title((*Dissecting the column creation *))above in this section the values in the constructor's hash parameter should be integers since they represent the column numbers for the actual values of these attributes in the model. If you recall in the paragraph above entitled((*Navigating tree model*))we mentioned that most of the tree model interface consists of operations on a Gtk::TreeIter. If you look at the "liststore.rb" program listing above you will notice that these iterators are used to access the model as if it were an array: iter[BUY_IT] = list[i].buy iter[QUANTITY] = list[i].quantity