Ejemplo n.º 1
0
    def __init__(self,trackableFeature,parent=None):
        qt.QWidget.__init__(self,parent)
        PlotController.__init__(self,parent)
        assert isinstance(trackableFeature, lib.TrackableFeature)
        self.__trackableFeature = trackableFeature
        self._canDisable = True
        self._featureTrackerIsEnabled = True
        self.availableFeatureTrackers = fw.FeatureTrackerFactory.getFeatureTrackers()


        #actions
        self.initializeTrackerAction = qt.QAction(self.style().standardIcon(qt.QStyle.SP_BrowserReload),"Initialize",self)
        self.locateInCurrentAction = qt.QAction(self.style().standardIcon(qt.QStyle.SP_MediaPlay),"Find in current profile",self)
        self.locateAllAction = qt.QAction(self.style().standardIcon(qt.QStyle.SP_MediaSeekForward),"Find in all profiles",self)

        #main layout
        layout = qt.QVBoxLayout()
        
        #featureEnabledCheckBox
        self.featureEnabledCheckBox = qt.QCheckBox("Enable")
        self.featureEnabledCheckBox.setChecked(True)
        layout.addWidget(self.featureEnabledCheckBox)

        
        #region limit SpinBoxes
        self.regionSpinBoxControl = RegionSpinBoxControl(self)
        layout.addWidget(self.regionSpinBoxControl)


        #featureTrackerComboBox
        self.featureTrackerComboBox = qt.QComboBox()
        layout.addWidget(self.featureTrackerComboBox)
        for tracker in self.availableFeatureTrackers:
            self.featureTrackerComboBox.addItem(tracker.getDisplayName())
        

        #featureTrackerWidgetContainer
        self.featureTrackerWidgetContainer = qt.QGridLayout()
        self.featureTrackerWidget = None
        layout.addLayout(self.featureTrackerWidgetContainer)
        

        #featureTrackerControls
        buttonsLayout = qt.QHBoxLayout()
        self.initializeButton = qt.QToolButton(self)
        self.initializeButton.setDefaultAction(self.initializeTrackerAction)
        self.findInCurrentProfileButton = qt.QToolButton(self)
        self.findInCurrentProfileButton.setDefaultAction(self.locateInCurrentAction)
        self.findInAllProfilesButton = qt.QToolButton(self)
        self.findInAllProfilesButton.setDefaultAction(self.locateAllAction)
        
        
        buttonsLayout.addStretch()
        buttonsLayout.addWidget(self.initializeButton)
        buttonsLayout.addWidget(self.findInCurrentProfileButton)
        buttonsLayout.addWidget(self.findInAllProfilesButton)
        layout.addLayout(buttonsLayout)

        
        
        self.setLayout(layout)
        
        self.setFeatureTracker()



        #connect signals and slots
        self.featureEnabledCheckBox.stateChanged.connect(self.setFeatureTrackerEnabled)
        self.featureTrackerComboBox.currentIndexChanged.connect(self.setFeatureTracker)

        self.initializeTrackerAction.triggered.connect(self.trackableFeature.initializeTracker)
        self.locateAllAction.triggered.connect(self.trackableFeature.locateAllAsync)
        self.locateInCurrentAction.triggered.connect(self.trackableFeature.locateInCurrent)

        self.trackableFeature.dataSource.sourceDataChanged.connect(self.setRegionMaximum)


        #bind linear region item with model and spinboxes

        self.regionObserver = Observer()
        self.regionObserver.bindToProperty(self.regionSpinBoxControl,"setRegion",useGetter = True)
        self.regionObserver.bindToProperty(self.trackableFeature,"setRegion", useGetter = True)
Ejemplo n.º 2
0
    def __init__(self):
        qt.QWidget.__init__(self, parent=None)
        layout = qt.QVBoxLayout()

        spinbox1 = qt.QSpinBox()
        spinbox2 = qt.QSpinBox()
        textEdit = qt.QTextEdit()
        button = qt.QPushButton()
        slider = qt.QSlider(q.Qt.Horizontal)

        self.model = Model()

        valueObserver = Observer()
        self.valueObserver = valueObserver
        valueObserver.bindToProperty(spinbox1, "value")
        valueObserver.bindToProperty(spinbox2, "value")
        valueObserver.bindToProperty(self.model, "value")
        valueObserver.bindToProperty(slider, "value")

        textObserver = Observer()
        self.textObserver = textObserver
        textObserver.bindToProperty(self.model, "someText")
        textObserver.bind(textEdit,
                          textEdit.setPlainText,
                          textEdit.textChanged,
                          getter=textEdit.toPlainText)

        button.clicked.connect(lambda: setattr(self.model, "value", 10))

        layout.addWidget(spinbox1)
        layout.addWidget(spinbox2)
        layout.addWidget(textEdit)
        layout.addWidget(button)
        layout.addWidget(slider)

        self.setLayout(layout)
