wxEvtHandler personalized Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
stefania
Knows some wx things
Knows some wx things
Posts: 26
Joined: Wed Jul 20, 2005 9:08 am

wxEvtHandler personalized

Post by stefania » Mon Aug 26, 2013 8:06 am

Hi!
In my project I need to use an Event Handlar personalized for some TextCtrl, and I use this code:

MyEvtHandlerOnTime *evt = new MyEvtHandlerOnTime( l_new->u.c_ptrtext, &l_new->c_wxvalue);
l_new->u.c_ptrtext->PushEventHandler( evt);

When I close the dialog, How can I pop all Event Handler in one time?

Thanks.
Stefania

catalin
Moderator
Moderator
Posts: 1594
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Re: wxEvtHandler personalized

Post by catalin » Mon Aug 26, 2013 3:19 pm

It's not very clear what your aim is; try to catch wxCloseEvent for the dialog. See wxDialog docs.

User avatar
eranon
Can't get richer than this
Can't get richer than this
Posts: 867
Joined: Sun May 13, 2012 11:42 pm
Location: France
Contact:

Re: wxEvtHandler personalized

Post by eranon » Mon Aug 26, 2013 7:26 pm

Maybe you could be interested by http://wiki.wxwidgets.org/Custom_Events_Tutorial ; but maybe the existing events suffice for what you want to achieve... Difficult to say from your post...
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]

stefania
Knows some wx things
Knows some wx things
Posts: 26
Joined: Wed Jul 20, 2005 9:08 am

Re: wxEvtHandler personalized

Post by stefania » Tue Aug 27, 2013 7:55 am

Hi!
This is my class fro wxEvtHandler:
class MyEvtHandlerOnTime : public wxEvtHandler
{
public:
MyEvtHandlerOnTime( wxTextCtrl *text, wxString *val) { c_text = text; c_val = val;}

void OnKeyDown (wxKeyEvent& event) {
.....
return;
}
private:
wxTextCtrl *c_text;
wxString *c_val;

DECLARE_EVENT_TABLE();
};
BEGIN_EVENT_TABLE(MyEvtHandlerOnTime, wxEvtHandler)
EVT_KEY_DOWN( MyEvtHandlerOnTime::OnKeyDown)
END_EVENT_TABLE()

In my code I wrote:
m_text = new wxTextCtrl( itemPanel153, ID_Mac_dalle4_6, wxEmptyString, wxDefaultPosition, wxSize(60, -1), 0 );
MyEvtHandlerOnTime *evt = new MyEvtHandlerOnTime(m_text, c_wxvalue);
m_text->PushEventHandler( evt);
.
.
.
When I close dialog I wrote:
m_text->PopEventHandler(true);

but when I close dialog I have wxWidget Debug Alert:
..\..\src\common\wincmn.cpp(468): assert "GetEventHandler() == this" failed in wxWindowsBase::~wxWindowsBase(): any pushed event handler have been removed

What is the problem?

User avatar
doublemax
Moderator
Moderator
Posts: 15174
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxEvtHandler personalized

Post by doublemax » Tue Aug 27, 2013 8:23 am

Code: Select all

..\..\src\common\wincmn.cpp(468): assert "GetEventHandler() == this" failed in wxWindowsBase::~wxWindowsBase(): any pushed event handler have been removed
The assert message means that the event handler has not yet been removed when the window gets destroyed. Where do you call m_text->PopEventHandler(true) and do you do it for every control that has a custom event handler?

And what exactly are you doing with the custom event handler? I've never used Push/PopEventHandler and i suspect there is an easier way to achieve what you need.
Use the source, Luke!

stefania
Knows some wx things
Knows some wx things
Posts: 26
Joined: Wed Jul 20, 2005 9:08 am

Re: wxEvtHandler personalized

Post by stefania » Tue Aug 27, 2013 8:58 am

I call PopEvtHandler before EndModal(wxID_CANCEL) and I am sure do it for each textCtrl.

With wxWindget 2.8.10 this message does not compare.

I use Pop/Push Event for TextCtrl that I use for time input, I need to format input with hh:mm
The timePickerCtrl does not work fine in my project because I need to have some value not valorized.

Thanks

User avatar
doublemax
Moderator
Moderator
Posts: 15174
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxEvtHandler personalized

Post by doublemax » Tue Aug 27, 2013 10:43 am

I call PopEvtHandler before EndModal(wxID_CANCEL) and I am sure do it for each textCtrl.
Is this the only path to close the dialog? What happens in the user clicks OK or the close button of the Dialog? Try moving it to the destructor.
Use the source, Luke!

User avatar
eranon
Can't get richer than this
Can't get richer than this
Posts: 867
Joined: Sun May 13, 2012 11:42 pm
Location: France
Contact:

Re: wxEvtHandler personalized

Post by eranon » Tue Aug 27, 2013 1:15 pm

I see in the doc (never used) that the wxTimePickerCtrl allows to pass a validator to its constructor. So, why don't you create your own validator to validate the value(s) the way you want ?
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]

Post Reply