'Are you sure?' custom dialog not exiting cleanly

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

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