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

Zurück zum Archiv-Index

ruby-****@sourc***** ruby-****@sourc*****
2012年 9月 20日 (木) 10:01:07 JST


-------------------------
REMOTE_ADDR = 184.145.80.187
REMOTE_HOST = 
        URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-treev-parts
-------------------------
@@ -298,7 +298,23 @@
  # The following is WRONG:
  column = Gtk::TreeViewColumn.new("Buy", renderer, "text" => BUY_IT, :foreground => "#ff0000")  # ERROR !!!
 
-In our example program (liststore.rb) above, we are defining three individual single columns, where we have a single name/value pair for each attribute. Finally we have to add (append) our newly defined column to the tree view.
+Providing you have the renderer object you could set these attributes for it by writing:
+
+ renderer.text = "Yes, buy this product"
+ renderer.foreground = "#ff0000"
+
+This would only change the tree view but not the model.
+
+To understand why the initialization of the column constructor above in the first of the two code snippet 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: 
+
+ iter[BUY_IT]   = list[i].buy
+ iter[QUANTITY] = list[i].quantity
+ iter[PRODUCT]  = list[i].product
+
+However, this code does two things it sets both the columns in the model and also the columns in the view. 
+
+As you see there are many issues to consider when dealing with tree model and tree view. It is not easy to learn all the aspects of this mechanism up front before you start to experiment with the programs. The best place to start investigating a program like our "liststore.rb" is the place where the tree view is initialized. In our example program this is the ((*setup_tree_view*)) method. In it, we are defining three individual single columns, where we have a single name/value pair for each attribute. Finally we have to add (append) our newly defined column to the tree view. Copy the program to your system and start playing with it. The above discussions should provide you with plenty of material to try different alternatives. 
+
 
 
 




ruby-gnome2-cvs メーリングリストの案内
Zurück zum Archiv-Index