Hi everyone,
I’m using the following code to try and register custom events:
When the commented line is uncommented, I the program crashes.
I’m running on windows xp.
Anyone know what am I doing wrong?
Thanks,
Idan.
require ‘wx’
class CustomCommandEvent < Wx::CommandEvent
end
class RecorderFrame < Wx::Frame
def initialize(parent, id, title, hwnds, scriptFilename,
fieldsFilename)
super(parent, id, title)
@hwnds = hwnds
@scriptFilename = scriptFilename
@fieldsFilename = fieldsFilename
layout = Wx::BoxSizer.new(Wx::VERTICAL)
set_sizer(layout)
@startButton = Wx::Button.new(self, Wx::ID_ANY, "Start")
@stopButton = Wx::Button.new(self, Wx::ID_ANY, "Stop")
@label = Wx::StaticText.new(self, Wx::ID_ANY, "Preparing...")
@startButton.disable
@stopButton.disable
evt_button @startButton, :startTracing
evt_button @stopButton, :stopTracing
layout.add(@startButton, 0, Wx::ALL|Wx::EXPAND, 1)
layout.add(@stopButton, 0, Wx::ALL|Wx::EXPAND, 1)
layout.add(@label, 0, Wx::ALL|Wx::EXPAND, 1)
evt_close { |event| onClose(event) }
evt_custom_commands { |event| onCustomCommand(event) }
show
end
def onCustomCommand(event)
puts (“Received command event, id: #{event.inspect.to_s}”)
end
def onClose(event)
if (event.can_veto)
#TODO: Constants
confirm = Wx::MessageDialog.new(nil, “Are you sure you want to
stop
recording?”, “Stop Recording”, Wx::OK | Wx::CANCEL)
case confirm.show_modal
when Wx::ID_OK
destroy
when Wx::ID_CANCEL
event.veto
end
else
destroy
end
end
def startTracing
end
def stopTracing
end
end
class WebRecorderApp < Wx::App
attr_reader :frame
def initialize(hwnds, scriptFilename, fieldsFilename)
@hwnds = hwnds
@scriptFilename = scriptFilename
@fieldsFilename = fieldsFilename
super()
end
def on_init
@frame = RecorderFrame.new(nil, Wx::ALL, “Test”, @hwnds,
@scriptFilename, @fieldsFilename)
end
end
#Wx::EvtHandler.register_class(CustomCommandEvent, nil,
“evt_custom_commands”, 1)
app = WebRecorderApp.new(nil, nil, nil)
app.main_loop