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

アーカイブの一覧に戻る

ruby-****@sourc***** ruby-****@sourc*****
2012年 10月 10日 (水) 07:45:19 JST


-------------------------
REMOTE_ADDR = 184.145.82.7
REMOTE_HOST = 
        URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-treev-cbbr
-------------------------
@@ -169,3 +169,99 @@
  window.add(scrolled_win)
  window.show_all
  Gtk.main
+
+
+
+
+
+
+== Progress Bar Renderers
+
+{{image_left("treev-cbbr-progbar.png")}}
+
+Another type of cell renderer is Gtk::CellRendererProgress, which implements the Gtk::ProgressBar widget. Gtk::CellRendererProgress is limited in one way, it does not support pulsing, it only allows you to set the current value of the progress bar. It provides two properties ((*text*)) and ((*value*))
+
+The progress bar state is defined by the value "property" which is an integer between 0 and 100. A value of 0 means empty, and 100 a full progress bar. Since the value is stored as an integer, the tree model model column corresponding to the value of the progress bar should have the type Integer. 
+
+The second property provided by the Gtk::CellRendererProgress is text. This property is a string that will be drawn over the top of the progress bar. Following is the example using progress bar renderer:
+
+((*liststore-progbarr.rb*))
+
+ #!/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.
+ 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)
+   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)
+   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
+ 
+ list = [
+   ActList.new("www.alpha.net", 55),
+   ActList.new("www.boby.com", 15),
+   ActList.new("turtle.on.ca", 85),
+   ActList.new("www.kwackers.org", 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)
+ 
+ # 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.next!
+ end
+ 
+ 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
+     sleep 0.05
+     iter.next!
+   }
+ 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.add(scrolled_win)
+ window.show_all
+ Gtk.main




ruby-gnome2-cvs メーリングリストの案内
アーカイブの一覧に戻る