class ClickablePlotItem(pg.PlotItem):

    def __init__(self, dataset, chan, row, col, *args, **kwargs):
        pg.PlotItem.__init__(self, *args, **kwargs)

        self.dataset = dataset
        self.chan = chan
        self.row = row
        self.col = col
        self.getAxis('left').setStyle(textFillLimits=[(3,0.05)], tickLength=5)
        self.getAxis('bottom').setStyle(tickLength=5)
        self.setTitle(title='Row %d, Col %d, Chan %d' % (self.row, self.col, self.chan))

        # install event filter for viewbox and axes items
        self.vb.installEventFilter(self)
        for axesDict in self.axes.values():
            axesDict['item'].installEventFilter(self)

    def mouseDoubleClickEvent(self, event):
        self.spikeScopeWindow = SpikeScopeWindow(self.dataset, self.chan)
        self.spikeScopeWindow.show()

    def plotRaw(self, dim=False):
        self.clear()
        pen = 0.2 if dim else (143,219,144)
        self.plot(x=self.dataset.time_ms, y=self.dataset.data_uv[self.chan,:],
                    pen=pen)
        self.setYRange(self.dataset.dataMin, self.dataset.dataMax, padding=0.9)

    def plotFiltered(self, dim=False):
        self.clear()
        pen = 0.2 if dim else (143,219,144)
        self.plot(x=self.dataset.time_ms, y=self.dataset.data_uv_filtered[self.chan,:],
                    pen=pen)
        self.setYRange(self.dataset.dataMin_filtered, self.dataset.dataMax_filtered, padding=0.9)

    def eventFilter(self, target, ev):
        if ev.type() == QtCore.QEvent.GraphicsSceneWheel:
            if ev.modifiers() == QtCore.Qt.ControlModifier:
                print 'ctrl-wheel'
                self.axes['bottom']['item'].wheelEvent(ev)
            elif ev.modifiers() == (QtCore.Qt.ControlModifier | QtCore.Qt.ShiftModifier):
                print 'ctrl-shift-wheel'
                self.axes['left']['item'].wheelEvent(ev)
            else:
                print 'wheel'
            return True
        return False
 def mouseDoubleClickEvent(self, event):
     self.spikeScopeWindow = SpikeScopeWindow(self.dataset, self.chan)
     self.spikeScopeWindow.show()