def newDetection(self):
        dia = QDialog()
        v = QVBoxLayout()
        dia.setLayout(v)
        self.wMeth = WidgetMultiMethodsParam(
            list_method=list_method,
            method_name='<b>Choose methd for detection</b>:',
            globalApplicationDict=self.globalApplicationDict,
            keyformemory='methodRespiration',
        )
        v.addWidget(self.wMeth)
        buttonBox = QDialogButtonBox(QDialogButtonBox.Ok
                                     | QDialogButtonBox.Cancel)
        v.addWidget(buttonBox)
        #~ self.connect( buttonBox.buttons()[1] , SIGNAL('clicked()') , self.apply )
        self.connect(buttonBox, SIGNAL('rejected()'), dia, SLOT('reject()'))
        self.connect(buttonBox, SIGNAL('accepted()'), dia, SLOT('accept()'))

        if dia.exec_():
            method = self.wMeth.get_method()
            m = method()
            self.cycle_times = m.compute(self.respiration,
                                         **self.wMeth.get_dict())
            self.refreshPlot(with_same_zoom=False)
            self.refreshTable()
    def __init__(
        self,
        parent=None,
        metadata=None,
        session=None,
        Session=None,
        globalApplicationDict=None,
        mode=None,
        tablename=None,
        id_recordingpoint=None,
    ):
        QMainWindow.__init__(self, parent)

        #~ self.setWindowFlags(  Qt.Dialog)
        self.metadata = metadata
        self.globalApplicationDict = globalApplicationDict

        #self.setWindowTitle( 'Spike sorting for recordingpoint %d' % id_recordingpoint )

        self.setAnimated(False)

        self.Session = Session

        #TODO : Not sure why, but it is different in mySQL and SQlite
        try:
            self.session = Session()
        except TypeError:
            self.session = Session
        self.mode = mode

        # recording point in the same group
        recordingPoint = self.session.query(RecordingPoint).filter_by(
            id=id_recordingpoint).one()

        # Window title
        self.setWindowTitle(
            ('Spike sorting for recordingpoint id=%d channel=%s group=%s' %
             (id_recordingpoint, str(
                 recordingPoint.channel), str(recordingPoint.group))))

        # look for recording point with same group
        if recordingPoint.group is not None:
            query = self.session.query(RecordingPoint)
            query = query.filter(
                RecordingPoint.id_block == recordingPoint.id_block)
            query = query.filter(RecordingPoint.group == recordingPoint.group)
            query = query.order_by(RecordingPoint.id)
            rPointListNonSorted = []
            recordingPointList = []
            ids = []
            for rp in query.all():
                rp.metadata = metadata
                rPointListNonSorted.append(rp)
                ids.append(rp.id)
            ind = numpy.argsort(ids)
            for i in ind:
                recordingPointList.append(rPointListNonSorted[i])
        else:
            recordingPointList = [recordingPoint]

        self.spikesorter = spikesorter.SpikeSorter(
            mode=mode,
            session=self.session,
            recordingPointList=recordingPointList,
        )

        # Compute steps widget
        #TEST3
        self.toolboxSteps = QToolBox()
        dock = QDockWidget('Steps', self)
        dock.setWidget(self.toolboxSteps)
        dock.setFeatures(QDockWidget.NoDockWidgetFeatures)
        self.addDockWidget(Qt.LeftDockWidgetArea, dock)
        self.toolboxSteps.setSizePolicy(QSizePolicy.Maximum,
                                        QSizePolicy.Preferred)

        #TEST 2
        #~ w = QWidget()
        #~ w.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        #~ v = QVBoxLayout()
        #~ w.setLayout(v)
        #~ self.toolboxSteps = QToolBox()
        #~ v.addWidget(self.toolboxSteps)
        #~ self.setCentralWidget(w)
        #~ w.setMaximumSize(300,600)

        # TEST 1
        #~ self.toolboxSteps = QToolBox()
        #~ self.setCentralWidget(self.toolboxSteps)
        #~ self.toolboxSteps.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)

        self.hboxes = {}
        self.vboxes = {}
        self.widgetMultimethods = {}
        self.buttonCompute = {}
        s = 0
        for name, module, in spikesorter.steps:
            w = QWidget()
            self.toolboxSteps.addItem(w, QIcon(':/' + name + '.png'), name)
            h = QHBoxLayout()
            self.hboxes[name] = h
            w.setLayout(h)

            v = QVBoxLayout()
            h.addLayout(v)
            self.vboxes[name] = v
            wMeth = WidgetMultiMethodsParam(
                list_method=module.list_method,
                method_name='<b>Choose method for %s</b>:' % name,
                globalApplicationDict=self.globalApplicationDict,
                keyformemory='spikesorting',
            )
            self.widgetMultimethods[name] = wMeth
            v.addWidget(wMeth)
            v.addStretch(0)
            but = QPushButton('Compute %s' % name)
            v.addWidget(but)
            self.buttonCompute[name] = but
            but.clicked.connect(self.computeAStep)
            but.stepNum = s
            but.setEnabled(name in spikesorter.mode_steps[self.mode])
            s += 1

        if self.mode == 'from_full_band_signal':
            self.toolboxSteps.setCurrentIndex(0)
        elif self.mode == 'from_filtered_signal':
            self.toolboxSteps.setCurrentIndex(1)
        elif self.mode == 'from_detected_spike':
            self.toolboxSteps.setCurrentIndex(3)

        # dockable area for plottings
        self.setDockNestingEnabled(True)
        self.toolbar = QToolBar()
        self.addToolBar(self.toolbar)

        # Menu for view template
        #but =  QToolButton( 	popupMode = QToolButton.InstantPopup, toolButtonStyle = Qt.ToolButtonTextBesideIcon)
        but = QToolButton()
        but.setPopupMode(QToolButton.InstantPopup)
        but.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
        self.toolbar.addWidget(but)
        but.setIcon(QIcon(':/view-choose.png'))
        but.setText('Views template')

        self.templateNames = [
            'Best', 'Good ensemble', 'Nothing', 'One cell',
            'Manual clustering', 'Detection', 'Before to save', 'Controls'
        ]
        self.list_actTemplate = []
        for name in self.templateNames:
            act = QAction(name, but)
            act.setCheckable(True)
            self.list_actTemplate.append(act)
            but.addAction(act)
            act.triggered.connect(self.templateChanged)

        # Menu for selecting view
        #but =  QToolButton( 	popupMode = QToolButton.InstantPopup, toolButtonStyle = Qt.ToolButtonTextBesideIcon)
        but = QToolButton()
        but.setPopupMode(QToolButton.InstantPopup)
        but.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
        self.toolbar.addWidget(but)
        but.setIcon(QIcon(':/plot.png'))
        but.setText('Select displayed plots')

        self.list_actionView = []
        self.list_widget = []
        self.list_dock = []
        for W in spikesortingwidgets:
            # Menu
            act = QAction(W.name, but)
            act.setCheckable(True)
            self.list_actionView.append(act)
            if hasattr(W, 'icon_name'):
                act.setIcon(QIcon(':/' + W.icon_name))
            but.addAction(act)
            act.triggered.connect(self.selectPlotChanged)

            # Widget and dock
            w = W(
                spikesorter=self.spikesorter,
                globalApplicationDict=self.globalApplicationDict,
            )
            w.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
            dock = QDockWidget(W.name, self)
            dock.setObjectName(W.name)
            dock.setWidget(w)
            self.addDockWidget(Qt.RightDockWidgetArea, dock)
            self.list_dock.append(dock)
            self.list_widget.append(w)

            self.connect(w, SIGNAL('SpikeLabelsChanged'),
                         self.spikeLabelsChanged)
            self.connect(w, SIGNAL('SpikeSelectionChanged'),
                         self.spikeSelectionChanged)
            self.connect(w, SIGNAL('SpikeSubsetChanged'),
                         self.spikeSubsetChanged)
            dock.visibilityChanged.connect(self.oneDockVisibilityChanged)

        self.toolbar.addSeparator()

        #but =  QToolButton( toolButtonStyle = Qt.ToolButtonTextBesideIcon)
        but = QToolButton()
        but.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
        self.toolbar.addWidget(but)
        but.setIcon(QIcon(':/view-refresh.png'))
        but.setText('Refresh all')
        but.clicked.connect(self.refreshAll)

        #but =  QToolButton( toolButtonStyle = Qt.ToolButtonTextBesideIcon)
        but = QToolButton()
        but.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
        self.toolbar.addWidget(but)
        but.setIcon(QIcon(':/roll.png'))
        but.setText('Sample subset n=')
        but.clicked.connect(self.sampleSubset)
        but.clicked.connect(self.refreshAll)

        #self.spinboxSubsetLimit = QSpinBox( minimum = 0 , maximum =  1e9, specialValueText = "All", singleStep = 500, )
        self.spinboxSubsetLimit = QSpinBox()
        self.spinboxSubsetLimit.setMinimum(0)
        self.spinboxSubsetLimit.setMaximum(1e9)
        self.spinboxSubsetLimit.setSpecialValueText("All")
        self.spinboxSubsetLimit.setSingleStep(500)
        self.spinboxSubsetLimit.setValue(5000)
        self.toolbar.addWidget(self.spinboxSubsetLimit)

        self.toolbar.addSeparator()

        #but =  QToolButton( toolButtonStyle = Qt.ToolButtonTextBesideIcon)
        but = QToolButton()
        but.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
        self.toolbar.addWidget(but)
        but.setIcon(QIcon(':/document-save.png'))
        but.setText('Save to db')
        but.clicked.connect(self.save)

        self.changeTemplate(self.templateNames[0])
        self.refreshAll()
