ruby-****@sourc*****
ruby-****@sourc*****
2012年 10月 14日 (日) 06:19:21 JST
------------------------- REMOTE_ADDR = 184.145.82.7 REMOTE_HOST = URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-treev-cbbr ------------------------- @@ -313,13 +313,16 @@ == 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*)) + +{{image_right("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' attribute 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: +The second 'text' property is a string that will be drawn over the top of the progress bar. This property does not have its column on the tree view, though you have to create the column for it in the model. Following is the example using progress bar renderer: ((*liststore-progbar.rb*)) @@ -338,7 +341,12 @@ # 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" => VALUE_COLUMN) + column = Gtk::TreeViewColumn.new("Progress", renderer, + {:value => VALUE_COLUMN, :text => PBTEXT_COLUMN} + ) treeview.append_column(column) end @@ -346,7 +351,12 @@ attr_accessor :location, :action def initialize(l, a); @location, @action = l, a; end end - LOCATION_COLUMN = 0; VALUE_COLUMN = 1 + LOCATION_COLUMN = 0; VALUE_COLUMN = 1; PBTEXT_COLUMN = 2 list = [ ActList.new("www.alpha.net", 0), @@ -358,13 +363,19 @@ # Create a new tree model with two columns, as # string and integer. - treeview = Gtk::TreeView.new(store = Gtk::ListStore.new(String, Integer)) + treeview = Gtk::TreeView.new(store = Gtk::ListStore.new(String, Integer, String)) # Add all of the products to the GtkListStore. list.each_with_index do |e, i| iter = store.append iter[LOCATION_COLUMN] = list[i].location iter[VALUE_COLUMN] = list[i].action + iter[PBTEXT_COLUMN] = nil iter.next! end @@ -385,14 +391,23 @@ loop do break if iiter[VALUE_COLUMN] >= 100 iiter[VALUE_COLUMN] = iiter[VALUE_COLUMN] + 5 if iiter[VALUE_COLUMN] < 100 + iiter[PBTEXT_COLUMN] = + (iiter[VALUE_COLUMN] > 45 && iiter[VALUE_COLUMN] < 66) ? "Almost done" : nil sleep (0.05 * (r_factor)) end + iiter[PBTEXT_COLUMN] = "Completed" "Thread #{(Thread.current)[:id]} ... done" # set this thread's value attribute end iter.next! end - sleep 0.5 # wait for threads to be created + sleep 0.1 # wait for threads to be created Thread.new do # This thread finishes after all threads are done! Thread.list.each {|t| puts "DEBUG: thread's value=[#{t.value}]" if t.key?(:id)} end @@ -405,7 +414,16 @@ window.resizable = true window.border_width = 10 window.signal_connect('destroy') { Gtk.main_quit } - window.set_size_request(250, 150) + window.set_size_request(275, 175) window.add(scrolled_win) window.show_all Gtk.main