How to clear client area or replace sizers and controls on a panel

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
PaulUK
Earned a small fee
Earned a small fee
Posts: 17
Joined: Wed Nov 18, 2020 12:55 pm

How to clear client area or replace sizers and controls on a panel

Post by PaulUK » Thu Dec 24, 2020 9:30 am

I've been making some progress with my wxWidgets project and decided to go with a ribbon menu to choose from a number of independent calculator and simulation programs that would be shown in the main window frame. I have successfully been able to connect ribbon icons to event functions. It could equally be a toolbar by the way.

The problem I have now is how do I reset and place controls and sizers on the window when switching between programs in my app. Do I need a new panel for each independent calculator app, or does the panel need to be cleared and reset in some way.

I tried simply to create a new panel and sizers in an event function, but they get added to the original one created in the main frame definition. Any advice would be appreciated. Thank you.

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

Re: How to clear client area or replace sizers and controls on a panel

Post by doublemax » Thu Dec 24, 2020 10:16 am

The easiest way would be to have a separate panel for each calculator/simulation, create them all at once when the program starts, and put them into a wxSimpleBook, so that only one is visible at a time.
I tried simply to create a new panel and sizers in an event function, but they get added to the original one created in the main frame definition.
That should also work, but without seeing code, it's hard to tell what you did wrong.
Use the source, Luke!

PaulUK
Earned a small fee
Earned a small fee
Posts: 17
Joined: Wed Nov 18, 2020 12:55 pm

Re: How to clear client area or replace sizers and controls on a panel

Post by PaulUK » Thu Apr 29, 2021 12:28 pm

Since the last posts I have been trying to get panels to be shown or to hidden whenever an icon/button is clicked on. These buttons are on a ribbon and I tested them to work fine so far with a message that pops up to confirm that I clicked on an icon. I can create a panel, give it a colour and add it to a sizer. From with the MainWindow I can hide or show the panel, this works fine. However, my problem now is that when I try to hide or show a panel from within a function that is activated by a ribbon button click, nothing seems to happen.

Is this problem because I am trying to show or hide the panel from outside the MainWindow function? If so is there a way to achieve what I want whenever an icon is clicked and a OnXXXButton event is called?

Here is the MainWindow.cpp file. The function "void MainWindow::OnMicrostripButton(wxRibbonButtonBarEvent& evt)" is where I'd like to hide the default panel and show a new one with its own controls. Near the bottom of MainWindow is where I was trying to show and hide the default panel by commenting out and uncommenting various lines. I hope that someone can help with this issue. Thank you.

The function "void MainWindow::OnCPWButton(wxRibbonButtonBarEvent& evt)" is a mess and doesn't do what I want either.

Code: Select all

#include "MainWindow.h"
#include <cmath>
#include "dish32.xpm"

// Static Event Table
wxBEGIN_EVENT_TABLE(MainWindow, wxFrame)
    EVT_TEXT_ENTER(wxID_ANY, MainWindow::OnRadiusEntered)
    // Ribbon menu buttons
    EVT_RIBBONBUTTONBAR_CLICKED(ID_MICROSTRIP, MainWindow::OnMicrostripButton)
    EVT_RIBBONBUTTONBAR_CLICKED(ID_CPW, MainWindow::OnCPWButton)
    EVT_RIBBONBUTTONBAR_CLICKED(ID_CPW_G, MainWindow::OnCPW_GButton)
    EVT_RIBBONBUTTONBAR_CLICKED(ID_STRIPLINE, MainWindow::OnStriplineButton)
    EVT_RIBBONBUTTONBAR_CLICKED(ID_COUPLED_STRIPLINE, MainWindow::OnCoupled_StriplineButton)



wxEND_EVENT_TABLE()

wxStaticText *EnterRadius;
wxTextCtrl *RadiusEntered;
wxStaticText *RadiusIs;
wxTextCtrl *AreaResult;
wxSizer* sizer = new wxBoxSizer(wxVERTICAL);
wxSizer* panelSizer = new wxBoxSizer(wxVERTICAL);

