Skip to content
Snippets Groups Projects
Commit f0959dfb authored by Paul McCarthy's avatar Paul McCarthy
Browse files

PlotPanel now listens for changes to its own properties only -

subclasses manage their properties separately. New property on
HistogramPanel - selectedSeries - which will be used to link the
HistogramListPanel with the HistogramControlPanel without them
explicitly knowing about each other.
parent 7ea1b539
No related branches found
No related tags found
No related merge requests found
......@@ -342,6 +342,9 @@ class HistogramPanel(plotpanel.PlotPanel):
autoBin = props.Boolean(default=True)
showCurrent = props.Boolean(default=True)
histType = props.Choice(('probability', 'count'))
selectedSeries = props.Int(minval=0, clamped=True)
def __init__(self, parent, overlayList, displayCtx):
......@@ -370,14 +373,10 @@ class HistogramPanel(plotpanel.PlotPanel):
self._name,
self.__selectedOverlayChanged)
# Custom listener for autoBin - this
# overwrites the one added by the
# PlotPanel.__init__ method. See the
# __autoBinChanged method.
self.addListener('autoBin',
self._name,
self.__autoBinChanged,
overwrite=True)
self.addListener('showCurrent', self._name, self.draw)
self.addListener('histType', self._name, self.draw)
self.addListener('autoBin', self._name, self.__autoBinChanged)
self.addListener('dataSeries', self._name, self.__dataSeriesChanged)
self.__histCache = {}
self.__current = None
......@@ -389,8 +388,12 @@ class HistogramPanel(plotpanel.PlotPanel):
def destroy(self):
"""De-registers property listeners. """
plotpanel.PlotPanel.destroy(self)
self.removeGlobalListener(self._name)
self.removeListener('showCurrent', self._name)
self.removeListener('histType', self._name)
self.removeListener('autoBin', self._name)
self.removeListener('dataSeries', self._name)
self._overlayList.removeListener('overlays', self._name)
self._displayCtx .removeListener('selectedOverlay', self._name)
......@@ -398,6 +401,12 @@ class HistogramPanel(plotpanel.PlotPanel):
hs.destroy()
def __dataSeriesChanged(self, *a):
self.setConstraint('selectedSeries',
'maxval',
len(self.dataSeries) - 1)
def __overlaysChanged(self, *a):
self.disableListener('dataSeries', self._name)
......
......@@ -127,22 +127,26 @@ class PlotPanel(viewpanel.ViewPanel):
canvas.mpl_connect('button_release_event', self.__onMouseUp)
canvas.mpl_connect('axes_leave_event', self.__onMouseUp)
# Redraw whenever any property changes
self.addGlobalListener(self._name, self.draw)
# Custom listeners for these properties
# TODO Should you use a different listener
# name for these properties? Things will
# break if subclasses overwrite them ..
# Redraw whenever any property changes,
for propName in ['legend',
'autoScale',
'xLogScale',
'yLogScale',
'ticks',
'grid',
'smooth',
'xlabel',
'ylabel']:
self.addListener(propName, self._name, self.draw)
# custom listeners for a couple of properties
self.__name = '{}_{}'.format(self._name, id(self))
self.addListener('dataSeries',
self._name,
self.__dataSeriesChanged,
overwrite=True)
self.__name,
self.__dataSeriesChanged)
self.addListener('limits',
self._name,
self.__limitsChanged,
overwrite=True)
self.__name,
self.__limitsChanged)
self.Bind(wx.EVT_SIZE, lambda *a: self.draw())
......@@ -160,7 +164,18 @@ class PlotPanel(viewpanel.ViewPanel):
def destroy(self):
viewpanel.ViewPanel.destroy(self)
self.removeGlobalListener(self._name)
self.removeListener('dataSeries', self.__name)
self.removeListener('limits', self.__name)
for propName in ['legend',
'autoScale',
'xLogScale',
'yLogScale',
'ticks',
'grid',
'smooth',
'xlabel',
'ylabel']:
self.removeListener(propName, self._name)
def getFigure(self):
......@@ -191,10 +206,10 @@ class PlotPanel(viewpanel.ViewPanel):
xlims = list(self.__axis.get_xlim())
ylims = list(self.__axis.get_ylim())
self.disableListener('limits', self._name)
self.disableListener('limits', self.__name)
self.limits.x = xlims
self.limits.y = ylims
self.enableListener( 'limits', self._name)
self.enableListener( 'limits', self.__name)
def __limitsChanged(self, *a):
......@@ -237,9 +252,9 @@ class PlotPanel(viewpanel.ViewPanel):
ymin = axisylims[0]
ymax = axisylims[1]
self.disableListener('limits', self._name)
self.disableListener('limits', self.__name)
self.limits[:] = [xmin, xmax, ymin, ymax]
self.enableListener('limits', self._name)
self.enableListener('limits', self.__name)
return (xmin, xmax), (ymin, ymax)
......
......@@ -90,6 +90,10 @@ class TimeSeriesPanel(plotpanel.PlotPanel):
displayCtx .addListener('selectedOverlay', self._name, self.draw)
displayCtx .addListener('location', self._name, self.draw)
self.addListener('demean', self._name, self.draw)
self.addListener('usePixdim', self._name, self.draw)
self.addListener('showCurrent', self._name, self.draw)
self.Layout()
self.draw()
......@@ -97,6 +101,11 @@ class TimeSeriesPanel(plotpanel.PlotPanel):
def destroy(self):
plotpanel.PlotPanel.destroy(self)
self.removeListener('demean', self._name)
self.removeListener('usePixdim', self._name)
self.removeListener('showCurrent', self._name)
self._overlayList.removeListener('overlays', self._name)
self._displayCtx .removeListener('selectedOverlay', self._name)
self._displayCtx .removeListener('location', self._name)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment