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

Back to archive index

ruby-****@sourc***** ruby-****@sourc*****
2012年 10月 12日 (金) 02:52:47 JST


-------------------------
REMOTE_ADDR = 184.145.82.7
REMOTE_HOST = 
        URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-treev-cbbr
-------------------------
@@ -326,35 +326,27 @@
  #!/usr/bin/env ruby
  require 'gtk2'
  
- # Add three columns to the Gtk::TreeView. All three of the
- # columns will be displayed as text, although one is a Boolean
- # value and another is an integer.
+ # Add two columns to the Gtk::TreeView. The first will display
+ # location as text, and the second the progress bar.
  def setup_tree_view(treeview)
    # Create a new Gtk::CellRendererText, add it to the tree
    # view column and append the column to the tree view.
    renderer = Gtk::CellRendererText.new
-   column = Gtk::TreeViewColumn.new("Location", renderer, "text" => ActList::LOCATION)
+   column = Gtk::TreeViewColumn.new("Location", renderer, "text" => LOCATION_COLUMN)
    treeview.append_column(column)
-   
+ 
    # Create a new Gtk::CellRendererProgress, add it to the tree
    # view column and append the column to the tree view.
    renderer = Gtk::CellRendererProgress.new
-   column = Gtk::TreeViewColumn.new("Progress", renderer, "value" => ActList::ACTION)
+   column = Gtk::TreeViewColumn.new("Progress", renderer, "value" => VALUE_COLUMN)
    treeview.append_column(column) 
  end
  
- window = Gtk::Window.new(Gtk::Window::TOPLEVEL)
- window.resizable = true
- window.title = "Progress List"
- window.border_width = 10
- window.signal_connect('delete_event') { Gtk.main_quit }
- window.set_size_request(250, 150)
- 
  class ActList
    attr_accessor :location, :action
    def initialize(l, a); @location, @action = l, a; end
-   LOCATION = 0; ACTION = 1
  end
+ LOCATION_COLUMN = 0; VALUE_COLUMN = 1
  
  list = [
    ActList.new("www.alpha.net", 55),
@@ -364,40 +356,30 @@
    ActList.new("www.wealthy.org", 10)
  ]
  
- treeview = Gtk::TreeView.new
- setup_tree_view(treeview)
-   
  # Create a new tree model with two columns, as 
  # string and integer.
- store = Gtk::ListStore.new(String, Integer)
+ treeview = Gtk::TreeView.new(store = Gtk::ListStore.new(String, Integer))
  
  # Add all of the products to the GtkListStore.
  list.each_with_index do |e, i|
      iter = store.append
-     iter[ActList::LOCATION] = list[i].location
-     iter[ActList::ACTION]   = list[i].action
+     iter[LOCATION_COLUMN] = list[i].location
+     iter[VALUE_COLUMN]   = list[i].action
      iter.next!
  end
  
+ setup_tree_view(treeview)
+ 
  thread = Thread.start do
-   new_val = 0
    iter = store.iter_first
-   loop {
-     new_val = iter[ActList::ACTION] + 5
-     new_val = 0 if new_val > 100
-     iter[ActList::ACTION] = new_val
+   loop do
+     iter[VALUE_COLUMN] = iter[VALUE_COLUMN] + 5 if iter[VALUE_COLUMN] < 100
      sleep 0.05
      iter.next!
-   }
+   end
  end
  
- # Add the tree model to the tree view
- treeview.model = store
- 
  scrolled_win = Gtk::ScrolledWindow.new
  scrolled_win.add(treeview)
  scrolled_win.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC)
  
+ window = Gtk::Window.new("Progress List")
+ window.resizable = true
+ window.border_width = 10
+ window.signal_connect('destroy') { Gtk.main_quit }
+ window.set_size_request(250, 150)
  window.add(scrolled_win)
  window.show_all
  Gtk.main




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