Page 1 of 2

Help coming from Code Blocks

Posted: Fri Sep 07, 2012 11:59 pm
by papayrus
Hello I was using code blocks before with wxSmith and if I added a control like a button to the visual GUI I could double click on it and it would go into the button code where I can write what I wanted the button to do. Is there anyway to do that in codelite and if not can you give me an example.
For example if I am going to be using wxFormBuilder I can make it generate code and if I put a button on the var name generated is m_button1. It looks like I need to make a connect evenhandler though and then the code for the button event on my own. Is this true? If so the code layout is a little different so can you give me an example of what I need to put in for code as the connect eventhandler and then something simple like having a wxMessageBox pop up when I click the button.

Thanks in advance for any help.

Re: Help coming from Code Blocks

Posted: Sat Sep 08, 2012 12:28 am
by eranif
If you are using wxFormBuilder, then you can connect event handler in wxFB, note that wxFormBuilder separates the UI from the logic by using inheritance: all the generated code goes into a "base" class and your code
goes into a derived class (which you maintain)

Luckily for you, you can connect the events in wxFB and then switch to codelite, open your derived class right click somewhere inside the class header and from the context menu:
"Code Generation Refactoring -> Implement inherited virtual functions"

and codelite will automatically will override all the newly created event handlers in the derived class

You might also want to try the BETA plugin (not open sourced, but free atm) wxCrafter:
http://forums.codelite.org/viewtopic.php?f=9&t=1813

Eran

Re: Help coming from Code Blocks

Posted: Sat Sep 08, 2012 12:46 am
by papayrus
I saw that but I do not see a download link for wxCrafter. I am using wxFormbuilder plugin but there is also an option for wxFB plugin so are you saying I should be using the wxFB plugin instead of the wxFormBuilder plugin because I do not see where the code connect event handler and where the button code gets generated like below

Code: Select all

void MainFrame::OnMyButtonClicked(wxCommandEvent &event)
{
    
}

Re: Help coming from Code Blocks

Posted: Sat Sep 08, 2012 9:45 am
by eranif
papayrus wrote:I saw that but I do not see a download link for wxCrafter
wxCrafter is currently in beta and is not available for download to all of codelite's users. Only users on this forum who are part of the forum's 'wxCrafter' group
can see and download the plugin. If you want to join just send me a private message and I will add you
papayrus wrote:I am using wxFormbuilder plugin but there is also an option for wxFB plugin so are you saying I should be using the wxFB plugin instead of the wxFormBuilder
wxFB *is* a shortcut for wxFormBuilder. wxFormBuilder is a standalone application which works very nicely with codelite.
the wxFormBuilder (aka wxFB plugin) just help you get started faster with wxFormBuilder.

Eran

Re: Help coming from Code Blocks

Posted: Sat Sep 08, 2012 10:04 am
by papayrus
Also there is no auto add code generation happening while I type is that normal? I still can't get a button to pop up a wxMessageBox because I don't think that formbuilder puts all the needed code in. Also everytime I open wxFormBuilder to edit the visual GUI I get the message This project file is not the current version would yopu like to attemp automatic conversion?Here is what I got. NOTE this will modify your project file on disk. Here is the code I get after generating code with wxFormBuilder and just adding one button.

In gui.h

Code: Select all

///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Jun 30 2011)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////

#ifndef __GUI_H__
#define __GUI_H__

#include <wx/artprov.h>
#include <wx/xrc/xmlres.h>
#include <wx/intl.h>
#include <wx/string.h>
#include <wx/bitmap.h>
#include <wx/image.h>
#include <wx/icon.h>
#include <wx/menu.h>
#include <wx/gdicmn.h>
#include <wx/font.h>
#include <wx/colour.h>
#include <wx/settings.h>
#include <wx/button.h>
#include <wx/sizer.h>
#include <wx/statusbr.h>
#include <wx/frame.h>

///////////////////////////////////////////////////////////////////////////


///////////////////////////////////////////////////////////////////////////////
/// Class MainFrameBase
///////////////////////////////////////////////////////////////////////////////
class MainFrameBase : public wxFrame 
{
	private:
	
	protected:
		wxMenuBar* m_menuBar;
		wxMenu* m_menuFile;
		wxButton* m_button1;
		wxStatusBar* m_statusBar;
		
		// Virtual event handlers, overide them in your derived class
		virtual void OnCloseFrame( wxCloseEvent& event ) { event.Skip(); }
		virtual void OnExitClick( wxCommandEvent& event ) { event.Skip(); }
		
	
	public:
		
		MainFrameBase( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("wxMiniApp"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 500,300 ), long style = wxCLOSE_BOX|wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL );
		
		~MainFrameBase();
	
};

#endif //__GUI_H__
in main.h

Code: Select all

/*********************************************************************
 * Name:      	main.h
 * Purpose:   	Declares simple wxWidgets application with GUI
 * 				created using wxFormBuilder.
 * Author:    
 * Created:   
 * Copyright: 
 * License:   	wxWidgets license (www.wxwidgets.org)
 * 
 * Notes:		Note that all GUI creation code is declared in
 * 				gui.h source file which is generated by wxFormBuilder.
 *********************************************************************/

#ifndef __main__
#define __main__

// main wxWidgets header file
#include <wx/wx.h>
// gui classes generated by wxFormBuilder
#include "gui.h"

////////////////////////////////////////////////////////////////////////////////
// application class declaration 
////////////////////////////////////////////////////////////////////////////////

class MainApp : public wxApp
{
	public:
		virtual bool OnInit();
};

// declare global static function wxGetApp()
DECLARE_APP(MainApp)

////////////////////////////////////////////////////////////////////////////////
// main application frame declaration 
////////////////////////////////////////////////////////////////////////////////

class MainFrame : public MainFrameBase
{
	public:
		MainFrame( wxWindow *parent );
		virtual ~MainFrame();
		
	protected:
		// protected event handlers
		virtual void OnCloseFrame( wxCloseEvent& event );
		virtual void OnExitClick( wxCommandEvent& event );
};

#endif //__main__
in gui.cpp

Code: Select all

///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Jun 30 2011)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////

#include "gui.h"

///////////////////////////////////////////////////////////////////////////

MainFrameBase::MainFrameBase( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style )
{
	this->SetSizeHints( wxDefaultSize, wxDefaultSize );
	
	m_menuBar = new wxMenuBar( 0 );
	m_menuFile = new wxMenu();
	wxMenuItem* menuFileExit;
	menuFileExit = new wxMenuItem( m_menuFile, wxID_EXIT, wxString( _("E&xit") ) + wxT('\t') + wxT("Alt+X"), wxEmptyString, wxITEM_NORMAL );
	m_menuFile->Append( menuFileExit );
	
	m_menuBar->Append( m_menuFile, _("&File") ); 
	
	this->SetMenuBar( m_menuBar );
	
	wxBoxSizer* mainSizer;
	mainSizer = new wxBoxSizer( wxVERTICAL );
	
	m_button1 = new wxButton( this, wxID_ANY, _("MyButton"), wxDefaultPosition, wxDefaultSize, 0 );
	mainSizer->Add( m_button1, 0, wxALL, 5 );
	
	this->SetSizer( mainSizer );
	this->Layout();
	m_statusBar = this->CreateStatusBar( 1, wxST_SIZEGRIP, wxID_ANY );
	
	this->Centre( wxBOTH );
	
	// Connect Events
	this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( MainFrameBase::OnCloseFrame ) );
	this->Connect( menuFileExit->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( MainFrameBase::OnExitClick ) );
}

MainFrameBase::~MainFrameBase()
{
	// Disconnect Events
	this->Disconnect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( MainFrameBase::OnCloseFrame ) );
	this->Disconnect( wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( MainFrameBase::OnExitClick ) );
	
}
in main.cpp

Code: Select all

/*********************************************************************
 * Name:      	main.cpp
 * Purpose:   	Implements simple wxWidgets application with GUI
 * 				created using wxFormBuilder.
 * Author:    
 * Created:   
 * Copyright: 
 * License:   	wxWidgets license (www.wxwidgets.org)
 * 
 * Notes:		Note that all GUI creation code is implemented in
 * 				gui.cpp source file which is generated by wxFormBuilder.
 *********************************************************************/

#include "main.h"

// initialize the application
IMPLEMENT_APP(MainApp);

////////////////////////////////////////////////////////////////////////////////
// application class implementation 
////////////////////////////////////////////////////////////////////////////////

bool MainApp::OnInit()
{
	SetTopWindow( new MainFrame( NULL ) );
	GetTopWindow()->Show();
	
	// true = enter the main loop
	return true;
}

////////////////////////////////////////////////////////////////////////////////
// main application frame implementation 
////////////////////////////////////////////////////////////////////////////////

MainFrame::MainFrame(wxWindow *parent) : MainFrameBase( parent )
{
}

