Hello El,
On Thu, Nov 5, 2009 at 1:09 PM, El Gato <lists at ruby-forum.com> wrote:
> I''m having a heck of a time trying to keep my app appearing
responsive
> while shelling out to long running commands / downloading large files.
> I''ve read everything I can find on the subject, which got me what
I have
> now, but nothing I try seems to work. How do I keep the interface
> refreshed so that it''s not just a plain white box after other
windows
> are opened over it, etc? Below is a rough idea of what I have. What am
> I missing?
>
> def on_init
> t = Wx::Timer.new(self, 55)
> evt_timer(55) { Thread.pass }
> t.start(25)
>
> @frame = MyFrame.new
> @frame.show
> end
>
> class MyFrame
> ...
> def on_download(event)
> ...
> Thread.new { download(file) }
> ...
> end
>
> # on an event, download the file
> def download(file_obj)
> Wx::WindowDisabler.disable(self) do
> info = Wx::BusyInfo.busy(''Please wait...'', self) do
> Wx::log_message("Getting file #{file_obj.name}")
> file_obj.fetch # uses open-uri to get a large binary
> end
> end
> ...
> end
> end
>
There needs to be a Thread.pass in whatever your fetch method on file_obj
runs, if your downloading a file, then you need to use Async Sockets, and
utilize IO.select() to detect activity on a socket, if no activity, do a
Thread.pass, if there is activity, read it, then do a Thread.pass.
It has to work between the Main thread, which handles the Ruby events, and
the wxWidgets thread, which handles the GUI events internally.
hth,
Mario
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> wxruby-users mailing list
> wxruby-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/wxruby-users
>
--
Mario Steele
http://www.trilake.net
http://www.ruby-im.net
http://rubyforge.org/projects/wxruby/
http://rubyforge.org/projects/wxride/
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/wxruby-users/attachments/20091105/d124cb3d/attachment.html>