Forum: wxRuby Ending Application When Window Closes

Posted by Michael Satterwhite (msatterwhite)
on 2010-02-15 02:24
OK, I *KNOW* I've got a case of tunnel vision here. I've written apps
that use wxRuby without a problem. Regardless, I don't see what I'm
doing wrong here. The code in my main routine looks like this:

class MyApp < Wx::App
  def on_init
    f = Video.new(nil)
    f.show
  end
end

app = MyApp.new
app.main_loop

There is only one simple window in the app - created via wxFormBuilder.
The window (a frame) displays cleanly. Problem: when I close this window
(either by clicking the "X" or by issuing a call to self.close() through
an event, the app doesn't exit. It simply goes to sleep. The only way I
see to close it is to go to a terminal and issue a "kill" command.

I'm running under Ubuntu 9.10.

Would someone be so kind as to point out what I'm missing - which I'm
sure is going to be obvious to everyone but me.
Posted by Chloro Form (tony44)
on 2010-03-08 14:43
I've had similar behavior and it was due to the app still holding 
resources. For me, I created a dock_icon that wants to be destroyed 
prior to exiting.

So, in short, check if your code still holds any resources that need 
manual destruction and call them in an on_close method ... for instance:

class YourFrame < Wx::Frame
 def initialize
  (...)

  evt_close :on_close

  (...)

  @dock_icon = Wx::TaskBarIcon.new
  @dock_icon.set_icon((Wx::Icon.new("icon.png", 
Wx::BITMAP_TYPE_PNG)),"Your App")
 end

(...)

 def on_close
  @dock_icon.destroy if @dock_icon
  destroy
 end
end
Posted by Alex Fenton (Guest)
on 2010-03-08 14:46
(Received via mailing list)
Tony Meier wrote:
> I've had similar behavior and it was due to the app still holding 
> resources. For me, I created a dock_icon that wants to be destroyed 
> prior to exiting.
Thanks Tony. Yes, this normally. As far as know, the only things that
need manual destruction are:

TaskBarIcon
Dialog, when created with no window as parent

What these have in common is that they are GUI elements which should
persist even if there is no main window (some kind of Wx::Frame) for the
application. Everything else should be cleaned up automatically as an
application runs and windows open and close.

a
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.