wxWidgets / Phoenix

wxPython's Project Phoenix. A new implementation of wxPython, better, stronger, faster than he was before.
http://wxpython.org/
2.32k stars 519 forks source link

AuiManager.LoadPerspective does not update orientation of AuiToolBar #917

Closed wingel closed 6 years ago

wingel commented 6 years ago

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()
RobinD42 commented 6 years ago

Closed by #916