Page 1 of 1

wxCrafter adding event.skip() to .h file

Posted: Fri Mar 04, 2022 7:26 pm
by antoniochang

I am having difficulty getting a button to work. It's my first time trying out CodeLite and it's not going well.
In wxCrafter, I created a wxButton, then double-clicked and it automatically connected it to a wxEVT_COMMAND_BUTTON_CLICKED.

Clicking on "Generate Code" in wxCrafter automatically generated 2 virtual void event handler functions, each in:
wxcrafter.h in the Login class
LoginFrame.h in the LoginFrame class

I want the definition/actual handling to be in
LoginFrame.cpp

The problem is that in the wxcrafter.h, it automatically adds to the base class the code: event.Skip().
LoginFrame inherits from Login, and event.Skip() is in Login, so the event handler in LoginFrame.cpp is never called. The wxcrafter.h is autogenerated. When I put the true handling in wxcrafter.h, I get the desired behavior, but this .h file is overridden and erased every time the "Generate Code" is pressed in the wxCrafter.

What must I do to resolve the problem?

Thanks!


Re: wxCrafter adding event.skip() to .h file

Posted: Fri Mar 04, 2022 9:01 pm
by antoniochang

==============================================================================

wxcrafter.h

Code: Select all

class SigninDialog : public wxDialog
{
....
protected:
    virtual void OnBtnLoginClicked(wxCommandEvent& event)
    {
        event.Skip();
    }
...

==============================================================================

Signin.h

Code: Select all


#ifndef SIGNIN_H
#define SIGNIN_H
#include "wxcrafter.h"

class Signin : public SigninDialog
{
public:
    Signin(wxWindow* parent);
    virtual ~Signin();
protected:
    virtual void OnBtnLoginClicked(wxCommandEvent& event);
};
#endif // SIGNIN_H

==============================================================================

Signin.cpp

Code: Select all

#include "Signin.h"
#include <wx/msgdlg.h>

Signin::Signin(wxWindow* parent)
    : SigninDialog(parent)
{
}

Signin::~Signin()
{
}

void Signin::OnBtnLoginClicked(wxCommandEvent& event)
{
    ::wxMessageBox(_("Hello World"));
}

==============================================================================
This setup yields no reaction when clicked.
No compilation errors are raised during build.
What code or steps am I missing?
Note that this dialog box is not the mainFrame window.
Thanks!


Re: wxCrafter adding event.skip() to .h file

Posted: Fri Mar 04, 2022 9:27 pm
by antoniochang

==============================================================
This is the relevant section in my MainFrame.cpp
The bottom shows the connect event code.
As mentioned, nothing happens when the button btnLogin is clicked.

MainFrame.cpp

Code: Select all

SigninDialog::SigninDialog(wxWindow* parent,
    wxWindowID id,
    const wxString& title,
    const wxPoint& pos,
    const wxSize& size,
    long style)
    : wxDialog(parent, id, title, pos, size, style)
{
    if(!bBitmapLoaded) {
        // We need to initialise the default bitmap handler
        wxXmlResource::Get()->AddHandler(new wxBitmapXmlHandler);
        wxC9ED9InitBitmapResources();
        bBitmapLoaded = true;
    }

    wxBoxSizer* SigninSizer = new wxBoxSizer(wxHORIZONTAL);
    this->SetSizer(SigninSizer);

    btnLogin = new wxButton(this, wxID_ANY, _("Enter"), wxDefaultPosition, wxDLG_UNIT(this, wxSize(-1, -1)), 0);

    SigninSizer->Add(btnLogin, 0, wxALL, WXC_FROM_DIP(5));

    SetName(wxT("SigninDialog"));
    SetSize(wxDLG_UNIT(this, wxSize(500, 300)));
    if(GetSizer()) {
        GetSizer()->Fit(this);
    }
    if(GetParent()) {
        CentreOnParent(wxBOTH);
    } else {
        CentreOnScreen(wxBOTH);
    }
#if wxVERSION_NUMBER >= 2900
    if(!wxPersistenceManager::Get().Find(this)) {
        wxPersistenceManager::Get().RegisterAndRestore(this);
    } else {
        wxPersistenceManager::Get().Restore(this);
    }
#endif
    // Connect events
    btnLogin->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(SigninDialog::OnBtnLoginClicked), NULL, this);
}

SigninDialog::~SigninDialog()
{
    btnLogin->Disconnect(
        wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(SigninDialog::OnBtnLoginClicked), NULL, this);
}

==============================================================
What could be the problem?

Thanks!


Re: wxCrafter adding event.skip() to .h file

Posted: Fri Mar 04, 2022 9:38 pm
by antoniochang

The button works when I use it in my MainFrame, but it doesn't when it is on a secondary dialog or secondary frame.
I need to create a Sign-in dialog box before entering the MainFrame. What is the correct way to go about this?
Thanks!


Re: wxCrafter adding event.skip() to .h file

Posted: Sat Mar 05, 2022 6:38 pm
by antoniochang

The problem has been solved.
viewtopic.php?f=18&t=4929&p=19862#p19862
Thanks!