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

Back to archive index

ruby-****@sourc***** ruby-****@sourc*****
2012年 10月 14日 (日) 05:08:52 JST


-------------------------
REMOTE_ADDR = 184.145.82.7
REMOTE_HOST = 
        URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-treev-cbbr
-------------------------
@@ -349,11 +349,11 @@
  LOCATION_COLUMN = 0; VALUE_COLUMN = 1
  
  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)
+   ActList.new("www.alpha.net",    0),
+   ActList.new("www.boby.com",     0),
+   ActList.new("turtle.on.ca",     0),
+   ActList.new("www.kwackers.org", 0),
+   ActList.new("www.wealthy.org",  0)
  ]
  
  # Create a new tree model with two columns, as 
@@ -370,13 +370,31 @@
  
  setup_tree_view(treeview)
  
- thread = Thread.start do
-   iter = store.iter_first
-   loop do
-     iter[VALUE_COLUMN] = iter[VALUE_COLUMN] + 5 if iter[VALUE_COLUMN] < 100
-     sleep 0.05
-     iter.next!
+ # Create as many threads as there are items in the list containing ActList objects.
+ # Each thread updates a progress bar for one line in our tree view, by setting the
+ # VALUE_COLUMN column in the store list model.   
+ aiter = []
+ iter = store.iter_first
+ (1..list.size).each do |ii| # {{ ii }} internal index, private to each iteration & thread
+   aiter[ii] = iter.clone
+   Thread.new do
+     iiter = aiter[ii]
+     r_factor = rand(20) + 1
+     Thread.current[:id] = "#{ii}: #{iiter[LOCATION_COLUMN]}"
+ 
+     loop do
+       break if iiter[VALUE_COLUMN] >= 100
+       iiter[VALUE_COLUMN] = iiter[VALUE_COLUMN] + 5 if iiter[VALUE_COLUMN] < 100
+       sleep (0.05 * (r_factor))
+     end
+     "Thread #{(Thread.current)[:id]} ... done" # set this thread's value attribute
    end
+   iter.next!
+ end
+ 
+ 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
  
  scrolled_win = Gtk::ScrolledWindow.new




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