Kirix Support Forums

wxAui LoadPerspective, Update problem (urgent!)

Please post all general questions, comments, bug reports, and any other wxAUI feedback here.

wxAui LoadPerspective, Update problem (urgent!)

Postby rick_g777 on Fri May 23, 2008 10:29 pm

Hi, I'm trying to use wxAUI for a new project of mine. So far everything's good, panes are created successfully.

The problem comes when saving and loading the perspectives.

Here's the code for the frame init:

Code: Select all
AppFrame::AppFrame(wxFrame *frame, const wxString& title)
    : wxFrame(frame, -1, title)
{
    bool bRet;
    bRet = wxXmlResource::Get()->Load(wxT("resources/mainmenu.xrc"));
    if(bRet) bRet = wxXmlResource::Get()->Load(wxT("resources/projectpane.xrc"));

    if(!bRet) {
        Destroy();
        return;
    }
    m_mgr.SetManagedWindow(this);

    m_projectpanel = CreateProjectPane(); // Creates a panel and some objects inside
    m_monitorpanel = wxXmlResource::Get()->LoadPanel(this,wxT("monitor_panel"));
    m_effectspanel = wxXmlResource::Get()->LoadPanel(this,wxT("effects_panel"));

    m_projectpanel->SetSize(200,300);
    m_projectpanel->SetPosition(wxDefaultPosition);

     // --- Begin wxAUI test ----
     // create several controls

     m_timelinepanel = new wxPanel(this, -1,
                      wxDefaultPosition, wxSize(800,400));
     m_mgr.SetFlags(m_mgr.GetFlags() | wxAUI_MGR_ALLOW_ACTIVE_PANE);
     // add the panes to the manager
    m_mgr.SetDockSizeConstraint(0.3,0.45);
    m_mgr.AddPane(m_projectpanel, wxLEFT,wxT("Project"));
    m_mgr.AddPane(m_monitorpanel, wxBOTTOM,wxT("Monitor"));
    m_mgr.AddPane(m_effectspanel, wxBOTTOM,wxT("Effects"));
    m_mgr.AddPane(m_timelinepanel, wxCENTER, wxT("Timeline"));

    m_mgr.Update(); // Up to this point everything's going fine.

    {
        wxCommandEvent tmpevent(wxEVT_COMMAND_MENU_SELECTED,idMenuLoadDefaultLayout);
        wxPostEvent(this, tmpevent);
    }


The part that loads the layout is the following:
Code: Select all
// ... before this line, some code reads the perspective into strlayout. I checked, it's 806 bytes, just as the last perspective save.

bool result = m_mgr.LoadPerspective(strlayout,false);
if(result) {
    wxMessageBox(_T("Layout loaded successfully"));
   m_mgr.Update();
} else {
    wxMessageBox(_T("Error loading layout!"));
}


What happens, is that the panes are created as usual, then I see the message "Layout loaded successfully". But after I click OK in the dialog box, all the panes disappear! :(

What am I doing wrong? Please help!!
rick_g777
Registered User
 
Posts: 3
Joined: Fri May 23, 2008 10:17 pm

Re: wxAui LoadPerspective, Update problem (urgent!)

Postby rick_g777 on Sat May 24, 2008 12:15 am

I think I found out why they disappear. Apparently after doing Update(), I need to call each Panel's Show() method.

But the panes were supposed to be visible already (they were before I saved the Perspective). Is this a bug or something? Hey, the panes didn't conserve their dockable flags. What happened?
Or do I need to save and restore the panes' info, too?
rick_g777
Registered User
 
Posts: 3
Joined: Fri May 23, 2008 10:17 pm

Re: wxAui LoadPerspective, Update problem (urgent!)

Postby rick_g777 on Sat May 24, 2008 9:21 am

Ah, I saw what went wrong. Guys, this is a serious documentation Issue! If you don't add the panes by actually invoking wxAuiPaneInfo().etc, Loading the Perspective fails! (Whether it's by design or an actual bug doesn't concern me, it SHOULD be documented).

Also, I think you should add more examples of Loading and Saving the perspective, and explain (by example) what the layers do.

In any case, thanks for making such a wonderful toolkit.
rick_g777
Registered User
 
Posts: 3
Joined: Fri May 23, 2008 10:17 pm

Re: wxAui LoadPerspective, Update problem (urgent!)

Postby Ben on Sat May 24, 2008 10:18 am

Hello,

I think the problem is due to a misunderstanding of how perspectives work.

In the example above, panes are being added with the AddPane routine (with three parameters). This adds windows without a pane name. If there is no pane name exists for a given window, a random pane name is added. With the simple AddPane routine you are using, a random pane name is being assigned every time, and is different each time you run the program.

When you load a perspective saved from a previous run, your pane names will be different, and thus the panes will dissappear suddenly.

The solution is quite simple. Use the AddPane(wxAuiPaneInfo&) instead to add your panes. The sample includes examples of this. Look at the following code:

Code: Select all
    m_mgr.AddPane(CreateGrid(), wxAuiPaneInfo().Name(wxT("grid_content")).
                  CenterPane().Hide());


The name parameter is being called and a pane name is being assigned to the window. This will make LoadPerspective work the way you are expecting.

Hope this helps,
Ben
Ben Williams
Kirix Support Team
User avatar
Ben
Kirix Support Team
 
Posts: 525
Joined: Mon Dec 19, 2005 6:29 am

Return to wxAUI Questions, Thoughts & Feedback