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
Do you have a GitHub repository with the actual code in it, or could you
paste the most minimal code, that reproduces the error, so that we can
properly diagnose the issue?
Sorry for the late reply, I was busy with Windows issues, and couldn’t
test
with Ruby 2.0, as wxRuby needs to be compiled with Ruby 2.0.
In any case, after testing, and throwing in a require ‘thread’ and
Thread.abort_on_exception = true, I found that when you sub-class a
Wx::Event, and attempt create a new instance of the sub-class, you will
end
up with an internal error, saying that no allocator has been defined for
Wx::Event, which in all cases, is true, cause in C++ wxWidgets,
Wx::Event,
isn’t a True Instantiate class. In C++, the WxEvent Class is considered
an
Abstract Base Class, or to put it into Ruby Terms, consider WxEvent a
Module.
It defines the base methods and instance variables / structure of the
class
for any sub-class of WxEvent, without actually having an allocator
associated with the base class itself. So in order to actually get a
Class
that is usable in Ruby, you need to sub-class a pre-existing C++ Class,
such as Wx::CommandEvent (WxCommandEvent class), in order to have it
work
in Ruby.
I hope that this helps with your future programming.