Menu event handler problem

Guys,

I make a form with xrc file help
I load, use lambda to get all my widgets,
then set event handler

somehow, it does not work well with menu
with no clear sign of what the mistake is

is there something I miss?

here is the code

require ‘rubygems’
require ‘wx’
require ‘pathname’
include Wx
class MyForm < Wx::Frame
def initialize(parent=nil)
super()
xrc_file = ‘file.xrc’
xml = Wx::XmlResource.get
xml.flags = 2
xml.init_all_handlers
xml.load(xrc_file)
xml.load_frame_subclass(self, parent, ‘my_frame’)
@finder = lambda do | x |
int_id = Wx::xrcid(x)
begin
Wx::Window.find_window_by_id(int_id, self)
rescue RuntimeError
int_id
end
end

            @menuitem_new = @finder.call('menuitem_new')
            evt_menu(@menuitem_new.get_id) { | event |

menuitem_new_clicked(event) }

end

def menuitem_new_clicked(event)
puts ‘Menu New is clicked’
end

end

Thank you
Regards
Hendra

done by changing
evt_menu(@menuitem_new.get_id) { | event | menuitem_new_clicked(event)
}
into
evt_menu(Wx::xrcid.('menuitem_new)) { | event |
menuitem_new_clicked(event) }

why does previous one does not work?
anybody can tell?

Another question,
I want to make an accelerator to call that menu, something like ctrl+n

doc tells to add accelerator table and then assign,
something like
acc_table = Wx::AcceleratorTable[ [ Wx::MOD_CONTROL, “n”.ord,
@menuitem_new.get_id ] ]
self.accelerator_table = acc_table

but it does not work…
How can I fix this?
(i tried to replace @menuitem_new.get_id with Wx::xrcid(‘menuitem_new’)
but
no luck…)

Sorry, somehow I find it myself
using

acc_table = Wx::AcceleratorTable[ [ Wx::MOD_CONTROL, ?n,
Wx::xrcid’menuitem_new’] ]

I really dont understand
how is ?n different from “n”.ord

anyone can explain?

hendra kusuma wrote:

Sorry, somehow I find it myself
using

acc_table = Wx::AcceleratorTable[ [ Wx::MOD_CONTROL, ?n,
Wx::xrcid’menuitem_new’] ]

I really dont understand
how is ?n different from “n”.ord

anyone can explain?

I didn’t know this before, but it seems the meaning of the ?x literal
changed in Ruby 1.9 along with the meaning of “x”[0]. String#ord didn’t
exist in 1.8:

abaddon:~ alex$ irb

RUBY_VERSION
=> “1.8.7”

?n
=> 110

“n”[0]
=> 110

“n”.ord
NoMethodError: undefined method `ord’ for “n”:String
from (irb):3

abaddon:~ alex$ ~/bleed/bin/irb
irb(main):001:0> RUBY_VERSION
=> “1.9.1”
irb(main):002:0> “n”.ord
=> 110
irb(main):003:0> “n”[0]
=> “n”
irb(main):004:0> ?n
=> “n”

cheers
alex