From 72d8c6da2816b3d5aa19c3ab901a555eac4b769c Mon Sep 17 00:00:00 2001 From: Paul McCarthy <pauld.mccarthy@gmail.com> Date: Fri, 11 Mar 2016 12:05:18 +0000 Subject: [PATCH] Fixed bug w.r.t. user grouping control panels into a tabbed notebook. --- fsl/fsleyes/views/viewpanel.py | 64 ++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 23 deletions(-) diff --git a/fsl/fsleyes/views/viewpanel.py b/fsl/fsleyes/views/viewpanel.py index 1d6f62879..4f25f9ed9 100644 --- a/fsl/fsleyes/views/viewpanel.py +++ b/fsl/fsleyes/views/viewpanel.py @@ -557,31 +557,49 @@ class ViewPanel(fslpanel.FSLEyesPanel): ev.Skip() panel = ev.GetPane().window - if isinstance(panel, (fslpanel .FSLEyesPanel, - fsltoolbar.FSLEyesToolBar)): - - panel = self.__panels.pop(type(panel), None) - - # WTF AUI. Sometimes this method gets called - # twice for a panel, the second time with a - # reference to a wx._wxpyDeadObject; in such - # situations, the Destroy method call below - # will result in an exception being raised. - if panel is not None: - - log.debug('Panel closed: {}'.format(type(panel).__name__)) + # If the user has grouped multiple control panels + # into a single tabbed notebook, and then closed + # the entire notebook, the AuiManager will generate + # a single close event, and will pass us that + # notebook. So we have to look in the notebook + # to see which control panels were actually closed. + if isinstance(panel, wx.lib.agw.aui.AuiNotebook): + panels = [panel.GetPage(i) for i in range(panel.GetPageCount())] + else: + panels = [panel] + + + for panel in list(panels): + + if isinstance(panel, (fslpanel .FSLEyesPanel, + fsltoolbar.FSLEyesToolBar)): + + # WTF AUI. Sometimes this method gets called + # twice for a panel, the second time with a + # reference to a wx._wxpyDeadObject; in such + # situations, the Destroy method call below + # would result in an exception being raised. + if self.__panels.pop(type(panel), None) is None: + panels.remove(panel) # calling fslpanel.FSLEyesPanel.destroy() - # here - wx.Destroy is done below - panel.destroy() - - # Even when the user closes a pane, - # AUI does not detach said pane - - # we have to do it manually - self.__auiMgr.DetachPane(panel) - self.__auiMgrUpdate() - - panel.Destroy() + # here - wx.Destroy is done below + else: + log.debug('Panel closed: {}'.format(type(panel).__name__)) + panel.destroy() + + # Destroy all the panels + for panel in panels: + + # Even when the user closes a pane, + # AUI does not detach said pane - + # we have to do it manually + self.__auiMgr.DetachPane(panel) + wx.CallAfter(panel.Destroy) + + # Update the view panel layout + wx.CallAfter(self.__auiMgrUpdate) + # # Here I am monkey patching the -- GitLab