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 -- Suka linux? Kunjungi blog saya http://penguinroad.blogspot.com _______________________________________________ wxruby-users mailing list wxruby-users@rubyforge.org http://rubyforge.org/mailman/listinfo/wxruby-users
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? On Tue, Dec 15, 2009 at 12:48 PM, hendra kusuma <penguinroad at gmail.com>wrote:> 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 > > -- > Suka linux? > Kunjungi blog saya http://penguinroad.blogspot.com >-- Suka linux? Kunjungi blog saya http://penguinroad.blogspot.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/wxruby-users/attachments/20091215/d2a8acb2/attachment.html>
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...) On Tue, Dec 15, 2009 at 1:22 PM, hendra kusuma <penguinroad at gmail.com>wrote:> 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? > > > On Tue, Dec 15, 2009 at 12:48 PM, hendra kusuma <penguinroad at gmail.com>wrote: > >> 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 >> >> -- >> Suka linux? >> Kunjungi blog saya http://penguinroad.blogspot.com >> > > > > -- > Suka linux? > Kunjungi blog saya http://penguinroad.blogspot.com >-- Suka linux? Kunjungi blog saya http://penguinroad.blogspot.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/wxruby-users/attachments/20091215/bc64317d/attachment.html>
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? On Tue, Dec 15, 2009 at 2:04 PM, hendra kusuma <penguinroad at gmail.com>wrote:> 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...) > > On Tue, Dec 15, 2009 at 1:22 PM, hendra kusuma <penguinroad at gmail.com>wrote: > >> 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? >> >> >> On Tue, Dec 15, 2009 at 12:48 PM, hendra kusuma <penguinroad at gmail.com>wrote: >> >>> 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 >>> >>> -- >>> Suka linux? >>> Kunjungi blog saya http://penguinroad.blogspot.com >>> >> >> >> >> -- >> Suka linux? >> Kunjungi blog saya http://penguinroad.blogspot.com >> > > > > -- > Suka linux? > Kunjungi blog saya http://penguinroad.blogspot.com >-- Suka linux? Kunjungi blog saya http://penguinroad.blogspot.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/wxruby-users/attachments/20091215/ba3c2d47/attachment-0001.html>
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