KONTRA Gergely wrote:> Hi!
>
> During developing my little program, I''ve noticed, that the
objects have
> a hierarchy, but now I don''t know what to do, if a widget
initiates an
> event which has an effect to the parent, grandfather/brother/other
> relatives.
It is difficult to answer that question without knowing specific details
about what you are trying to do.
I just wrote a little program that might help, depending on your exact
situation. It creates a subclass of TextCtrl, and filters input
characters. If the character is legal, it delegates handling to the
parent (TextCtrl itself, in this case). Otherwise, it consumes the event
itself.
As far as I know, in wxRuby it is not a good idea to try to push
specific events to specific widgets, as you might do in Win32 coding.
Instead, it would be better to just call a ruby method to do the work.
But that requires you to know which ruby object you want to control.
If you can ask a more specific question, perhaps with some sample code,
I can try to give a better answer.
Kevin
-----
require ''wxruby''
class MyTextCtrl < Wx::TextCtrl
def initialize(parent)
super(parent, -1)
evt_char do | e | on_char(e) end
end
def on_char(e)
c = e.key_code
if((?a .. ?z).member?(c) || (?A .. ?Z).member?(c))
# legal, so pass this event to our parent
e.skip
puts("skip")
else
# illegal, so beep and consume this event
Wx::bell
puts("beep")
end
end
end
class MyFrame < Wx::Frame
def initialize(title)
super(nil, -1, title)
text = MyTextCtrl.new(self)
box = Wx::BoxSizer.new(Wx::VERTICAL)
box.add(Wx::StaticText.new(self, -1,
"This box only allows alpha input:"))
box.add(text)
set_sizer(box)
text.set_focus
end
end
class NothingApp < Wx::App
def on_init
frame = MyFrame.new("Event Filter Sample")
frame.show
end
end
a = NothingApp.new
a.main_loop()