Creating and handling a non_GUI event

Eric Rubin
Wed, 10 Apr 2013 17:43:27 -0000

I need to change the value of a Wx::TextCtrl when a message is received
in a separate thread from the GUI.  I think I should be creating a class
derived from Wx::Event (not Wx::CommandEvent) for this.  But I haven''t
been able to get it to work.

Here''s my event class:

class TextMsgEvent < Wx::Event
  EVT_TEXT_MSG = Wx::EvtHandler.register_class(self, nil,
''evt_text_msg'', 1)

  def initialize(text)
    @text = text
    super(0, EVT_TEXT_MSG)
  end
end

My Frame class includes this:

class myFrame < Wx::Frame

  def initialize
    ...
    @text = TextCtrl.new(self, ID_ANY, $status, Point.new(20, 20),
        Size.new(250, 150), SUNKEN_BORDER|TE_READONLY|TE_MULTILINE)
    evt_text_msg(@text.get_id) {|event| on_text(event) }
    ...
  end
  ...
end

When I receive the message (which contains the text) in In my non-GUI
thread I call:

$myFrame.process_event(TextMsgEvent.new(text))

But I don''t seem to be even getting into TextMsgEvent.initialize.

(When I was deriving from Wx::CommandEvent instead of Wx::Event, I was
successfully creating a TextMsgEvent, but the process_event returned
false.)

Any suggestions?  Am I even going about this in the right way?

Thanks,
Eric Rubin

--
Posted via http://www.ruby-forum.com/.