# Help with clean exits

**URL:** <https://www.ruby-forum.com/t/help-with-clean-exits/180944>\
**Category:** wxRuby\
**Created:** [January 1, 2010, 11:39am UTC](https://www.ruby-forum.com/t/help-with-clean-exits/180944 "2010-01-01T11:39:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pnomolos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/85f322/32.png) [@pnomolos](https://www.ruby-forum.com/u/pnomolos)\
**Post date:** [January 1, 2010, 11:39am UTC](https://www.ruby-forum.com/t/help-with-clean-exits/180944/1 "2010-01-01T11:39:34Z")

</div>

require ‘wx’  
require ‘Eyes.rb’  
require ‘date.rb’

# I am trying to close then mainframe window cleanly so I don’t have to

# shut down ruby1.9 via `kill -9 …’. When I press cancel on the

first

# (welcome) window it does exit cleanly. However when I try to shut

down

# the main window using the close box, it hangs. It doesn’t even use

the

# on\_window\_close window event. How do I rectify this situation? Any

# help would be appreciated. If you want more info just ask. Thanks

# Happy new year everyone!

# 

# Philip

class Main\_Frame \< EyesFrame

```
def on_init()
    evt_close {|event| on_window_close(event)}
end

def on_window_close(event)
  puts (" ************")
    destroy()
end

```

end

class EW\_Dialog \< EW\_dialog  
def on\_init()  
set\_affirmative\_id(Wx::ID\_OK)  
set\_escape\_id(Wx::ID\_CANCEL)  
end  
end

class Waiter

# This method waits x seconds to allow other processing to

# take place such as opening a new window

```
def initialize(secs)
    startTime = Time.new()

  startSecs = startTime.hour() * 60 * 60
  startSecs += (startTime.min() * 60)
  startSecs += startTime.sec()

  puts "startSecs #{startSecs}"
  endSecs = startSecs + secs
  puts "endSecs #{endSecs}"
  currSecs = startSecs

    while (currSecs < endSecs)
        currTime = Time.new
        currSecs = currTime.hour() * 60 * 60
      currSecs += (currTime.min() * 60)
      currSecs += currTime.sec()
     puts ("currentsecs: #{currSecs}")
    end
end

```

end

class MyApp \< Wx::App  
def on\_init()  
@screen1 = EW\_Dialog.new  
# show welcome dialog  
case @screen1.show\_modal()  
when Wx::ID\_CANCEL then  
@screen1.close  
puts(“Cancel”)  
exit\_main\_loop()  
when Wx::ID\_OK  
@screen1.close  
@screen2 = Main\_Frame.new()  
@screen2.show  
set\_top\_window(@screen2)  
Waiter.new(1) #wait x seconds  
end #case  
end #def  
end # class

app = MyApp.new  
app.main\_loop
