Hi,
i''ve had the same problem and resolved as follow:
in the app i have something like this
class MyApp < App
def on_init
begin
main = Views::MainFrame.new
main.show
main.login
rescue Exception => e
exit(1)
end
end
end
MyApp.new.main_loop
... and in the main frame
module Views
class MainFrame < Wx::Frame
....
def login
login_dlg = Views::Dialog::LoginDialog.new(self)
answer = login_dlg.show_modal()
login_dlg.destroy()
if answer == Wx::ID_CANCEL
Wx::get_app.exit_main_loop()
else
....
end
end
end
end
hope it helps.
bio.
On Thu, Dec 24, 2009 at 1:34 AM, Philip Stephens <plusgforce at
gmail.com>wrote:
> require ''wx''
> require ''Eyes.rb''
>
> =begin
> What I would like to be able to do is to first show
> a modal dialog where someone enters his name and
> password. I would like to exit the program if the
> user clicks cancel on the modal dialog box.
>
> then I would like to be able to show the main screen
> and after clicking on the close button, I would like
> to exit the application, not just close the dialog
> box. One time I used a timer but I don''t think a timer
> is necessary. What can I do to make the following exit
> cleanly after closing both dialog boxes? Thanks for
> your help.
>
> Philip
>
> class Main_Frame < EyesFrame
>
> attr_accessor :score, :symbol
>
> def on_init
> @m_statusbar.set_fields_count(2)
> @score = 0
> @m_statusbar.set_status_text("Score: #{@score}", 2)
> show_user_dialog
> end
>
> def show_user_dialog
> @screen1 = EW_Dialog.new
> temp = @screen1.show_modal
> @screen1.close
> @screen1.end_modal(2)
> end
> end
>
> class EW_Dialog < EW_dialog
> def get_username
> return @m_textctrl_username.value
> end
>
> def get_password
> return @m_textctrl_password.value
> end
> end
>
> class DLG_About < DLG_about
> end
>
> class MyApp < Wx::App
>
> @username = nil
> @password = nil
>
> def on_init
> @screen2 = Main_Frame.new
> self.set_exit_on_frame_delete(true)
> self.set_top_window(@screen2)
> @screen2.show
> end
> end # class
>
> app = MyApp.new
> app.main_loop
>
> =begin
> $ ruby1.9 mintest.rb
> ^Z
> [4]+ Stopped ruby1.9 mintest.rb
>
>
> # Eyes.rb
> # 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: EyesGui.xrc
> # Generated at: 2009-12-03 18:01:35 -0600
>
> class EyesFrame < Wx::Frame
>
> attr_reader :txtred, :m_textrednumber, :m_staticlblgreen,
> :m_textgreennumber, :m_staticlblblue, :m_textbluenumber,
> :m_staticlblsymbol, :m_textctrlguess,
> :m_buttondecrement, :m_buttonincrement, :m_statusbar
>
> def initialize(parent = nil)
> super()
> xml = Wx::XmlResource.get
> xml.flags = 2 # Wx::XRC_NO_SUBCLASSING
> xml.init_all_handlers
> xml.load("EyesGui.xrc")
> xml.load_frame_subclass(self, parent, "frmMain")
>
> 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
>
> @txtred = finder.call("txtRed")
> @m_textrednumber = finder.call("m_textRedNumber")
> @m_staticlblgreen = finder.call("m_staticlblGreen")
> @m_textgreennumber = finder.call("m_textGreenNumber")
> @m_staticlblblue = finder.call("m_staticLBLBlue")
> @m_textbluenumber = finder.call("m_textBlueNumber")
> @m_staticlblsymbol = finder.call("m_staticLBLsymbol")
> @m_textctrlguess = finder.call("m_textCtrlGuess")
> @m_buttondecrement = finder.call("m_buttonDecrement")
> @m_buttonincrement = finder.call("m_buttonincrement")
> @m_statusbar = finder.call("m_statusBar")
> 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: EyesGui.xrc
> # Generated at: 2009-12-03 18:01:35 -0600
>
> class EW_dialog < Wx::Dialog
>
> attr_reader :m_bitmap1, :m_staticlblinstr1, :m_staticlblinstr2,
> :m_staticlblusername, :m_textctrl_username,
> :m_staticlblpassword, :m_textctrl_password
>
> def initialize(parent = nil)
> super()
> xml = Wx::XmlResource.get
> xml.flags = 2 # Wx::XRC_NO_SUBCLASSING
> xml.init_all_handlers
> xml.load("EyesGui.xrc")
> xml.load_dialog_subclass(self, parent, "diab_welcome")
>
> 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_bitmap1 = finder.call("m_bitmap1")
> @m_staticlblinstr1 = finder.call("m_staticLBLinstr1")
> @m_staticlblinstr2 = finder.call("m_staticLBLinstr2")
> @m_staticlblusername = finder.call("m_staticLBLusername")
> @m_textctrl_username = finder.call("m_textCtrl_username")
> @m_staticlblpassword = finder.call("m_staticLBLPassword")
> @m_textctrl_password = finder.call("m_textCtrl_Password")
> if self.class.method_defined? "on_init"
> self.on_init()
> end
> end
> end
> =end
>
>
> _______________________________________________
> wxruby-users mailing list
> wxruby-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/wxruby-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/wxruby-users/attachments/20091228/6fb2f9df/attachment-0001.html>