In the code below my panel1_impt button and panel1_dnld buttons don''t trigger the button event. I''m banging my head against the table wondering what''s going on. Can anyone advise? wizard = Wx::Wizard.new(self, :title => "Wizard") wizard.icon = Wx::Icon.new(''wizard.ico'') splash.destroy ########################################################## # Panel1, Masthead selection panel1 = Wx::WizardPageSimple.new(wizard) panel1_txt = Wx::StaticText.new(panel1, :label => "Select Site") panel1_lst = Wx::CheckListBox.new(panel1, :choices => files) panel1_btns = Wx::Panel.new(panel1) panel1_impt = Wx::Button.new(panel1_btns, :label => "Import") panel1_dnld = Wx::Button.new(panel1_btns, :label => "Download") panel1_btns.sizer = Wx::HBoxSizer.new panel1_btns.sizer.add(panel1_impt, 0, Wx::ALL, 5) panel1_btns.sizer.add(panel1_dnld, 0, Wx::ALL, 5) panel1.sizer = Wx::VBoxSizer.new panel1.sizer.add(panel1_txt, 0, Wx::ALL, 5) panel1.sizer.add(panel1_lst, 1, Wx::ALL|Wx::GROW, 5) panel1.sizer.add(panel1_btns, 0, Wx::ALL, 5) files.each_index {|i| panel1_lst.check(i, true)} # Panel1 Events evt_button(panel1_impt) {p "IMPORT!"} evt_button(panel1_dnld) {p "DOWNLOAD!"} -- Posted via http://www.ruby-forum.com/.
El Gato wrote:> In the code below my panel1_impt button and panel1_dnld buttons don''t > trigger the button event. I''m banging my head against the table > wondering what''s going on. Can anyone advise?<snip>> panel1_impt = Wx::Button.new(panel1_btns, :label => "Import") > panel1_dnld = Wx::Button.new(panel1_btns, :label => "Download") > ><snip>> # Panel1 Events > evt_button(panel1_impt) {p "IMPORT!"} > evt_button(panel1_dnld) {p "DOWNLOAD!"} >Please, if you''re going to post code, reduce it to the bare minimum that shows the problem, and make it runnable. There is nothing wrong with your event handling code itself. Things to consider: - are you calling Wizard#run_wizard to show the panel? - is output buffering on in the terminal in which you''re running the application - in which case the output might not show straight away? alex
I guess the problem with reducing the code is that I have no idea what the problem is, so I''m not really sure what not to show -- it''s possible that some non-button item is the culprit. I didn''t really think that my event code was bad. Here''s a full program that shows the issue. #!/usr/bin/env rubyw require ''wx'' $stdout.sync = true class AppWizard < Wx::Frame def initialize(*args) super wizard = Wx::Wizard.new(self, :title => "App Wizard") panel1 = Wx::WizardPageSimple.new(wizard) panel1_txt = Wx::StaticText.new(panel1, :label => "Panel 1:") panel1_lst = Wx::CheckListBox.new(panel1, :choices => ["one", "two", "three"]) # This event never triggers when the button is clicked panel1_impt = Wx::Button.new(panel1, :label => "Import") evt_button(panel1_impt) {puts "You clicked the import button"} panel1.sizer = Wx::VBoxSizer.new panel1.sizer.add(panel1_txt, 0, Wx::ALL, 5) panel1.sizer.add(panel1_lst, 1, Wx::ALL|Wx::GROW, 5) panel1.sizer.add(panel1_impt, 0, Wx::ALL, 5) wizard.set_page_size(Wx::Size.new(500,300)) wizard.run_wizard(panel1) end end class App < Wx::App def on_init frame = AppWizard.new frame.show(false) end end app = App.new app.main_loop() -- Posted via http://www.ruby-forum.com/.
El Gato wrote:> I guess the problem with reducing the code is that I have no idea what > the problem is, so I''m not really sure what not to show -- it''s possible > that some non-button item is the culprit. I didn''t really think that my > event code was bad. Here''s a full program that shows the issue.> # This event never triggers when the button is clicked > panel1_impt = Wx::Button.new(panel1, :label => "Import") > evt_button(panel1_impt) {puts "You clicked the import button"}wizard.evt_button(panel1_impt) {puts "You clicked the import button"} Does the trick for me. best, Peter. -- Posted via http://www.ruby-forum.com/.
Peter Lane wrote:> El Gato wrote: > >> # This event never triggers when the button is clicked >> panel1_impt = Wx::Button.new(panel1, :label => "Import") >> evt_button(panel1_impt) {puts "You clicked the import button"} >> > > wizard.evt_button(panel1_impt) {puts "You clicked the import button"} >Thanks Peter. By way of explanation, this is because CommandEvents - those associated with standard controls like Button, CheckBox, ToggleButton etc - bubble upwards through the window hierarchy UNTIL they reach a top-level window. Each window has a chance to process it. So in the example, the Button event gets offered to the Button (then) the Panel (then) the Wizard (a top-level window) But in the original evt_button was called on "self", the Frame. The button event never reaches that Frame it so the event handler isn''t ever triggered. Calling wizard.evt_button sets it on the Wizard instead. Encapsulating GUI classes by inheritance tends to help avoid this mix-up (class DownloadWizard < Wx::Wizard ...) hth alex
Peter Lane wrote:> > wizard.evt_button(panel1_impt) {puts "You clicked the import button"} > > Does the trick for me. > > best, > > Peter.It does indeed! Thanks very much! -- Posted via http://www.ruby-forum.com/.