MainWindow::MainWindow(wxWindow *parent,
		wxWindowID id,
		const wxString& title,
		const wxPoint& pos,
		const wxSize& size,
		long style,
		const wxString& name)
	:wxFrame(parent, id, title, pos, wxSize(1024, 768), style, name)
{
    wxPanel *panel = new wxPanel(this, -1);
    panel->SetBackgroundColour(wxColor(000, 000, 000));



    // Set frame icon
    wxIcon frameicon(dish32_xpm);
    SetIcon(frameicon);

    // Ribbon
    ribbonBar = new wxRibbonBar(this, -1, wxDefaultPosition, wxDefaultSize, wxRIBBON_BAR_FLOW_HORIZONTAL
                                | wxRIBBON_BAR_SHOW_PAGE_LABELS
                                | wxRIBBON_BAR_SHOW_PANEL_EXT_BUTTONS
                                | wxRIBBON_BAR_SHOW_TOGGLE_BUTTON
                                );

    tlinesRibbonPage = new wxRibbonPage(ribbonBar, wxID_ANY, wxT("TLine Calculators"), wxNullBitmap);
    radomeRibbonPage = new wxRibbonPage(ribbonBar, wxID_ANY, wxT("Radome Analysis"), wxNullBitmap);
    hornsRibbonPage = new wxRibbonPage(ribbonBar, wxID_ANY, wxT("Horn Analysis"), wxNullBitmap);
    sinuousRibbonPage = new wxRibbonPage(ribbonBar, wxID_ANY, wxT("Sinuous & Spiral"), wxNullBitmap);
    reflectorsRibbonPage = new wxRibbonPage(ribbonBar, wxID_ANY, wxT("Reflector Analysis"), wxNullBitmap);


    planartlinesRibbonPanel = new wxRibbonPanel(tlinesRibbonPage, wxID_ANY, wxT("Planar TLines"), wxNullBitmap,
                                        wxDefaultPosition, wxDefaultSize,
                                        wxRIBBON_PANEL_NO_AUTO_MINIMISE);

    wgRibbonPanel = new wxRibbonPanel(tlinesRibbonPage, wxID_ANY, wxT("Waveguide"), wxNullBitmap,
                                        wxDefaultPosition, wxDefaultSize,
                                        wxRIBBON_PANEL_NO_AUTO_MINIMISE);

    coaxRibbonPanel = new wxRibbonPanel(tlinesRibbonPage, wxID_ANY, wxT("Coaxial"), wxNullBitmap,
                                        wxDefaultPosition, wxDefaultSize,
                                        wxRIBBON_PANEL_NO_AUTO_MINIMISE);

    radomeRibbonPanel = new wxRibbonPanel(radomeRibbonPage, wxID_ANY, wxT("Radome"), wxNullBitmap,
                                        wxDefaultPosition, wxDefaultSize,
                                        wxRIBBON_PANEL_NO_AUTO_MINIMISE);

    planartlinesRibbonButtonBar = new wxRibbonButtonBar(planartlinesRibbonPanel);
    wgRibbonButtonBar = new wxRibbonButtonBar(wgRibbonPanel);
    coaxRibbonButtonBar = new wxRibbonButtonBar(coaxRibbonPanel);
    radomeRibbonButtonBar = new wxRibbonButtonBar(radomeRibbonPanel);


    // Planar TLine Tools
    planartlinesRibbonButtonBar->AddButton(ID_MICROSTRIP, wxT("Microstrip"),
                                   wxArtProvider::GetBitmap(wxART_ADD_BOOKMARK, wxART_TOOLBAR, wxSize(32,32)));

    planartlinesRibbonButtonBar->AddButton(ID_CPW, wxT("CPW"),
                                   wxArtProvider::GetBitmap(wxART_ADD_BOOKMARK, wxART_TOOLBAR, wxSize(32,32)));

    planartlinesRibbonButtonBar->AddButton(ID_CPW_G, wxT("CPW-G"),
                                   wxArtProvider::GetBitmap(wxART_ADD_BOOKMARK, wxART_TOOLBAR, wxSize(32,32)));

    planartlinesRibbonButtonBar->AddButton(ID_STRIPLINE, wxT("Stripline"),
                                   wxArtProvider::GetBitmap(wxART_ADD_BOOKMARK, wxART_TOOLBAR, wxSize(32,32)));

    planartlinesRibbonButtonBar->AddButton(ID_COUPLED_STRIPLINE, wxT("Coupled Stripline"),
                                   wxArtProvider::GetBitmap(wxART_ADD_BOOKMARK, wxART_TOOLBAR, wxSize(32,32)));
    // Waveguide Tools
    wgRibbonButtonBar->AddButton(wxID_ANY, wxT("Rectangular Waveguide"),
                                   wxArtProvider::GetBitmap(wxART_QUESTION, wxART_TOOLBAR, wxSize(32,32)));

    wgRibbonButtonBar->AddButton(wxID_ANY, wxT("Circular Waveguide"),
                                   wxArtProvider::GetBitmap(wxART_QUESTION, wxART_TOOLBAR, wxSize(32,32)));

    wgRibbonButtonBar->AddButton(wxID_ANY, wxT("Double Ridge Waveguide"),
                                   wxArtProvider::GetBitmap(wxART_QUESTION, wxART_TOOLBAR, wxSize(32,32)));

    wgRibbonButtonBar->AddButton(wxID_ANY, wxT("Waveguide Modes"),
                                   wxArtProvider::GetBitmap(wxART_QUESTION, wxART_TOOLBAR, wxSize(32,32)));

    wgRibbonButtonBar->AddButton(wxID_ANY, wxT("Waveguide Dimensions"),
                                   wxArtProvider::GetBitmap(wxART_QUESTION, wxART_TOOLBAR, wxSize(32,32)));

    coaxRibbonButtonBar->AddButton(wxID_ANY, wxT("Coaxial Impedance"),
                                   wxArtProvider::GetBitmap(wxART_QUESTION, wxART_TOOLBAR, wxSize(32,32)));

    //Radome Tools
    radomeRibbonButtonBar->AddButton(wxID_ANY, wxT("Multi-Layer Radome Analysis"),
                                   wxArtProvider::GetBitmap(wxART_QUESTION, wxART_TOOLBAR, wxSize(32,32)));

    radomeRibbonButtonBar->AddButton(wxID_ANY, wxT("Dielectric Properties"),
                                   wxArtProvider::GetBitmap(wxART_QUESTION, wxART_TOOLBAR, wxSize(32,32)));



    ribbonBar->AddPageHighlight(ribbonBar->GetPageCount());
    ribbonBar->Realise();


    // Set layout with sizers
    wxSizer* sizer = new wxBoxSizer(wxVERTICAL);
    sizer->Add(ribbonBar, 0, wxEXPAND);

    wxSizer* panelSizer = new wxBoxSizer(wxVERTICAL);
    panelSizer->Add(panel, 1, wxEXPAND);

   // panelSizer->Show(panel);

    sizer->Add(panelSizer, 1, wxEXPAND);
    panelSizer->Hide(panel);


  SetSizer(sizer);

 // panelSizer->Show(panel);

    Center();

    // Set status bar
    CreateStatusBar(2);
    SetStatusText(_T("Status Text 1"), 0);
    SetStatusText(_T("Status Text 2"), 1);

//panelSizer->Show(panel);  Testing Show(panel) within MainWindow setup and it works here.
//panel->Show();
}

// Functions Here

void MainWindow::OnMicrostripButton(wxRibbonButtonBarEvent& evt)
{
 MainWindow::panel->Show();
    //panelSizer->Show(panel);
    panel->Refresh();
}

void MainWindow::OnCPWButton(wxRibbonButtonBarEvent& evt)
{
  //wxMessageBox("MainWindow::OnCPWButton");

  wxPanel *panelCPW = new wxPanel(this, -1);
  panelCPW->SetBackgroundColour(wxColor(50, 200, 200));
//  sizer->Add(panelCPW, 1, wxEXPAND);
//  //SetSizer(sizer);
//  panelMicrostrip->Hide();
//  panelCPW->Show();
//  panelCPW->Refresh();
//  SetSizer(sizer);

}

void MainWindow::OnCPW_GButton(wxRibbonButtonBarEvent& evt)
{
  wxMessageBox("MainWindow::OnCPW_GButton");
}

void MainWindow::OnStriplineButton(wxRibbonButtonBarEvent& evt)
{
  wxMessageBox("MainWindow::OnStriplineButton");
}

void MainWindow::OnCoupled_StriplineButton(wxRibbonButtonBarEvent& evt)
{
  wxMessageBox("MainWindow::OnCoupled_StriplineButton");
}


Post Reply