w=Gtk::Window.new
w.signal_connect(‘destroy’) do
Gtk.main_quit
end
w.show_all
Thread.new do
while true
puts File.read FILE # blocked, if comment the line, the script
will print ‘—’ every second as expect.
puts ‘-’*80
sleep 1
end
end
Gtk.main
It works as expected for me. That is, it prints out the file followed
by the line of dashes every second. I’m using the packages in
Ubuntu 10.4 (lucid): Ruby 1.8.7 and ruby-gnome 19.3.
I got fooled at the beginning though because the file is as big as
my terminal. So it prints out a new page and I don’t see anything
unless I scroll back.
It works as expected for me. That is, it prints out the file followed
by the line of dashes every second. I’m using the packages in
Ubuntu 10.4 (lucid): Ruby 1.8.7 and ruby-gnome 19.3.
I got fooled at the beginning though because the file is as big as
my terminal. So it prints out a new page and I don’t see anything
unless I scroll back.
MikeC
Thank you for reply.
Quite strange, I still have no idea how to solve the Gtk.main or linux
conflict(maybe), but it solved when I try Gtk.events_pending? and
Gtk.main_iteration.
Patched code:
require ‘rubygems’
require ‘gtk2’
w=Gtk::Window.new
w.signal_connect(‘destroy’) do
$done=true
end
w.show_all
Thread.new do
while true
puts File.read FILE
puts ‘-’*80
sleep 1
end
end
$done=false
begin
while Gtk.events_pending?
Gtk.main_iteration
end
sleep 0.02
end until $done
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.