Hunter Kelly
2003-Nov-25 15:12 UTC
[Wxruby-users] Does wxRuby have event masks or something similar?
I''m trying to capture character events on a frame, using the following piece of code (adapted from samples/etc/test.rb): def initialize(title) super(nil, -1, title, Wx::Point.new(-1,-1), Wx::Size.new(530,590), Wx::DEFAULT_FRAME_STYLE | Wx::FRAME_SHAPED) evt_paint { onPaint } evt_char { | evt | puts "Got char evt: "+evt.to_s if evt.get_key_code.chr =~ /\s/ next_image end } @bitmap = nil @file = nil end (I''ve added the constant for Wx::FRAME_SHAPED to try and allow resizing programtically. Doesn''t seem to work, but that''s a seperate issue). I''m using a class based on Kevin''s image/png sample that he sent to the list earlier. For whatever reason, my event handler never seems to get called. Is there some kind of event mask that I need to enable or something? I know other toolkits sometimes require it... H
Kevin Smith
2003-Nov-25 21:18 UTC
[Wxruby-users] Does wxRuby have event masks or something similar?
Hunter Kelly wrote:> I''m trying to capture character events on a frame, using the following > piece of code (adapted from samples/etc/test.rb):Your questions always require some interesting research :-)> I''m using a class based on Kevin''s image/png sample that he sent to the > list earlier. > > For whatever reason, my event handler never seems to get called. > > Is there some kind of event mask that I need to enable or something? > I know other toolkits sometimes require it...It took me a little while to figure out that Frame, for some reason, does not get key events (nor char events). I don''t see this in the wxWindows docs anywhere. So I added a Panel inside the frame, and did the keyboard handling there. Here are my Panel and Frame classes: ################### class MyPanel < Wx::Panel def initialize(parent) super(parent, -1, Wx::DEFAULT_POSITION, Wx::Size.new(200,200)) # evt_key_down do |evt | puts("Key down"); evt.skip; end evt_char do | evt | puts "Got char evt: "+evt.to_s if evt.get_key_code.chr =~ /\s/ puts("space") end end end end class MyFrame < Wx::Frame def initialize(title) super(nil, -1, title) MyPanel.new(self).set_focus end end ################### Note that I had to set the focus to the panel before it started receiving keys. Here, I used set_focus. Or manually clicking in the panel area (inside the frame) also works to set the focus. Also note that if you catch evt_keyXXX, then you must call evt.skip in order for the evt_char to fire. Kevin