wxAuiManager::SavePerspective() Problem

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.
User avatar
doublemax
Moderator
Moderator
Posts: 15833
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxAuiManager::SavePerspective() Problem

Post by doublemax » Sat Feb 20, 2021 10:01 am

OrbWeaver wrote:
Sat Feb 20, 2021 9:53 am
You must give your panels consistent, deterministic wxAuiPanelInfo::Name() properties
Thanks for your input, but this is a user-forum.

It would be great if you could post this again at https://groups.google.com/g/wx-users where the core devs can see it. Thanks.
Use the source, Luke!

OrbWeaver
In need of some credit
In need of some credit
Posts: 2
Joined: Fri Feb 19, 2021 8:17 pm

Re: wxAuiManager::SavePerspective() Problem

Post by OrbWeaver » Sat Feb 20, 2021 12:19 pm

doublemax wrote:
Sat Feb 20, 2021 10:01 am
Thanks for your input, but this is a user-forum.
Sorry, I'm not sure what you mean.

"Users" are, in this case, developers who are using wxWidgets to develop their own applications, if I understand correctly? The problem posted by Kerry earlier in the thread described an inability to restore AUI panel state using LoadPerspective(), and my post about giving panels consistent names describes how to solve this problem by using the existing wxWidgets API.

If you are referring specifically to my suggestions for improvements to API or documentation, I am happy to edit these out of the post if they are considered off-topic for a wxWidgets users forum.

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

Re: wxAuiManager::SavePerspective() Problem

Post by doublemax » Sat Feb 20, 2021 1:29 pm

OrbWeaver wrote:
Sat Feb 20, 2021 12:19 pm
If you are referring specifically to my suggestions for improvements to API or documentation...
Yes
OrbWeaver wrote:
Sat Feb 20, 2021 12:19 pm
...I am happy to edit these out of the post if they are considered off-topic for a wxWidgets users forum.
No, they're not off-topic, and you can leave them. But unfortunately the core wxWidgets developers probably won't see them here.
Use the source, Luke!

ollydbg23
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 224
Joined: Fri Dec 12, 2008 10:31 am

Re: wxAuiManager::SavePerspective() Problem

Post by ollydbg23 » Sun Feb 21, 2021 8:10 am

OrbWeaver wrote:
Sat Feb 20, 2021 9:53 am
Apologies for the thread necromancy, but having found this thread after investigating and Googling this exact problem, I thought it was worth detailing the ultimate solution.

You must give your panels consistent, deterministic wxAuiPanelInfo::Name() properties

If you do not specify a Name() when adding a panel, wxWidgets gives the panel an internal, pseudo-random name which changes between sessions. These names are written into the string exported with SavePerspective() and matched in the LoadPerspective() step; if names do not match, the panels will simply disappear (I would suggest this is still a bug: non-matching perspective strings should surely result in no change to the panels, not panels disappearing?).

Nigel's answer touches on this, but sort of implies that the only problem is that you need to create the panels first. This is indeed necessary, but not sufficient: the key fact is you need to create the panels with the same names as in the previous session. In hindsight, this seems somewhat obvious, however nothing in the documentation indicates that the Name() values are important or that LoadPerspective() depends on their values, and there is no error at runtime if the names fail to match, only the unhelpful change to panel visibility.

My suggestions for improvement:
  • The documentation should clearly specify that LoadPerspective() uses Name() values for matching, and will fail if consistent panel names are not specified when the wxAuiManager is populated. Similarly, the documentation for Name() should indicate what the internal name is used for, and should mention that without a user-specified name, an internal name will be generated which is only consistent within the lifetime of the wxAuiManager object.
  • If LoadPerspective() is called with a string containing names which cannot be matched with current panels, these names are ignored and unmatched panels do not change their properties in any way. Depending on whether it is considered valid to attempt to load a perspective with a mix of matching and unmatching names (perhaps if an application can be configured with various different panels), there could be either a warning to console or a wxASSERT in debug mode to alert the developer that something is wrong.
Thanks for the information, by reading this, I found that I have a wrong usage of the wxAuiPanelInfo.

I have some thing like:

Code: Select all

    wxAuiPaneInfo().Name(_T("My Panel")).Caption(_("My Panel"))
Now, I think I should not use _T for the Name() function, because the actual name changes in different language. Which means if I switch the language, I just change the name, and the saved perspective string can't be used in another language.

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2928
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxAuiManager::SavePerspective() Problem

Post by PB » Wed Feb 24, 2021 2:48 pm

ollydbg23 wrote:
Sun Feb 21, 2021 8:10 am
Thanks for the information, by reading this, I found that I have a wrong usage of the wxAuiPanelInfo.

I have some thing like:

Code: Select all

    wxAuiPaneInfo().Name(_T("My Panel")).Caption(_("My Panel"))
Now, I think I should not use _T for the Name() function, because the actual name changes in different language. Which means if I switch the language, I just change the name, and the saved perspective string can't be used in another language.
Unlike _() you use for Caption(), _T() does not cause the string to be translated: It is just an obsolete synonym for wxT():
https://docs.wxwidgets.org/trunk/group_ ... 7ef315472b

ollydbg23
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 224
Joined: Fri Dec 12, 2008 10:31 am

Re: wxAuiManager::SavePerspective() Problem

Post by ollydbg23 » Wed Feb 24, 2021 3:03 pm

PB wrote:
Wed Feb 24, 2021 2:48 pm
ollydbg23 wrote:
Sun Feb 21, 2021 8:10 am
Thanks for the information, by reading this, I found that I have a wrong usage of the wxAuiPanelInfo.

I have some thing like:

Code: Select all

    wxAuiPaneInfo().Name(_T("My Panel")).Caption(_("My Panel"))
Now, I think I should not use _T for the Name() function, because the actual name changes in different language. Which means if I switch the language, I just change the name, and the saved perspective string can't be used in another language.
Unlike _() you use for Caption(), _T() does not cause the string to be translated: It is just an obsolete synonym for wxT():
https://docs.wxwidgets.org/trunk/group_ ... 7ef315472b
Good catch, I did made a mistake. Whether I use _T("My Panel") or "My Panel" gives the same result, I just check the generated layout string, it always contain "My Panel", not the translated language.

Thanks!

Post Reply