Adding a custom widget to wxSmith?
Adding a custom widget to wxSmith?
I'd like to add a custom widget to the wxSmith widget groups (in this case a grouping of tape-recorder style buttons). Is there a good beginner tutorial on how to do this? I've done some web searching with no luck.
Re: Adding a custom widget to wxSmith?
Hi,
Can't you use a dummy sizer/text control in-place and after generating the code replace the dummy one with the one you want?
It will be much easier and faster.
Thank you.
Can't you use a dummy sizer/text control in-place and after generating the code replace the dummy one with the one you want?
It will be much easier and faster.
Thank you.
Re: Adding a custom widget to wxSmith?
I was hoping there was an easy way to add a control into wxSmith without going into coding acrobatics.
Re: Adding a custom widget to wxSmith?
I went ahead with the suggested method of using a placeholder object then renaming it to fit the custom class I am building (ArrowNav).
Unfortunately, I am still new to C++ and wxWidgets so I find myself running into a compiler problem that I haven't been able to solve. The build log shows this:
Here is the ArrowNav.h code...
And here is the ArrowNav.cpp code:
Unfortunately, I am still new to C++ and wxWidgets so I find myself running into a compiler problem that I haven't been able to solve. The build log shows this:
Code: Select all
ArrowNav.h: In constructor 'ArrowNav::ArrowNav(wxWindow*, const wxPoint&)':
ArrowNav.h:14:118: error: expected '{' at end of input
ArrowNav(wxWindow *parent, const wxPoint& pos) : wxPanel(parent, wxID_ANY, pos, wxSize(-1, -1), wxBORDER_NONE);
Code: Select all
#ifndef ARROWNAV_H
#define ARROWNAV_H
//(*AppHeaders
#include <wx/image.h>
#include <wx/button.h>
//*)
class ArrowNav:public wxPanel
{
public:
ArrowNav();
virtual ~ArrowNav();
ArrowNav(wxWindow *parent, const wxPoint& pos) : wxPanel(parent, wxID_ANY, pos, wxSize(-1, -1), wxBORDER_NONE);
protected:
private:
wxButton* m_FirstButton;
wxButton* m_PrevButton;
wxButton* m_NextButton;
wxButton* m_LastButton;
};
#endif // ARROWNAV_H
Code: Select all
#include "inc/cshpApp.h"
#include "inc/ArrowNav.h"
class ArrowNav:public wxPanel{
private:
wxButton* m_FirstButton;
wxButton* m_PrevButton;
wxButton* m_NextButton;
wxButton* m_LastButton;
public:
ArrowNav()
{
//ctor
}
~ArrowNav()
{
//dtor
}
//ArrowNav(Panel1,ID_ARROWNAV1,wxDefaultPosition,wxSize(100,20),,wxDefaultValidator,_T("ID_ARROWNAV1"));
ArrowNav(wxWindow *parent, const wxPoint& pos) : wxPanel(parent, wxID_ANY, pos, wxSize(-1, -1), wxBORDER_NONE){
wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);
m_FirstButton = new wxButton(this, wxID_ANY, wxT("|<"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT );
m_PrevButton = new wxButton(this, wxID_ANY, wxT("<"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT );
m_NextButton = new wxButton(this, wxID_ANY, wxT(">"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT );
m_LastButton = new wxButton(this, wxID_ANY, wxT(">|"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT );
hbox->Add(m_FirstButton, 1, wxALL, 5);
hbox->Add(m_PrevButton, 1, wxALL, 5);
hbox->Add(m_NextButton, 1, wxALL, 5);
hbox->Add(m_LastButton, 1, wxALL, 5);
hbox->SetSizeHints(this);
this->SetSizer(hbox);
}
};
Last edited by Lowkus on Mon Jun 26, 2017 7:33 pm, edited 2 times in total.
Re: Adding a custom widget to wxSmith?
Hi,
You are mixing here a declaration and implementation.
The quick and easy solution is:
- header file is for declaration (this is where you declare you class interface)
- cpp file is for implementation (this is where you write an actual code).
So your code should look like this:
Grab this code, understand the difference with yours learn it and use it as tis is the way the proper C++ code should be written.
If it is easier for you you can try to use wxPython/wxPerl binding to make your GUI in a language you are familiar with.
Also, for the future references the code you post on the forum should be put inside tags.
You have a helper button above the text control to simplify this.
Enjoy!
Thank you.
You are mixing here a declaration and implementation.
The quick and easy solution is:
- header file is for declaration (this is where you declare you class interface)
- cpp file is for implementation (this is where you write an actual code).
So your code should look like this:
Code: Select all
#ifndef ARROWNAV_H
#define ARROWNAV_H
//(*AppHeaders
#include <wx/image.h>
#include <wx/button.h>
//*)
class ArrowNav:public wxPanel
{
public:
ArrowNav();
virtual ~ArrowNav();
ArrowNav(wxWindow *parent, const wxPoint& pos);
private:
wxButton* m_FirstButton;
wxButton* m_PrevButton;
wxButton* m_NextButton;
wxButton* m_LastButton;
};
#endif // ARROWNAV_H
Code: Select all
#include "inc/cshpApp.h"
#include "inc/ArrowNav.h"
ArrowNav::ArrowNav()
{
//ctor
}
ArrowNav::~ArrowNav()
{
//dtor
}
//ArrowNav(Panel1,ID_ARROWNAV1,wxDefaultPosition,wxSize(100,20),,wxDefaultValidator,_T("ID_ARROWNAV1"));
ArrowNav::ArrowNav(wxWindow *parent, const wxPoint& pos) : wxPanel(parent, wxID_ANY, pos, wxSize(-1, -1), wxBORDER_NONE)
{
wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);
m_FirstButton = new wxButton(this, wxID_ANY, wxT("|<"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT );
m_PrevButton = new wxButton(this, wxID_ANY, wxT("<"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT );
m_NextButton = new wxButton(this, wxID_ANY, wxT(">"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT );
m_LastButton = new wxButton(this, wxID_ANY, wxT(">|"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT );
hbox->Add(m_FirstButton, 1, wxALL, 5);
hbox->Add(m_PrevButton, 1, wxALL, 5);
hbox->Add(m_NextButton, 1, wxALL, 5);
hbox->Add(m_LastButton, 1, wxALL, 5);
hbox->SetSizeHints(this);
this->SetSizer(hbox);
}
If it is easier for you you can try to use wxPython/wxPerl binding to make your GUI in a language you are familiar with.
Also, for the future references the code you post on the forum should be put inside
Code: Select all
...
You have a helper button above the text control to simplify this.
Enjoy!
Thank you.
Re: Adding a custom widget to wxSmith?
Wow, those code brackets make a world of difference! When I post build log text should I wrap that in code brackets as well?
Re: Adding a custom widget to wxSmith?
Yes, you should.
It makes reading code/logs much easier and simpler.
And if you want to quote something or someone, you should use
Thank you.
It makes reading code/logs much easier and simpler.
And if you want to quote something or someone, you should use
tags....
Thank you.
Re: Adding a custom widget to wxSmith?
Your code did the trick, thanks!
I'm running into a new problem though; when I put a wxCustom control onto a form, then set the class name to ArrowNav, wxSmith then auto-generates the following line of code in the form's cpp file:
Do I need to change this auto-generated code to match my ArrowNav constructor, or do I need to modify the ArrowNav constructor so that it accepts all of the auto-generated parameters?
I'm running into a new problem though; when I put a wxCustom control onto a form, then set the class name to ArrowNav, wxSmith then auto-generates the following line of code in the form's cpp file:
Code: Select all
Custom1 = new ArrowNav(Panel1,ID_ARROWNAV1,wxDefaultPosition,wxSize(100,20),,wxDefaultValidator,_T("ID_ARROWNAV1"));
Re: Adding a custom widget to wxSmith?
Hi,
Yes, you should change the auto-generated code to match whatever you put in.
Or to make life easier - you change the signature of the constructor in the .h file, modify the .cpp file to match, set the unneeded parameters to have the values by default and then everything will just work.
But I would suggest learn a language (C++) first. Or go with wxPython as it is much easier and there the language itself is not hard.
If you still want this code to work - start learning the language and set wxWidgets aside. When you will be familiar with C++ - go back and continue working with the library.
Also, wxWidgets is NOT a way to learn C++. Especially modern C++.
Thank you.
Yes, you should change the auto-generated code to match whatever you put in.
Or to make life easier - you change the signature of the constructor in the .h file, modify the .cpp file to match, set the unneeded parameters to have the values by default and then everything will just work.
But I would suggest learn a language (C++) first. Or go with wxPython as it is much easier and there the language itself is not hard.
If you still want this code to work - start learning the language and set wxWidgets aside. When you will be familiar with C++ - go back and continue working with the library.
Also, wxWidgets is NOT a way to learn C++. Especially modern C++.
Thank you.
Re: Adding a custom widget to wxSmith?
I actually have decades of VB experience and I dabbled in C++ back in college, it's just that I've forgotten most of my C++ and the transition from VB.NET to C++ is not as direct as I'd hoped. But, jumping into a complex project has always been my favorite way of learning, striving for a high-quality useful application keeps me engaged in the learning process.
Re: Adding a custom widget to wxSmith?
Well, then maybe it is better for you to go get some refresher course on C++.
Because if you go further down the road, more problems will arise. And if you switch to *nix/Mac you will need to work with plain editors/debuggers. It's not a nice, good-looking MSVC.
But it is up to you. It just harder to try to learn 2 things at the same time even though they are related.
Thank you.
Because if you go further down the road, more problems will arise. And if you switch to *nix/Mac you will need to work with plain editors/debuggers. It's not a nice, good-looking MSVC.
But it is up to you. It just harder to try to learn 2 things at the same time even though they are related.
Thank you.
Re: Adding a custom widget to wxSmith?
I'm reading up on C++ as I can find the time. I have been using Code::Blocks to make things easier when compiling for Linux.
Re: Adding a custom widget to wxSmith?
Hi,
You probably should start with C++ reading and forget about wx until after you have some basic C++ understanding and how to write C++ code.
Only when you will be comfortable with the language - go back to wx and continue.
You probably should start with C++ reading and forget about wx until after you have some basic C++ understanding and how to write C++ code.
Only when you will be comfortable with the language - go back to wx and continue.