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?
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?
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
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”}
# 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 …)