MainFrame::~MainFrame()
{
}

void MainFrame::OnCloseFrame(wxCloseEvent& event)
{
	Destroy();
}

void MainFrame::OnExitClick(wxCommandEvent& event)
{
	Destroy();
}
So what do I need to change that wxFormBuilder does not generate. I know I am missing the wxMessageBox code on the button but when I try to make it it still will not build. I thought that wxFormBuilder would generate code where I would put the wxMessageBox(("Hey")); Code in some brackets somewhere but it does not seem to do that. What am I missing? Also do I really need to have the 2 dll files in my release they add up to 15.9mb.

Re: Help coming from Code Blocks

Posted: Sat Sep 08, 2012 10:26 am
by eranif
papayrus wrote:Also there is no auto add code generation happening while I type is that normal?
I am not sure what you mean.. do you mean "code completion" ? to get code completion you will need to use Ctrl-SPACE
papayrus wrote: I still can't get a button to pop up a wxMessageBox because I don't think that formbuilder puts all the needed code in
wxFormBuilder puts what you tell it to put. Did you click on the "Generate" button in wxFormBuilder? ( I see that you added the button, as I can see "wxButton* m_button1;") but did you connect it to an event?
To connect the button to an event you should select the button you created in wxFormBuilder and then select the 'Events' tab on the properties view on the right side and then in the 'OnButtonClick' field type the name of the
event handler (e.g. OnMyButtonClicked) - click Save followed by Generate and then move back to codelite.

You should now have a stub function in gui.h/gui.cpp, and you will need to override it in the main class:
Place your caret somewhere inside main.h (make sure that the caret is inside the MainFrame class body) right click and select "Code Generation / Refactoring -> Implement inherited virtual functions"
a dialog box with show up and codelite will offer you to override the base class (MainFrameBase's OnMyButtonClick) click OK and you are done

Eran

Re: Help coming from Code Blocks

Posted: Sat Sep 08, 2012 10:36 am
by papayrus
eranif wrote:
papayrus wrote:Also there is no auto add code generation happening while I type is that normal?
I am not sure what you mean.. do you mean "code completion" ? to get code completion you will need to use Ctrl-SPACE
papayrus wrote: I still can't get a button to pop up a wxMessageBox because I don't think that formbuilder puts all the needed code in
wxFormBuilder puts what you tell it to put. Did you click on the "Generate" button in wxFormBuilder? ( I see that you added the button, as I can see "wxButton* m_button1;") but did you connect it to an event?
To connect the button to an event you should select the button you created in wxFormBuilder and then select the 'Events' tab on the properties view on the right side and then in the 'OnButtonClick' field type the name of the
event handler (e.g. OnMyButtonClicked) - click Save followed by Generate and then move back to codelite.

You should now have a stub function in gui.h/gui.cpp, and you will need to override it in the main class:
Place your caret somewhere inside main.h (make sure that the caret is inside the MainFrame class body) right click and select "Code Generation / Refactoring -> Implement inherited virtual functions"
a dialog box with show up and codelite will offer you to override the base class (MainFrameBase's OnMyButtonClick) click OK and you are done

Eran
OK I got everything and it made the connect codes when I figured out how to add events in wxFormBuilder but I do not get what you mean in thew last part where you right click in the class where exactly should I be right clicking?

Re: Help coming from Code Blocks

Posted: Sat Sep 08, 2012 10:41 am
by eranif
See the attached image (notice where the caret is)
16.png
Eran

Re: Help coming from Code Blocks

Posted: Sat Sep 08, 2012 10:44 am
by papayrus
eranif wrote:See the attached image (notice where the caret is)
16.png
Eran
OK I got it it's working it is different from code blocks. That is for sure but I think I like it this way much more it looks like it puts the controls code in a less messy area.
Yep the gui.cpp and the main.cpp are all in one file in code blocks here they are seaparated so it looks like the wxMessageBox code goes in to the main.cpp and that makes the code easier to deal with.
Now I have to get used to being forced to use boxsizers in the wxFormBuilder I guess that's for the better.

Any idea why when I added a textCtrl just now wxFormBuilder is locked up?

Re: Help coming from Code Blocks

Posted: Sat Sep 08, 2012 11:17 am
by papayrus
Last 2 questions for now so I cn get using this. WxFormBuilder locked up when I added a tectCtrl and clicked in it. Is this a bug?
Where can I add code like

Code: Select all

m_textCtrl1->AppendText(("ok"));
So that it will append the text when the application is launched.