Page 1 of 1

Showing & Hiding of a managed pane.

Posted: Mon Nov 20, 2017 1:10 am
by coder99
Using wxCrafter 2.7
As part of my projects in general, I want to be able to include a log window which the user can chose to show or hide.
When I use wxCrafter to build the GUI, I have, simply included a pane at the bottom with a sizer and a multi-line text control.

Up to now, I have not even tried to hide or show this control, but when I recently I decided to do so,I was unable to hide or show this pane via a menu item or shortcut key.
If I include a 'close' button. I can close the pane, but I have not found any way to to show it again.

After a discussion on the wxWidgets forum - see https://forums.wxwidgets.org/viewtopic. ... 37#p180537
I have managed to get this functionality to work by not adding the log window code in wxCrafter, but rather manually adding it in my main frame constructor.

The big difference seems to be in the way the log window is added in these two cases.
Under wxCrafter, the following code is generated:

Code: Select all

m_panelLog = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDLG_UNIT(this, wxSize(-1,-1)), wxTAB_TRAVERSAL);
    
    m_auimgrMain->AddPane(m_panelLog, wxAuiPaneInfo().Direction(wxAUI_DOCK_BOTTOM).Layer(0).Row(0).Position(0).BestSize(100,100).MinSize(100,100).MaxSize(100,100).CaptionVisible(true).MaximizeButton(false).CloseButton(true).MinimizeButton(false).PinButton(false));
    m_auimgrMain->Update();
    
    wxBoxSizer* boxSizer76 = new wxBoxSizer(wxVERTICAL);
    m_panelLog->SetSizer(boxSizer76);
    
    m_textCtrlLog = new wxTextCtrl(m_panelLog, wxID_ANY, wxT(""), wxDefaultPosition, wxDLG_UNIT(m_panelLog, wxSize(-1,-1)), wxTE_READONLY|wxTE_MULTILINE);
    
    boxSizer76->Add(m_textCtrlLog, 1, wxALL|wxEXPAND, WXC_FROM_DIP(5));
When I manually add the code in the main frame ctor, all I need is

Code: Select all

 m_textCtrlLog = new wxTextCtrl(this, wxID_ANY, wxT(""), wxDefaultPosition, wxDLG_UNIT(this, wxSize(-1,-1)), wxTE_READONLY|wxTE_MULTILINE);
   
    m_auimgrMain->AddPane(m_textCtrlLog, wxAuiPaneInfo().Name("logwin").Caption("log").Bottom());
    m_auimgrMain->Update();
The code I use to hide or show the window invoke as an event handler from the menu item or keyboard shortcut:

Code: Select all

void MyFrame::OnMenuLogShow( wxCommandEvent& event) 
{
  wxAuiPaneInfo& info = GetAuimgrMain()->GetPane("logwin");

    if ( info.IsShown() )
    {
        if ( !event.IsChecked() )
        {
            info.Show(false);
            GetAuimgrMain()->Update();
        }
    }
    else
    {
        if ( event.IsChecked() )
        {
            info.Show(true);
            GetAuimgrMain()->Update();
        }
    }
}
The above handler shows/hides the log pane when its code is added manually, but not when it is added by wxCrafter, even when I adjust for the two different names of the text control
The main problem seems to be that wxCrafter dows not allow adding a plain wxTextCtrl, but only 'containers'.
Then again, perhaps the difference is that the wxCrafter code does not 'name' the text ctrl??
Any comments or corrections ?
TIA

Re: Showing & Hiding of a managed pane.

Posted: Mon Nov 20, 2017 10:33 am
by eranif
Why don't you set the container name to: 'logwin' in wxCrafter?
It will work exactly the same

Re: Showing & Hiding of a managed pane.

Posted: Mon Nov 20, 2017 9:55 pm
by coder99
Thank you, Eran
I had missed the separate wxAUI name for the panel and instead used the name (wrong) of the control in my efforts.
Once I filled in the name in wxAuiPanelInfo, I was able to get the code to work as expected - as least as far as showing & hiding goes. :D