# 'Are you sure?' custom dialog not exiting cleanly

**URL:** <https://www.ruby-forum.com/t/are-you-sure-custom-dialog-not-exiting-cleanly/179572>\
**Category:** wxRuby\
**Created:** [November 28, 2009, 10:51pm UTC](https://www.ruby-forum.com/t/are-you-sure-custom-dialog-not-exiting-cleanly/179572 "2009-11-28T22:51:27Z")\
**Posts on this page:** 2\
**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:** [November 28, 2009, 10:51pm UTC](https://www.ruby-forum.com/t/are-you-sure-custom-dialog-not-exiting-cleanly/179572/1 "2009-11-28T22:51:27Z")

</div>

The following program does not exit cleanly after pressing ‘Yes’ when  
asked  
‘Are you sure’?  
How do I free up the resources after exiting? You can use wxsugar  
(xrcise)  
to try out this mini program  
if you wish to create sample1.rb . Thank you.

# -Philip =========== asample1.rb

require ‘wx’  
require ‘sample1.rb’

class DIA\_Frame \< DiaFrame  
def on\_init  
set\_affirmative\_id(Wx::ID\_YES)  
set\_escape\_id(Wx::ID\_NO)

end  
end

class Main\_Frame \< MainFrame  
def on\_init  
evt\_close { confirm\_closure }  
evt\_button(@m\_butexit) {self.close}  
end

def confirm\_closure  
dlg = DIA\_Frame.new  
if(dlg.show\_modal==Wx::ID\_YES) then  
dlg.end\_modal(Wx::ID\_YES)  
self.destroy  
end  
end  
end

class MyApp \< Wx::App  
def on\_init  
main\_frame = Main\_Frame.new()  
set\_top\_window(main\_frame)  
set\_exit\_on\_frame\_delete(true)  
main\_frame.show  
end  
end

app = MyApp.new  
app.main\_loop  
============= sample1.xrc ===========================================

# This class was automatically generated from XRC source. It is not

# recommended that this file is edited directly; instead, inherit from

# this class and extend its behaviour there.

# 

# Source file: sample1.xrc

# Generated at: 2009-11-27 18:13:59 -0600

class MainFrame \< Wx::Frame

```
attr_reader :m_statictext1, :m_butexit

def initialize(parent = nil)
    super()
    xml = Wx::XmlResource.get
    xml.flags = 2 # Wx::XRC_NO_SUBCLASSING
    xml.init_all_handlers
    xml.load("sample1.xrc")
    xml.load_frame_subclass(self, parent, "MyFrame1")

    finder = lambda do | x |
        int_id = Wx::xrcid(x)
        begin
            Wx::Window.find_window_by_id(int_id, self) || int_id
        # Temporary hack to work around regression in 1.9.2; remove
        # begin/rescue clause in later versions
        rescue RuntimeError
            int_id
        end
    end

    @m_statictext1 = finder.call("m_staticText1")
    @m_butexit = finder.call("m_butExit")
    if self.class.method_defined? "on_init"
        self.on_init()
    end
end

```

end

# This class was automatically generated from XRC source. It is not

# recommended that this file is edited directly; instead, inherit from

# this class and extend its behaviour there.

# 

# Source file: sample1.xrc

# Generated at: 2009-11-27 18:13:59 -0600

class DiaFrame \< Wx::Dialog

```
attr_reader :m_statictext4, :m_statictext5

def initialize(parent = nil)
    super()
    xml = Wx::XmlResource.get
    xml.flags = 2 # Wx::XRC_NO_SUBCLASSING
    xml.init_all_handlers
    xml.load("sample1.xrc")
    xml.load_dialog_subclass(self, parent, "MyDialog1")

    finder = lambda do | x |
        int_id = Wx::xrcid(x)
        begin
            Wx::Window.find_window_by_id(int_id, self) || int_id
        # Temporary hack to work around regression in 1.9.2; remove
        # begin/rescue clause in later versions
        rescue RuntimeError
            int_id
        end
    end

    @m_statictext4 = finder.call("m_staticText4")
    @m_statictext5 = finder.call("m_staticText5")
    if self.class.method_defined? "on_init"
        self.on_init()
    end
end

```

end

---

<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:** [November 28, 2009, 11:07pm UTC](https://www.ruby-forum.com/t/are-you-sure-custom-dialog-not-exiting-cleanly/179572/2 "2009-11-28T23:07:50Z")

</div>

Philip S. wrote:

> The following program does not exit cleanly after pressing ‘Yes’ when  
> asked ‘Are you sure’?  
> How do I free up the resources after exiting?

It looks like you either need to make the confirmation dialog a child of  
the main frame of the whole program, or else call dialog.destroy  
explicitly when you’re finished with it, whatever the return value of  
show\_modal

def confirm\_closure  
# dlg = DIA\_Frame.new  
dlg = DIA\_Frame.new(the\_main\_window)  
if(dlg.show\_modal==Wx::ID\_YES) then  
dlg.end\_modal(Wx::ID\_YES)  
self.destroy  
end  
end

alex
