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

agw.aui.framemanager does not hide/close a page of automatic notebook properly. #895

Closed
tianzhuqiao opened this Issue Jun 23, 2018 · 4 comments

Comments

Projects
None yet
4 participants
@tianzhuqiao
Copy link

tianzhuqiao commented Jun 23, 2018

agw.aui.framemanager does not hide/close a page of automatic notebook properly (as shown in the following demo).

One potential solution may be

  1. add a flag to notebook page to indicate whether the page is shown or hidden; when it is hidden, do not show as a tab
  2. when click the 'close' button on a page, if DestroyOnClose() is true, then remove the page from notebook and destroy it as usual
  3. otherwise, hide the page
  4. similarly, when click the 'close' button on automatic notebook pane, hide the notebook pane.

2018-06-23_14-33-06

import wx
import wx.lib.agw.aui as aui
import wx.py as py

class RunApp(wx.App):
    def __init__(self):
        wx.App.__init__(self, redirect=False)

    def OnInit(self):
        frame = MainFrame()
        frame.Show(True)
        self.SetTopWindow(frame)
        self.frame = frame
        return True

class MainFrame(wx.Frame):
    ID_SHOW_PANE1 = wx.NewId()
    ID_SHOW_PANE2 = wx.NewId()
    ID_SHOW_PANE3 = wx.NewId()
    ID_LOAD_PERSPECTIVE = wx.NewId()
    def __init__(self):
        wx.Frame.__init__(self, None, -1, 'aui demo', size=(600, 400))
        self._mgr = aui.AuiManager()

        self._mgr.SetManagedWindow(self)

        ns = {}
        ns['wx'] = wx
        ns['app'] = wx.GetApp()
        ns['frame'] = self
        self.shell = py.shell.Shell(self, -1, locals=ns)
        auiinfo = aui.AuiPaneInfo().Caption('shell').BestSize((300, 300))\
                   .DestroyOnClose(False).CenterPane()
        self._mgr.AddPane(self.shell, auiinfo)

        self.panel1 = wx.Panel(self)
        auiinfo1 = aui.AuiPaneInfo().Caption('panel1').BestSize((300, 300)).\
                    DestroyOnClose(False).Top().Snappable().Dockable().\
                    MinimizeButton(True).MaximizeButton(True)

        self._mgr.Update()
        self._mgr.AddPane(self.panel1, auiinfo1)
        self.panel2 = wx.Panel(self)
        auiinfo2 = aui.AuiPaneInfo().Caption('panel2').BestSize((300, 300)).\
                    DestroyOnClose(False).Top().Dockable().\
                    MinimizeButton(True).MaximizeButton(True)

        self._mgr.AddPane(self.panel2, auiinfo2,target=auiinfo1)

        self.panel3 = wx.TextCtrl(self, style=wx.TE_MULTILINE)
        auiinfo3 = aui.AuiPaneInfo().Caption('panel3').BestSize((300, 300)).\
                    DestroyOnClose(False).Top().Dockable().\
                    MinimizeButton(True).MaximizeButton(True)

        self._mgr.AddPane(self.panel3, auiinfo3, target=auiinfo1)

        self.perspective = self._mgr.SavePerspective()
        self._mgr.Update()

        menubar = wx.MenuBar()
        viewMenu = wx.Menu()
        item = wx.MenuItem(viewMenu, self.ID_SHOW_PANE1,
                           text="Show Panel1",kind = wx.ITEM_NORMAL)
        viewMenu.Append(item)
        item = wx.MenuItem(viewMenu, self.ID_SHOW_PANE2,
                           text="Show Panel2",kind = wx.ITEM_NORMAL)
        viewMenu.Append(item)
        item = wx.MenuItem(viewMenu, self.ID_SHOW_PANE3,
                           text="Show Panel3",kind = wx.ITEM_NORMAL)
        viewMenu.Append(item)
        viewMenu.AppendSeparator()
        item = wx.MenuItem(viewMenu, self.ID_LOAD_PERSPECTIVE,
                           text="Load Default Perspective",kind = wx.ITEM_NORMAL)
        viewMenu.Append(item)
        menubar.Append(viewMenu, '&View')
        self.SetMenuBar(menubar)

        self.Bind(wx.EVT_TOOL, self.OnProcessTool)

    def OnProcessTool(self, event):
        eid = event.GetId()
        if eid == self.ID_SHOW_PANE1:
            self._mgr.ShowPane(self.panel1, True)
        elif eid == self.ID_SHOW_PANE2:
            self._mgr.ShowPane(self.panel2, True)
        elif eid == self.ID_SHOW_PANE3:
            self._mgr.ShowPane(self.panel3, True)
        elif eid == self.ID_LOAD_PERSPECTIVE:
            self._mgr.LoadPerspective(self.perspective)
        else:
            event.Skip()

def main():
    app = RunApp()
    app.MainLoop()

if __name__ == '__main__':
    main()
@Metallicow

This comment has been minimized.

Copy link
Contributor

Metallicow commented Jun 24, 2018

Yea, I've noticed this issue when restoring layout from saved perspectives on app restart. Tho Im not sure what the best way to handle a fix would be.... @infinity77 might have a suggestion?

@infinity77

This comment has been minimized.

Copy link
Contributor

infinity77 commented Jun 27, 2018

I don’t have a specific suggestion for this, I almost never use automatic notebooks in our applications. @tianzhuqiao, feel free to implement your solution as a PR if you wish so.

@tianzhuqiao

This comment has been minimized.

Copy link

tianzhuqiao commented Jul 3, 2018

After the change:

2018-07-02_22-19-06

@RobinD42

This comment has been minimized.

Copy link
Member

RobinD42 commented Jul 4, 2018

Fixed by #909

@RobinD42 RobinD42 closed this Jul 4, 2018

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