New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AuiManager.LoadPerspective does not update orientation of AuiToolBar #917

Closed
wingel opened this Issue Jul 11, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@wingel
Copy link

wingel commented Jul 11, 2018

I'm trying to use SavePerspective and LoadPerspective of AuiManager. This works fairly well except that the orientation of a docked AuiToolBar is not restored properly by LoadPerspective.

A complete test program is included below. To reproduce the problem, start the program, use the menu item Perspective->Save, move the toolbar from the top and dock it on the left or right side. The toolbar changes orientation as it should and becomes vertical. Now use the menu item Perspective->Load. The toolbar is moved back to the saved position, but it is still vertically oriented. The same thing happens if the other direction, if the perspective is saved with the toolbar in the vertical direction and the toolbar is moved to the horizontal direction and the perspective is loaded.

The fix seems to be easy, edit wx/lib/agw/aui/framemanager.py and remove the comment below in the DoUpdate method:

                if p.IsToolbar():
#                    self.SwitchToolBarOrientation(p)
                    p.best_size = p.window.GetBestSize()

With this change the toolbar orientation is updated on LoadPerspective.

System info:

Ubuntu 16.04
Python version: 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609]

wxWidgets version: 4.0.3 gtk3 (phoenix) wxWidgets 3.0.5

which I installed with:

pip install -f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-16.04 wxPython

Test program:

#! /usr/bin/python
import wx
import wx.lib.agw.aui as aui

class MyFrame(wx.Frame):
    def __init__(self, parent, id=-1, title="AUI Test", pos=wx.DefaultPosition,
                 size=(800, 600), style=wx.DEFAULT_FRAME_STYLE):
        wx.Frame.__init__(self, parent, id, title, pos, size, style)

        self.SetName('main')

        self.makeMenuBar()

        self._mgr = aui.AuiManager()

        self._mgr.SetManagedWindow(self)

        bmp = wx.ArtProvider.GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER, wx.Size(16, 16))

        self.toolbar = aui.AuiToolBar(self, -1, wx.DefaultPosition, wx.DefaultSize, agwStyle=aui.AUI_TB_DEFAULT_STYLE | aui.AUI_TB_OVERFLOW | aui.AUI_TB_TEXT | aui.AUI_TB_HORZ_TEXT)
        self.toolbar.AddSimpleTool(-1, "Item 1", bmp)
        self.toolbar.AddSimpleTool(-1, "Item 2", bmp)
        self.toolbar.AddSimpleTool(-1, "Item 3", bmp)
        self.toolbar.SetToolBitmapSize(wx.Size(8, 8))
        self.toolbar.SetName("tb1")

        self.text1 = wx.TextCtrl(self, -1, "Pane 1 - sample text", wx.DefaultPosition, wx.Size(200,150), wx.NO_BORDER | wx.TE_MULTILINE)
        self.text2 = wx.TextCtrl(self, -1, "Pane 2 - sample text", wx.DefaultPosition, wx.Size(200,150), wx.NO_BORDER | wx.TE_MULTILINE)
        self.text3 = wx.TextCtrl(self, -1, "Main content window",  wx.DefaultPosition, wx.Size(200,150), wx.NO_BORDER | wx.TE_MULTILINE)

        self._mgr.AddPane(self.toolbar, aui.AuiPaneInfo().ToolbarPane().Top().Name('toolbar').Caption("Simple Toolbar"))
        self._mgr.AddPane(self.text1, aui.AuiPaneInfo().Left().Caption("Pane Number One").Name('text1'))
        self._mgr.AddPane(self.text2, aui.AuiPaneInfo().Bottom().Caption("Pane Number Two").Name('text2'))
        self._mgr.AddPane(self.text3, aui.AuiPaneInfo().CenterPane().Name('text3'))

        self._mgr.Update()

        self.OnSave(None)

        self.Bind(wx.EVT_CLOSE, self.OnClose)

    def makeMenuBar(self):
        perspectiveMenu = wx.Menu()
        saveItem = perspectiveMenu.Append(-1, "&Save", "Save perspective")
        loadItem = perspectiveMenu.Append(-1, "&Load", "Load perspective")
        exitItem = perspectiveMenu.Append(wx.ID_EXIT)

        menuBar = wx.MenuBar()
        menuBar.Append(perspectiveMenu, "&Perspective")

        self.SetMenuBar(menuBar)

        self.Bind(wx.EVT_MENU, self.OnLoad, loadItem)
        self.Bind(wx.EVT_MENU, self.OnSave, saveItem)

    def OnClose(self, event):
        # deinitialize the frame manager
        self._mgr.UnInit()
        event.Skip()

    def OnExit(self, event):
        """Close the frame, terminating the application."""
        self.Close(True)

    def OnSave(self, event):
        """Save perspective."""
        self.perspective = self._mgr.SavePerspective()

    def OnLoad(self, event):
        """Load perspective."""
        self._mgr.LoadPerspective(self.perspective)

def main():
    app = wx.App()
    frame = MyFrame(None)
    frame.Show()
    app.MainLoop()

if __name__ == '__main__':
    main()

wingel added a commit to wingel/Phoenix that referenced this issue Jul 14, 2018

Update AuiToolBar orientation in AuiManager.DoUpdate
Fix an issue in wx.lib.agw.aui.AuiManager where the orientation of
an AuiToolBar would not be updated when calling LoadPerspective.

This means that if the orientation of the toolbar can be wrong after
calling LoadPerspective.  Example:  The toolbar has been moved by
the user to the right side of the aui widget so that it is oriented
vertically.  SavePerspective is called to save the arrangement of
the aui panels before the application exits.  When the application
starts up the toolbar is created in the default position and is
oriented horizontally.  LoadPerspective is then called to restore
the saved panel arrangement.  The position of the toolbar will be
restored but the orientation will be still horizonal after the
call, which is probably not what the user expects.

A call to SwitchToolBarOrientation in DoUpdate (which is called
by LoadPerspective) has been commented out since the AuiManager
class was imported into wxPython way back in 2009 so I have been
unable to find out why it was commented out.  Removing the comment
makes the above scenario work properly.  I have done some quick
testing of the change and it does not seem to break anything.

Fixes wxWidgets#917
@RobinD42

This comment has been minimized.

Copy link
Member

RobinD42 commented Oct 4, 2018

Closed by #916

@RobinD42 RobinD42 closed this Oct 4, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment