Beispiel #1
0
    def _initShortcuts(self):
        mgr = ShortcutManager()
        shortcutGroupName = "Predictions"

        togglePredictions = QShortcut(
            QKeySequence("p"),
            self,
            member=self.labelingDrawerUi.checkShowPredictions.click)
        mgr.register(shortcutGroupName, "Toggle Prediction Layer Visibility",
                     togglePredictions,
                     self.labelingDrawerUi.checkShowPredictions)

        toggleSegmentation = QShortcut(
            QKeySequence("s"),
            self,
            member=self.labelingDrawerUi.checkShowSegmentation.click)
        mgr.register(shortcutGroupName, "Toggle Segmentaton Layer Visibility",
                     toggleSegmentation,
                     self.labelingDrawerUi.checkShowSegmentation)

        toggleLivePredict = QShortcut(
            QKeySequence("l"),
            self,
            member=self.labelingDrawerUi.checkInteractive.click)
        mgr.register(shortcutGroupName, "Toggle Live Prediction Mode",
                     toggleLivePredict, self.labelingDrawerUi.checkInteractive)
Beispiel #2
0
    def _updateLabelShortcuts(self):
        numShortcuts = len(self._labelShortcuts)
        numRows = len(self._labelControlUi.labelListModel)

        # Add any shortcuts we don't have yet.
        for i in range(numShortcuts, numRows):
            shortcut = QShortcut(
                QKeySequence(str(i + 1)),
                self,
                member=partial(self._labelControlUi.labelListView.selectRow,
                               i))
            self._labelShortcuts.append(shortcut)
            toolTipObject = LabelListModel.EntryToolTipAdapter(
                self._labelControlUi.labelListModel, i)
            ShortcutManager().register("Labeling", "", shortcut, toolTipObject)

        # Make sure that all shortcuts have an appropriate description
        for i in range(numRows):
            shortcut = self._labelShortcuts[i]
            description = "Select " + self._labelControlUi.labelListModel[
                i].name
            ShortcutManager().setDescription(shortcut, description)
    def _initShortcuts(self):
        mgr = ShortcutManager()
        shortcutGroupName = "Predictions"

        togglePredictions = QShortcut( QKeySequence("p"), self, member=self.labelingDrawerUi.checkShowPredictions.click )
        mgr.register( shortcutGroupName,
                      "Toggle Prediction Layer Visibility",
                      togglePredictions,
                      self.labelingDrawerUi.checkShowPredictions )        

        toggleSegmentation = QShortcut( QKeySequence("s"), self, member=self.labelingDrawerUi.checkShowSegmentation.click )
        mgr.register( shortcutGroupName,
                      "Toggle Segmentaton Layer Visibility",
                      toggleSegmentation,
                      self.labelingDrawerUi.checkShowSegmentation )        

        toggleLivePredict = QShortcut( QKeySequence("l"), self, member=self.labelingDrawerUi.checkInteractive.click )
        mgr.register( shortcutGroupName,
                      "Toggle Live Prediction Mode",
                      toggleLivePredict,
                      self.labelingDrawerUi.checkInteractive )
Beispiel #4
0
    def __initShortcuts(self):
        mgr = ShortcutManager()
        shortcutGroupName = "Labeling"

        addLabel = QShortcut(QKeySequence("a"),
                             self,
                             member=self.labelingDrawerUi.AddLabelButton.click)
        mgr.register(shortcutGroupName, "Add New Label Class", addLabel,
                     self.labelingDrawerUi.AddLabelButton)

        navMode = QShortcut(QKeySequence("n"),
                            self,
                            member=self.labelingDrawerUi.arrowToolButton.click)
        mgr.register(shortcutGroupName, "Navigation Cursor", navMode,
                     self.labelingDrawerUi.arrowToolButton)

        brushMode = QShortcut(
            QKeySequence("b"),
            self,
            member=self.labelingDrawerUi.paintToolButton.click)
        mgr.register(shortcutGroupName, "Brush Cursor", brushMode,
                     self.labelingDrawerUi.paintToolButton)

        eraserMode = QShortcut(
            QKeySequence("e"),
            self,
            member=self.labelingDrawerUi.eraserToolButton.click)
        mgr.register(shortcutGroupName, "Eraser Cursor", eraserMode,
                     self.labelingDrawerUi.eraserToolButton)

        changeBrushSize = QShortcut(
            QKeySequence("c"),
            self,
            member=self.labelingDrawerUi.brushSizeComboBox.showPopup)
        mgr.register(shortcutGroupName, "Change Brush Size", changeBrushSize,
                     self.labelingDrawerUi.brushSizeComboBox)

        self._labelShortcuts = []
    def __initShortcuts(self):
        mgr = ShortcutManager()
        shortcutGroupName = "Labeling"

        addLabel = QShortcut( QKeySequence("a"), self, member=self.labelingDrawerUi.AddLabelButton.click )
        mgr.register( shortcutGroupName,
                      "Add New Label Class",
                      addLabel,
                      self.labelingDrawerUi.AddLabelButton )

        navMode = QShortcut( QKeySequence("n"), self, member=self.labelingDrawerUi.arrowToolButton.click )
        mgr.register( shortcutGroupName,
                      "Navigation Cursor",
                      navMode,
                      self.labelingDrawerUi.arrowToolButton )

        brushMode = QShortcut( QKeySequence("b"), self, member=self.labelingDrawerUi.paintToolButton.click )
        mgr.register( shortcutGroupName,
                      "Brush Cursor",
                      brushMode,
                      self.labelingDrawerUi.paintToolButton )

        eraserMode = QShortcut( QKeySequence("e"), self, member=self.labelingDrawerUi.eraserToolButton.click )
        mgr.register( shortcutGroupName,
                      "Eraser Cursor",
                      eraserMode,
                      self.labelingDrawerUi.eraserToolButton )

        changeBrushSize = QShortcut( QKeySequence("c"), self, member=self.labelingDrawerUi.brushSizeComboBox.showPopup )
        mgr.register( shortcutGroupName,
                      "Change Brush Size",
                      changeBrushSize,
                      self.labelingDrawerUi.brushSizeComboBox )


        self._labelShortcuts = []
Beispiel #6
0
    def updateAllLayers(self):
        # Check to make sure all layers are in sync
        # (During image insertions, outputs are resized one at a time.)
        if not self.areProvidersInSync():
            return

        if self.imageIndex >= 0:
            # Ask the subclass for the updated layer list
            newGuiLayers = self.setupLayers(self.imageIndex)
        else:
            newGuiLayers = []

        newNames = set(l.name for l in newGuiLayers)
        if len(newNames) != len(newGuiLayers):
            msg = "All layers must have unique names.\n"
            msg += "You're attempting to use these layer names:\n"
            msg += [l.name for l in newGuiLayers]
            raise RuntimeError()

        # Copy the old visibilities and opacities
        if self.imageIndex != self.lastUpdateImageIndex:
            existing = {l.name: l for l in self.layerstack}
            for layer in newGuiLayers:
                if layer.name in existing.keys():
                    layer.visible = existing[layer.name].visible
                    layer.opacity = existing[layer.name].opacity

            # Clear all existing layers.
            self.layerstack.clear()
            self.lastUpdateImageIndex = self.imageIndex

            # Zoom at a 1-1 scale to avoid loading big datasets entirely...
            for view in self.editor.imageViews:
                view.doScaleTo(1)

        # If the datashape changed, tell the editor
        newDataShape = self.determineDatashape()
        if newDataShape is not None and self.editor.dataShape != newDataShape:
            self.editor.dataShape = newDataShape
            # Find the xyz midpoint
            midpos5d = [x / 2 for x in newDataShape]
            midpos3d = midpos5d[1:4]

            # Start in the center of the volume
            self.editor.posModel.slicingPos = midpos3d
            self.editor.navCtrl.panSlicingViews(midpos3d, [0, 1, 2])

            # If one of the xyz dimensions is 1, the data is 2d.
            singletonDims = filter(lambda (i, dim): dim == 1,
                                   enumerate(newDataShape[1:4]))
            if len(singletonDims) == 1:
                # Maximize the slicing view for this axis
                axis = singletonDims[0][0]
                self.volumeEditorWidget.quadview.ensureMaximized(axis)

        # Old layers are deleted if
        # (1) They are not in the new set or
        # (2) Their data has changed
        for index, oldLayer in reversed(list(enumerate(self.layerstack))):
            if oldLayer.name not in newNames:
                needDelete = True
            else:
                newLayer = filter(lambda l: l.name == oldLayer.name,
                                  newGuiLayers)[0]
                needDelete = (newLayer.datasources != oldLayer.datasources)

            if needDelete:
                layer = self.layerstack[index]
                if hasattr(layer, 'shortcutRegistration'):
                    obsoleteShortcut = layer.shortcutRegistration[2]
                    obsoleteShortcut.setEnabled(False)
                    ShortcutManager().unregister(obsoleteShortcut)
                self.layerstack.selectRow(index)
                self.layerstack.deleteSelected()

        # Insert all layers that aren't already in the layerstack
        # (Identified by the name attribute)
        existingNames = set(l.name for l in self.layerstack)
        for index, layer in enumerate(newGuiLayers):
            if layer.name not in existingNames:
                # Insert new
                self.layerstack.insert(index, layer)

                # If this layer has an associated shortcut, register it with the shortcut manager
                if hasattr(layer, 'shortcutRegistration'):
                    ShortcutManager().register(*layer.shortcutRegistration)
            else:
                # Clean up the layer instance that the client just gave us.
                # We don't want to use it.
                if hasattr(layer, 'shortcutRegistration'):
                    shortcut = layer.shortcutRegistration[2]
                    shortcut.setEnabled(False)

                # Move existing layer to the correct positon
                stackIndex = self.layerstack.findMatchingIndex(
                    lambda l: l.name == layer.name)
                self.layerstack.selectRow(stackIndex)
                while stackIndex > index:
                    self.layerstack.moveSelectedUp()
                    stackIndex -= 1
                while stackIndex < index:
                    self.layerstack.moveSelectedDown()
                    stackIndex += 1