[wxruby-users] wxRuby dialog separate from main Ruby script execution

Mario Steele mario at ruby-im.net
Thu Jan 15 06:18:30 EST 2009


Well, given the example, it's kinda confusing how you are setting this Log
Window class up, and how things are truely initializing.  First of all, you
really should be starting the main_loop at the top level of your code, not
inside a Window class method, even if it's a module/singleton method.

Second, if your using threads, you need to setup a point for wxRuby to break
from it's processing of code internally in the main_loop, to yield back
control to Ruby under Ruby 1.8.  Ruby 1.9 will work perfectly fine, as the
threads are system native threads, not Green threads as in 1.8.

Third, if you have a single point of entry into your own application, that
starts everything off, it would be best to call that method inside the
on_init of your App instance inside a thread, and then do the previous
method of yielding control back to ruby from wxRuby.  You can yield the
control back to Ruby, by doing Wx::Timer.every(55) { Thread.pass }.  This
will execute a timer every 55 milliseconds, that will call Thread.pass to
give the next thread a bit of the CPU Scheduling, before returning back to
the wxRuby main_loop.

Lastely, if you don't have a single point of entry into your application,
then I would suggest making one, and doing as I described above, as this
will make things easier to track, should something go wrong.

hth,

Mario

On Thu, Jan 15, 2009 at 4:29 AM, David Muir <lists at ruby-forum.com> wrote:

> Hi,
>
> We have quite a large codebase in Ruby which uses Log4r to log errors,
> warnings etc.  I have been trying to create a log window dialog using
> wxRuby that can be popped up if a piece of code generates an error or
> warning in one of our scripts.
>
> E.g.
>   GUI::LogWindow::show_dialog( ) do
>     # Do something that will log messages.
>   end
>
>   def LogWindow::show_dialog( log, auto_popup = false, title = 'Log',
> &block )
>  log_window_thread = Thread.new do
>    begin
>      LogDialogApp.new( log, auto_popup, title ).main_loop( )
>    rescue Exception => ex
>      throw unless ( 'exit' == ex.message )
>    end
>  end
>
>  yield if ( block_given? )
>  log_window_thread.join( )
>   end
>
> My current problem is that when the wxRuby's main_loop is invoked no
> Ruby code gets executed.  Is there any way around this?  Or is this a
> limitation of using wxRuby?
>
> Any suggestions appreciated.
> Cheers,
> David
> --
> 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/20090115/f2d92c02/attachment.html>


More information about the wxruby-users mailing list