ruby-****@sourc*****
ruby-****@sourc*****
2012年 10月 8日 (月) 04:46:42 JST
------------------------- REMOTE_ADDR = 184.145.80.187 REMOTE_HOST = URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-treev-crs ------------------------- @@ -48,23 +48,21 @@ #!/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. - def setup_tree_view(treeview) - # Create a new GtkCellRendererText, add it to the tree - # view column and append the column to the tree view. + # Toggle Button Cell Renderer + # Add three columns to the GtkTreeView. This time first + # Boolean 'Buy' column will appear as check-button, the + # other two columns 'Count' and 'Product' remain Integer + # and String respectively. + def setup_tree_view(treeview) renderer = Gtk::CellRendererToggle.new column = Gtk::TreeViewColumn.new("Buy", renderer, "active" => GItm::BUY_INDEX) - - renderer.activatable = true renderer.signal_connect('toggled') do |w, path| iter = treeview.model.get_iter(path) iter[GItm::BUY_INDEX] = !iter[GItm::BUY_INDEX] if (iter) end treeview.append_column(column) - + renderer = Gtk::CellRendererText.new column = Gtk::TreeViewColumn.new("Count", renderer, "text" => GItm::QTY_INDEX) treeview.append_column(column) @@ -73,13 +71,4 @@ treeview.append_column(column) end - window = Gtk::Window.new(Gtk::Window::TOPLEVEL) - window.resizable = true - window.title = "Grocery List" - window.border_width = 10 - window.signal_connect('delete_event') { Gtk.main_quit } - window.set_size_request(275, 200) - class GItm attr_accessor :product_type, :buy, :quantity, :product def initialize(t,b,q,p) @@ -127,7 +118,-2 @@ list[i].quantity += list[j].quantity if list[j].buy j += 1 end - + # Add the category as a new root (parent) row (element). parent = store.append(nil) # store.set_value(parent, GItm::BUY_INDEX, list[i].buy) # <= same as below @@ -152,6 +143,3 @@ scrolled_win = Gtk::ScrolledWindow.new scrolled_win.add(treeview) scrolled_win.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC) + + window = Gtk::Window.new("Grocery List") + window.resizable = true + window.border_width = 10 + window.signal_connect('destroy') { Gtk.main_quit } + window.set_size_request(275, 200) window.add(scrolled_win) window.show_all Gtk.main