Beispiel #3
0
def saveAsFile(parent=None,
                                    ids =None,
                                    tablenames = None,
                                    metadata = None, 
                                    Session = None,
                                    session = None,
                                    globalApplicationDict = None, ):
    # mode homogeneous
    tablename = tablenames[0]
    
    session = Session()
    
    OEclass = metadata.dictMappedClasses[tablename]
    
    from ..io.io import all_format
    
    list_formats = [ ]
    formats ={ }
    for name, d in all_format:
        
        wo = [ o.__name__.lower() for o in d['class'].writeable_objects ]
        if tablename in wo:
            class F:
                pass
            f = F()
            f.name = name
            f.params = d['class'].write_params[ OEclass ]
            list_formats.append( f )
            formats[name] = d['class']
    
    dia = QDialog()
    dia.setWindowFlags(Qt.Dialog)
    v = QVBoxLayout()
    dia.setLayout(v)
    
    mwp = WidgetMultiMethodsParam( parent = parent ,
                        list_method = list_formats,
                        method_name = 'Export selected '+tablename,
                        globalApplicationDict = globalApplicationDict,
                        )
    v.addWidget( mwp )
    
    params = [
                        [ 'dir' , { 'value' : '' , 'widgettype' : ChooseDirWidget  , 'label' : 'Select path to write files' }],
                    ]
    place = ParamWidget(
                                params,
                                applicationdict = globalApplicationDict,
                                title = None,
                                )
    v.addWidget( place )

    buttonBox = QDialogButtonBox(QDialogButtonBox.Ok)
    v.addWidget(buttonBox)
    dia.connect(buttonBox, SIGNAL('accepted()'), dia, SLOT('accept()'));

    if dia.exec_():
        name =  mwp.get_name()
        options =  mwp.get_dict()
        dir = place['dir']
        for id in ids:
            OEinstance = session.query(OEclass).filter_by(id=id).one()
            IOinstance = formats[name](filename = os.path.join( dir, OEinstance.name+'.'+formats[name].extensions[0] ) )
            if OEclass ==Segment:
                IOinstance.write_segment( OEinstance, **options)
            elif OEclass ==Block:
                IOinstance.write_block( OEinstance, **options)