Trouble with dialog based application

Hi,

A long time ago, I made some MFC GUI programming …
There was basically 2 kinds of application :

  • dialog based application : a simple app based on a dialog (without
    menu, toolbar, status bar …)
  • frame based app (Single Document or Multiple Document) with menu,
    toolbar, status bar …

I tried to make a dialog based app with wxRuby but the application
never exits !!

The following code based on a frame works as expected.
After the closing of the application window, the “exit from
application” string is output.

require “wx”

class HelloWorld < Wx::App
def on_init
helloframe = Wx::Frame.new(nil, “Hello World”)
Wx::StaticText.new(helloframe, “Hello World”)
helloframe.show
end
end

HelloWorld.new.main_loop
puts “exit from application”

If the frame is replaced by a dialog, the application seems to be
closed but the message is never output.
I tried both show and show_modal to display the window.

require “wx”

class HelloWorld < Wx::App
def on_init
hellodlg = Wx::Dialog.new(nil, “Hello World”)
Wx::StaticText.new(hellodlg, “Hello World”)
hellodlg.show_modal

hellodlg.show

end
end

HelloWorld.new.main_loop
puts “exit from application”

=> Am I doing something wrong ?

Cheers.

Chauk-Mean.

Hi Chauk-Mean

Chauk-Mean P wrote:

If the frame is replaced by a dialog, the application seems to be
closed but the message is never output.
I tried both show and show_modal to display the window.

If you have a parent-less dialog, you probably need to call destroy() on
the dialog when it closes to ensure it’s really killed.

http://wxruby.rubyforge.org/doc/dialog.html#Dialog_destroy

hth
alex

2007/10/9, Alex F. [email protected]:

If you have a parent-less dialog, you probably need to call destroy() on
the dialog when it closes to ensure it’s really killed.

http://wxruby.rubyforge.org/doc/dialog.html#Dialog_destroy

Thanks Alex. I missed this subtlety.

Nevertheless, this raises another question. As Ruby has garbage
collection (unlike c++ WxWidgets) , it would be great if a Wx::Dialog
without a parent can call destroy itself when the Ruby object is about
to be destroyed.
This would simplify the usage of Wx::Dialog and makes it behave like a
Frame with no parent.

Cheers.

Chauk-Mean.

Chauk-Mean P wrote:

As Ruby has garbage collection (unlike c++ WxWidgets) , it would be great if a Wx::Dialog
without a parent can call destroy itself when the Ruby object is about
to be destroyed.
I agree; I’ve wanted to fix this ‘subtlety’, as you put it, politely.
It’s come up before on the m.l.

However, it’s a bit tricky and I don’t know how to solve it. The order
of destruction of all GUI objects is always wxWidgets first, then ruby’s
garbage collection to clean up the ruby object at some point later. By
the time a ruby GC hook could run, the C++ object is dead and gone.

Also, wxWidgets doesn’t consider a parentless Dialog destroyed when it’s
closed, unlike frames. I guess it assumes a dialog-based app might want
to close and re-show the same Dialog several times.

cheers
alex