From 33d93fcda441eae9bb7f6cf205ec5b9bd522e039 Mon Sep 17 00:00:00 2001 From: Paul McCarthy <pauld.mccarthy@gmail.com> Date: Fri, 20 Nov 2015 12:10:11 +0000 Subject: [PATCH] The new ToggleControlPanelAction makes the togglePanel(action=..) hack unnecessary, as the Action object tracks opening/closing of control panels, so can update its own state. --- fsl/fsleyes/views/canvaspanel.py | 41 +++++++------------------ fsl/fsleyes/views/histogrampanel.py | 10 ++---- fsl/fsleyes/views/lightboxpanel.py | 4 +-- fsl/fsleyes/views/orthopanel.py | 8 ++--- fsl/fsleyes/views/powerspectrumpanel.py | 11 +++---- fsl/fsleyes/views/timeseriespanel.py | 8 ++--- fsl/fsleyes/views/viewpanel.py | 38 +++++------------------ 7 files changed, 29 insertions(+), 91 deletions(-) diff --git a/fsl/fsleyes/views/canvaspanel.py b/fsl/fsleyes/views/canvaspanel.py index f6b0a1b96..caeb48767 100644 --- a/fsl/fsleyes/views/canvaspanel.py +++ b/fsl/fsleyes/views/canvaspanel.py @@ -317,9 +317,7 @@ class CanvasPanel(viewpanel.ViewPanel): """Toggles an :class:`.OverlayListPanel`. See :meth:`.ViewPanel.togglePanel`. """ - self.togglePanel(overlaylistpanel.OverlayListPanel, - location=wx.BOTTOM, - action=self.toggleOverlayList) + self.togglePanel(overlaylistpanel.OverlayListPanel, location=wx.BOTTOM) @actions.toggleControlAction(overlayinfopanel.OverlayInfoPanel) @@ -327,9 +325,7 @@ class CanvasPanel(viewpanel.ViewPanel): """Toggles an :class:`.OverlayInfoPanel`. See :meth:`.ViewPanel.togglePanel`. """ - self.togglePanel(overlayinfopanel.OverlayInfoPanel, - location=wx.LEFT, - action=self.toggleOverlayInfo) + self.togglePanel(overlayinfopanel.OverlayInfoPanel, location=wx.LEFT) @actions.toggleControlAction(atlaspanel.AtlasPanel) @@ -337,9 +333,7 @@ class CanvasPanel(viewpanel.ViewPanel): """Toggles an :class:`.AtlasPanel`. See :meth:`.ViewPanel.togglePanel`. """ - self.togglePanel(atlaspanel.AtlasPanel, - location=wx.BOTTOM, - action=self.toggleAtlasPanel) + self.togglePanel(atlaspanel.AtlasPanel, location=wx.BOTTOM) @actions.toggleControlAction(overlaydisplaytoolbar.OverlayDisplayToolBar) @@ -348,8 +342,7 @@ class CanvasPanel(viewpanel.ViewPanel): :meth:`.ViewPanel.togglePanel`. """ self.togglePanel(overlaydisplaytoolbar.OverlayDisplayToolBar, - viewPanel=self, - action=self.toggleDisplayToolBar) + viewPanel=self) @actions.toggleControlAction(overlaydisplaypanel.OverlayDisplayPanel) @@ -359,8 +352,7 @@ class CanvasPanel(viewpanel.ViewPanel): """ self.togglePanel(overlaydisplaypanel.OverlayDisplayPanel, floatPane=floatPane, - location=wx.LEFT, - action=self.toggleDisplayToolBar) + location=wx.LEFT) @actions.toggleControlAction(canvassettingspanel.CanvasSettingsPanel) @@ -371,8 +363,7 @@ class CanvasPanel(viewpanel.ViewPanel): self.togglePanel(canvassettingspanel.CanvasSettingsPanel, canvasPanel=self, floatPane=floatPane, - location=wx.LEFT, - action=self.toggleDisplayToolBar) + location=wx.LEFT) @actions.toggleControlAction(locationpanel.LocationPanel) @@ -380,9 +371,7 @@ class CanvasPanel(viewpanel.ViewPanel): """Toggles a :class:`.LocationPanel`. See :meth:`.ViewPanel.togglePanel`. """ - self.togglePanel(locationpanel.LocationPanel, - location=wx.BOTTOM, - action=self.toggleLocationPanel) + self.togglePanel(locationpanel.LocationPanel, location=wx.BOTTOM) @actions.toggleControlAction(clusterpanel.ClusterPanel) @@ -390,9 +379,7 @@ class CanvasPanel(viewpanel.ViewPanel): """Toggles a :class:`.ClusterPanel`. See :meth:`.ViewPanel.togglePanel`. """ - self.togglePanel(clusterpanel.ClusterPanel, - location=wx.TOP, - action=self.toggleClusterPanel) + self.togglePanel(clusterpanel.ClusterPanel, location=wx.TOP) @actions.toggleControlAction(lookuptablepanel.LookupTablePanel) @@ -400,9 +387,7 @@ class CanvasPanel(viewpanel.ViewPanel): """Toggles a :class:`.LookupTablePanel`. See :meth:`.ViewPanel.togglePanel`. """ - self.togglePanel(lookuptablepanel.LookupTablePanel, - location=wx.TOP, - action=self.toggleLookupTablePanel) + self.togglePanel(lookuptablepanel.LookupTablePanel, location=wx.TOP) @actions.toggleControlAction(melclasspanel.MelodicClassificationPanel) def toggleClassificationPanel(self): @@ -410,8 +395,7 @@ class CanvasPanel(viewpanel.ViewPanel): :meth:`.ViewPanel.togglePanel`. """ self.togglePanel(melclasspanel.MelodicClassificationPanel, - location=wx.RIGHT, - action=self.toggleClassificationPanel) + location=wx.RIGHT) @actions.toggleControlAction(shellpanel.ShellPanel) @@ -419,10 +403,7 @@ class CanvasPanel(viewpanel.ViewPanel): """Toggles a :class:`.ShellPanel`. See :meth:`.ViewPanel.togglePanel`. """ - self.togglePanel(shellpanel.ShellPanel, - self, - location=wx.BOTTOM, - action=self.toggleShell) + self.togglePanel(shellpanel.ShellPanel, self, location=wx.BOTTOM) def getSceneOptions(self): diff --git a/fsl/fsleyes/views/histogrampanel.py b/fsl/fsleyes/views/histogrampanel.py index 03d9479b9..b33a1db5d 100644 --- a/fsl/fsleyes/views/histogrampanel.py +++ b/fsl/fsleyes/views/histogrampanel.py @@ -105,10 +105,7 @@ class HistogramPanel(plotpanel.OverlayPlotPanel): """Shows/hides a :class:`.PlotListPanel`. See :meth:`.ViewPanel.togglePanel`. """ - self.togglePanel(plotlistpanel.PlotListPanel, - self, - location=wx.TOP, - action=self.toggleHistogramList) + self.togglePanel(plotlistpanel.PlotListPanel, self, location=wx.TOP) @actions.toggleControlAction(histogramcontrolpanel.HistogramControlPanel) @@ -117,10 +114,7 @@ class HistogramPanel(plotpanel.OverlayPlotPanel): :meth:`.ViewPanel.togglePanel`. """ self.togglePanel( - histogramcontrolpanel.HistogramControlPanel, - self, - location=wx.TOP, - action=self.toggleHistogramControl) + histogramcontrolpanel.HistogramControlPanel, self, location=wx.TOP) def getActions(self): diff --git a/fsl/fsleyes/views/lightboxpanel.py b/fsl/fsleyes/views/lightboxpanel.py index b6042148e..9ab54b1b6 100644 --- a/fsl/fsleyes/views/lightboxpanel.py +++ b/fsl/fsleyes/views/lightboxpanel.py @@ -172,9 +172,7 @@ class LightBoxPanel(canvaspanel.CanvasPanel): """Shows/hides a :class:`.LightBoxToolBar`. See :meth:`.ViewPanel.togglePanel`. """ - self.togglePanel(lightboxtoolbar.LightBoxToolBar, - lb=self, - action=self.toggleLightBoxToolBar) + self.togglePanel(lightboxtoolbar.LightBoxToolBar, lb=self) def getActions(self): diff --git a/fsl/fsleyes/views/orthopanel.py b/fsl/fsleyes/views/orthopanel.py index bfa1234cf..11c5255cd 100644 --- a/fsl/fsleyes/views/orthopanel.py +++ b/fsl/fsleyes/views/orthopanel.py @@ -254,9 +254,7 @@ class OrthoPanel(canvaspanel.CanvasPanel): """Shows/hides an :class:`.OrthoToolBar`. See :meth:`.ViewPanel.togglePanel`. """ - self.togglePanel(orthotoolbar.OrthoToolBar, - ortho=self, - action=self.toggleOrthoToolBar) + self.togglePanel(orthotoolbar.OrthoToolBar, ortho=self) @actions.toggleControlAction(orthoedittoolbar.OrthoEditToolBar) @@ -264,9 +262,7 @@ class OrthoPanel(canvaspanel.CanvasPanel): """Shows/hides an :class:`.OrthoEditToolBar`. See :meth:`.ViewPanel.togglePanel`. """ - self.togglePanel(orthoedittoolbar.OrthoEditToolBar, - ortho=self, - action=self.toggleEditToolBar) + self.togglePanel(orthoedittoolbar.OrthoEditToolBar, ortho=self) def getActions(self): diff --git a/fsl/fsleyes/views/powerspectrumpanel.py b/fsl/fsleyes/views/powerspectrumpanel.py index b5e046023..7b0fc1511 100644 --- a/fsl/fsleyes/views/powerspectrumpanel.py +++ b/fsl/fsleyes/views/powerspectrumpanel.py @@ -114,11 +114,9 @@ class PowerSpectrumPanel(plotpanel.OverlayPlotPanel): """Shows/hides a :class:`.PowerSpectrumControlPanel`. See :meth:`.ViewPanel.togglePanel`. """ - self.togglePanel( - pscontrol.PowerSpectrumControlPanel, - self, - location=wx.TOP, - action=self.togglePowerSpectrumControl) + self.togglePanel(pscontrol.PowerSpectrumControlPanel, + self, + location=wx.TOP) @actions.toggleControlAction(plotlistpanel.PlotListPanel) @@ -128,8 +126,7 @@ class PowerSpectrumPanel(plotpanel.OverlayPlotPanel): """ self.togglePanel(plotlistpanel.PlotListPanel, self, - location=wx.TOP, - action=self.togglePowerSpectrumList) + location=wx.TOP) def getActions(self): diff --git a/fsl/fsleyes/views/timeseriespanel.py b/fsl/fsleyes/views/timeseriespanel.py index e60da78e9..616cbc4b1 100644 --- a/fsl/fsleyes/views/timeseriespanel.py +++ b/fsl/fsleyes/views/timeseriespanel.py @@ -161,10 +161,7 @@ class TimeSeriesPanel(plotpanel.OverlayPlotPanel): """Shows/hides a :class:`.PlotListPanel`. See :meth:`.ViewPanel.togglePanel`. """ - self.togglePanel(plotlistpanel.PlotListPanel, - self, - location=wx.TOP, - action=self.toggleTimeSeriesList) + self.togglePanel(plotlistpanel.PlotListPanel, self, location=wx.TOP) @actions.toggleControlAction(timeseriescontrolpanel.TimeSeriesControlPanel) @@ -174,8 +171,7 @@ class TimeSeriesPanel(plotpanel.OverlayPlotPanel): """ self.togglePanel(timeseriescontrolpanel.TimeSeriesControlPanel, self, - location=wx.TOP, - action=self.toggleTimeSeriesControl) + location=wx.TOP) def getActions(self): diff --git a/fsl/fsleyes/views/viewpanel.py b/fsl/fsleyes/views/viewpanel.py index 4737220a5..fb514c611 100644 --- a/fsl/fsleyes/views/viewpanel.py +++ b/fsl/fsleyes/views/viewpanel.py @@ -17,7 +17,6 @@ import wx.lib.agw.aui as aui import props import fsl.fsleyes.panel as fslpanel -import fsl.fsleyes.actions as actions import fsl.fsleyes.toolbar as fsltoolbar import fsl.fsleyes.profiles as profiles import fsl.fsleyes.displaycontext as fsldisplay @@ -109,14 +108,8 @@ class ViewPanel(fslpanel.FSLEyesPanel): # of {type : instance} mappings of active # FSLeyes control panels that are contained # in this view panel. - # - # The panelActions dict contains a collection - # of {type : Action} mappings, but only if the - # control panel was opened as a result of an - # Action on this view panel. - self.__centrePanel = None - self.__panels = {} - self.__panelActions = {} + self.__centrePanel = None + self.__panels = {} self.__auiMgr = aui.AuiManager( self, @@ -240,14 +233,6 @@ class ViewPanel(fslpanel.FSLEyesPanel): :arg location: If ``floatPane=False``, the initial dock position of the panel - either ``wx.TOP``, ``wx.BOTTOM``, ``wx.LEFT``, or ``wx.RIGHT. Defaults to ``wx.BOTTOM``. - - :arg action: If this method has been called as the result of - execution of a :class:`.ToggleAction`, the - ``ToggleAction`` instance may be passed to this - method. This is so that, if the control panel is - closed directly by the user (as opposed to - re-executing the ``ToggleAction`), the ``toggled`` - state of the action can be updated. :arg kwargs: All keyword arguments, apart from ``floatPane`` and ``location``, are passed to the ``panelType`` @@ -265,14 +250,13 @@ class ViewPanel(fslpanel.FSLEyesPanel): .. warning:: Do not define a control (a.k.a. secondary) panel constructor to accept arguments with the names - ``floatPane``, ``action`` or ``location``, as - arguments with those names will get eaten by this - method before they can be passed to the constructor. + ``floatPane`` or ``location``, as arguments with those + names will get eaten by this method before they can be + passed to the constructor. """ location = kwargs.pop('location', wx.BOTTOM) floatPane = kwargs.pop('floatPane', False) - action = kwargs.pop('action', None) if location not in (wx.TOP, wx.BOTTOM, wx.LEFT, wx.RIGHT): raise ValueError('Invalid value for location') @@ -358,8 +342,7 @@ class ViewPanel(fslpanel.FSLEyesPanel): .FloatingPosition(panePos) self.__auiMgr.AddPane(window, paneInfo) - self.__panels[ panelType] = window - self.__panelActions[panelType] = action + self.__panels[panelType] = window self.__auiMgrUpdate() @@ -574,19 +557,12 @@ class ViewPanel(fslpanel.FSLEyesPanel): if isinstance(panel, (fslpanel .FSLEyesPanel, fsltoolbar.FSLEyesToolBar)): - self .__panels .pop(type(panel)) - action = self.__panelActions.pop(type(panel), None) + self.__panels.pop(type(panel)) # calling fslpanel.FSLEyesPanel.destroy() # here - wx.Destroy is done below panel.destroy() - # If this panel was opened through - # a ToggleAction, make sure that - # its toggled state is correct - if action is not None and isinstance(action, actions.ToggleAction): - action.toggled = False - # Even when the user closes a pane, # AUI does not detach said pane - # we have to do it manually -- GitLab