Ejemplo n.º 3
0
class TrackableFeatureWidget(qt.QWidget,PlotController):
    """
    Form for defining a trackable feature
    """

    _linearRegionItem_regionChanged = q.pyqtSignal(tuple)


    def __init__(self,trackableFeature,parent=None):
        qt.QWidget.__init__(self,parent)
        PlotController.__init__(self,parent)
        assert isinstance(trackableFeature, lib.TrackableFeature)
        self.__trackableFeature = trackableFeature
        self._canDisable = True
        self._featureTrackerIsEnabled = True
        self.availableFeatureTrackers = fw.FeatureTrackerFactory.getFeatureTrackers()


        #actions
        self.initializeTrackerAction = qt.QAction(self.style().standardIcon(qt.QStyle.SP_BrowserReload),"Initialize",self)
        self.locateInCurrentAction = qt.QAction(self.style().standardIcon(qt.QStyle.SP_MediaPlay),"Find in current profile",self)
        self.locateAllAction = qt.QAction(self.style().standardIcon(qt.QStyle.SP_MediaSeekForward),"Find in all profiles",self)

        #main layout
        layout = qt.QVBoxLayout()
        
        #featureEnabledCheckBox
        self.featureEnabledCheckBox = qt.QCheckBox("Enable")
        self.featureEnabledCheckBox.setChecked(True)
        layout.addWidget(self.featureEnabledCheckBox)

        
        #region limit SpinBoxes
        self.regionSpinBoxControl = RegionSpinBoxControl(self)
        layout.addWidget(self.regionSpinBoxControl)


        #featureTrackerComboBox
        self.featureTrackerComboBox = qt.QComboBox()
        layout.addWidget(self.featureTrackerComboBox)
        for tracker in self.availableFeatureTrackers:
            self.featureTrackerComboBox.addItem(tracker.getDisplayName())
        

        #featureTrackerWidgetContainer
        self.featureTrackerWidgetContainer = qt.QGridLayout()
        self.featureTrackerWidget = None
        layout.addLayout(self.featureTrackerWidgetContainer)
        

        #featureTrackerControls
        buttonsLayout = qt.QHBoxLayout()
        self.initializeButton = qt.QToolButton(self)
        self.initializeButton.setDefaultAction(self.initializeTrackerAction)
        self.findInCurrentProfileButton = qt.QToolButton(self)
        self.findInCurrentProfileButton.setDefaultAction(self.locateInCurrentAction)
        self.findInAllProfilesButton = qt.QToolButton(self)
        self.findInAllProfilesButton.setDefaultAction(self.locateAllAction)
        
        
        buttonsLayout.addStretch()
        buttonsLayout.addWidget(self.initializeButton)
        buttonsLayout.addWidget(self.findInCurrentProfileButton)
        buttonsLayout.addWidget(self.findInAllProfilesButton)
        layout.addLayout(buttonsLayout)

        
        
        self.setLayout(layout)
        
        self.setFeatureTracker()



        #connect signals and slots
        self.featureEnabledCheckBox.stateChanged.connect(self.setFeatureTrackerEnabled)
        self.featureTrackerComboBox.currentIndexChanged.connect(self.setFeatureTracker)

        self.initializeTrackerAction.triggered.connect(self.trackableFeature.initializeTracker)
        self.locateAllAction.triggered.connect(self.trackableFeature.locateAllAsync)
        self.locateInCurrentAction.triggered.connect(self.trackableFeature.locateInCurrent)

        self.trackableFeature.dataSource.sourceDataChanged.connect(self.setRegionMaximum)


        #bind linear region item with model and spinboxes

        self.regionObserver = Observer()
        self.regionObserver.bindToProperty(self.regionSpinBoxControl,"setRegion",useGetter = True)
        self.regionObserver.bindToProperty(self.trackableFeature,"setRegion", useGetter = True)

    @property
    def trackableFeature(self):
        return self.__trackableFeature

        
    def setFeatureTracker(self):
        self.trackableFeature.setTracker(self.availableFeatureTrackers[self.featureTrackerComboBox.currentIndex()]())
        
        if (self.featureTrackerWidget is not None):
            self.featureTrackerWidgetContainer.removeWidget(self.featureTrackerWidget)
            self.featureTrackerWidget.disconnectPlotWidget()
            self.featureTrackerWidget.setParent(None)

        featureTrackerWidgetType = fw.WidgetFactory.getWidgetClassFor(self.trackableFeature.tracker)
        if (featureTrackerWidgetType is not None):
            self.featureTrackerWidget = featureTrackerWidgetType(parent=None)
            if (self.featureTrackerWidget is PlotController):
                self.featureTrackerWidget.connectToPlotWidget(self.plotWidget)
            self.featureTrackerWidgetContainer.addWidget(self.featureTrackerWidget)
        

    def connectToPlotWidget(self, plotWidget):
        super(TrackableFeatureWidget, self).connectToPlotWidget(plotWidget)
        plotitem = self.plotWidget.getPlotItem()
        self.createPlotRegion()

    
    def createPlotRegion(self):
        self.linearRegionItem = pg.LinearRegionItem(brush=pg.intColor(1,alpha=100))
        self.linearRegionItem.setZValue(10)
        self.regionLabel = pg.TextItem(self.trackableFeature.name, color=pg.intColor(1), anchor=(0,1))
        self.regionLabel.setX(self.linearRegionItem.getRegion()[0])
        self.plotWidget.addItem(self.regionLabel)
        self.plotWidget.addItem(self.linearRegionItem, ignoreBounds=True)
        self.linearRegionItem.sigRegionChanged.connect(self.linearRegionItem_RegionChanged)
        self.regionObserver.bind(self.linearRegionItem,self.linearRegionItem.setRegion,self._linearRegionItem_regionChanged)

    def disconnectPlotWidget(self):
        self.linearRegionItem.sigRegionChanged.disconnect(self.linearRegionItem_RegionChanged)
        return super(TrackableFeatureWidget, self).disconnectPlotWidget()
        
    

    def linearRegionItem_RegionChanged(self, r):
        region = r.getRegion()
        self.regionLabel.setX(region[0])
        self._linearRegionItem_regionChanged.emit(region)
    
    
    

        
    def handleFeatureTrackerSelected(self):
        self.setFeatureTracker()

    def setCanDisable(self,canDisable):
        """
        Sets whether or not the "enable" checkbox should be shown on this widget.
        """
        self._canDisable = (canDisable == True)
        
    def getCanDisable(self):
        return self._canDisable

    def setFeatureTrackerEnabled(self,enabled):
        self._featureTrackerIsEnabled = (enabled == True)

    def setRegionMaximum(self):
        if not self.trackableFeature.dataSource.sourceIsEmpty:
            xMaximum = len(self.trackableFeature.dataSource.intensityProfiles.iloc[0])
            self.regionSpinBoxControl.setSpinBoxMaxima(xMaximum)
    def __init__(self):
        qt.QWidget.__init__(self,parent=None)
        layout = qt.QVBoxLayout()

        spinbox1 = qt.QSpinBox()
        spinbox2 = qt.QSpinBox()
        textEdit = qt.QTextEdit()
        button = qt.QPushButton()
        slider = qt.QSlider(q.Qt.Horizontal)
        

        self.model = Model()

        valueObserver = Observer()
        self.valueObserver = valueObserver
        valueObserver.bindToProperty(spinbox1, "value")
        valueObserver.bindToProperty(spinbox2, "value")
        valueObserver.bindToProperty(self.model, "value")
        valueObserver.bindToProperty(slider, "value")

        textObserver = Observer()
        self.textObserver = textObserver
        textObserver.bindToProperty(self.model, "someText")
        textObserver.bind(textEdit, textEdit.setPlainText, textEdit.textChanged, getter = textEdit.toPlainText)

        button.clicked.connect(lambda: setattr(self.model,"value",10))

        layout.addWidget(spinbox1)
        layout.addWidget(spinbox2)
        layout.addWidget(textEdit)
        layout.addWidget(button)
        layout.addWidget(slider)

        self.setLayout(layout)