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

Back to archive index

ruby-****@sourc***** ruby-****@sourc*****
2012年 8月 15日 (水) 09:59:36 JST


-------------------------
REMOTE_ADDR = 184.145.90.35
REMOTE_HOST = 
        URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-treev-parts
-------------------------
@@ -118,7 +118,7 @@
 ((*liststore.rb*))
  #!/usr/bin/env ruby
  require 'gtk2'
-
+ 
  # Add three columns to the GtkTreeView. All three of the
  # columns will be displayed as text, although one is a boolean
  # value and another is an integer.
@@ -126,29 +126,31 @@
    # Create a new GtkCellRendererText, add it to the tree
    # view column and append the column to the tree view.
    renderer = Gtk::CellRendererText.new
-   column = Gtk::TreeViewColumn.new("Buy", renderer, "text" => $buy_it)
+ 
+   # render's propery will effect entire column
+   renderer.foreground = "#ff0000"
+   column   = Gtk::TreeViewColumn.new("Buy", renderer,  :text => BUY_IT)
    treeview.append_column(column)
    renderer = Gtk::CellRendererText.new
-   column = Gtk::TreeViewColumn.new("Count", renderer, "text" => $quantity)
+   column   = Gtk::TreeViewColumn.new("Count", renderer, :text => QUANTITY)
    treeview.append_column(column)
    renderer = Gtk::CellRendererText.new
-   column = Gtk::TreeViewColumn.new("Product", renderer, "text" => $product)
+   column   = Gtk::TreeViewColumn.new("Product", renderer, :text => PRODUCT)
    treeview.append_column(column)
  end
  
- window = Gtk::Window.new(Gtk::Window::TOPLEVEL)
+ window = Gtk::Window.new("Grocery List")
  window.resizable = true
- window.title = "Grocery List"
  window.border_width = 10
  
- window.signal_connect('delete_event') { Gtk.main_quit }
- window.set_size_request(250, 175)
+ window.signal_connect('destroy') { Gtk.main_quit }
+ window.set_size_request(250, 165)
  
  class GroceryItem
    attr_accessor :buy, :quantity, :product
    def initialize(b, q, p); @buy, @quantity, @product = b, q, p; end
  end
- $buy_it = 0; $quantity = 1; $product  = 2
+ BUY_IT = 0; QUANTITY = 1; PRODUCT  = 2
  
  list = Array.new
  list[0] = GroceryItem.new(true,  1, "Paper Towels") 
@@ -160,7 +162,9 @@
  
  treeview = Gtk::TreeView.new
  setup_tree_view(treeview)
-   
+ 
  # Create a new tree model with three columns, as Boolean,
  # integer and string.
  store = Gtk::ListStore.new(TrueClass, Integer, String)
@@ -168,9 +170,12 @@
  # Add all of the products to the GtkListStore.
  list.each_with_index do |e, i|
      iter = store.append
-     store.set_value(iter, $buy_it,   list[i].buy)
-     store.set_value(iter, $quantity, list[i].quantity)
-     store.set_value(iter, $product,  list[i].product)
+ 
+     iter[BUY_IT]   = list[i].buy       # same as: >>> # store.set_value(iter, BUY_IT,   list[i].buy)
+     iter[QUANTITY] = list[i].quantity  # same as: >>> # store.set_value(iter, QUANTITY, list[i].quantity)
+     iter[PRODUCT]  = list[i].product   # same as: >>> # store.set_value(iter, PRODUCT,  list[i].product)
  end
  
  # Add the tree model to the tree view




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