Ejemplo n.º 1
0
    def addNewLabel(self):
        """
        Add a new label to the label list GUI control.
        Return the new number of labels in the control.
        """
        numLabels = len(self._labelControlUi.labelListModel)
        if numLabels >= len(self._colorTable16) - 1:
            # If the color table isn't large enough to handle all our labels,
            #  append a random color
            randomColor = QColor(numpy.random.randint(0, 255),
                                 numpy.random.randint(0, 255),
                                 numpy.random.randint(0, 255))
            self._colorTable16.append(randomColor.rgba())

        color = QColor()
        color.setRgba(self._colorTable16[
            numLabels + 1])  # First entry is transparent (for zero label)

        label = Label(self.getNextLabelName(), color)
        label.nameChanged.connect(self._updateLabelShortcuts)
        self._labelControlUi.labelListModel.insertRow(
            self._labelControlUi.labelListModel.rowCount(), label)
        nlabels = self._labelControlUi.labelListModel.rowCount()

        # Make the new label selected
        selectedRow = nlabels - 1
        self._labelControlUi.labelListModel.select(selectedRow)

        self._updateLabelShortcuts()
Ejemplo n.º 2
0
    def _addNewLabel(self,
                     labelName,
                     labelColor,
                     pmapColor,
                     makePermanent=True):
        """
        Add a new label to the label list GUI control.
        (Note: In the GUI, the color patch to the left of a label consists of two halves whose colors can be changed
        independently. The top left half is the color used for painting labels interactively; the bottom right half
        for drawing in the segmentation and probability layers.)
        """
        QApplication.setOverrideCursor(Qt.WaitCursor)

        label = Label(labelName, labelColor, pmapColor=pmapColor)

        # Insert new label
        newRow = self.drawer.labelListModel.rowCount()
        self.drawer.labelListModel.insertRow(newRow, label)

        if makePermanent:
            self.drawer.labelListModel.makeRowPermanent(newRow)

        # Make the new label selected
        selectedRow = self.drawer.labelListModel.rowCount() - 1
        self.drawer.labelListModel.select(selectedRow)

        QApplication.restoreOverrideCursor()
Ejemplo n.º 3
0
    def _addNewLabel(self):
        QApplication.setOverrideCursor(Qt.WaitCursor)
        
        """
        Add a new label to the label list GUI control.
        Return the new number of labels in the control.
        """
        label = Label( self.getNextLabelName(), self.getNextLabelColor(),
                       pmapColor=self.getNextPmapColor(),
                   )
        label.nameChanged.connect(self._updateLabelShortcuts)
        label.nameChanged.connect(self.onLabelNameChanged)
        label.colorChanged.connect(self.onLabelColorChanged)
        label.pmapColorChanged.connect(self.onPmapColorChanged)

        newRow = self._labelControlUi.labelListModel.rowCount()
        self._labelControlUi.labelListModel.insertRow( newRow, label )

        if self._allowDeleteLastLabelOnly:
            # make previous label unremovable
            if newRow > 0:
                self._labelControlUi.labelListModel.makeRowPermanent(newRow - 1)

        newColorIndex = self._labelControlUi.labelListModel.index(newRow, 0)
        self.onLabelListDataChanged(newColorIndex, newColorIndex) # Make sure label layer colortable is in sync with the new color

        # Update operator with new name
        operator_names = self._labelingSlots.labelNames.value
        if len(operator_names) < self._labelControlUi.labelListModel.rowCount():
            operator_names.append( label.name )
            try:
                self._labelingSlots.labelNames.setValue( operator_names, check_changed=False )
            except:
                # I have no idea why this is, but sometimes PyQt "loses" exceptions here.
                # Print it out before it's too late!
                log_exception( logger, "Logged the above exception just in case PyQt loses it." )
                raise

        # Call the 'changed' callbacks immediately to initialize any listeners
        self.onLabelNameChanged()
        self.onLabelColorChanged()
        self.onPmapColorChanged()

        # Make the new label selected
        nlabels = self._labelControlUi.labelListModel.rowCount()
        selectedRow = nlabels-1
        self._labelControlUi.labelListModel.select(selectedRow)

        self._updateLabelShortcuts()
       
        e = self._labelControlUi.labelListModel.rowCount() > 0
        self._gui_enableLabeling(e)
        
        QApplication.restoreOverrideCursor()
Ejemplo n.º 4
0
    def _addNewLabel(self):
        """
        Add a new label to the label list GUI control.
        Return the new number of labels in the control.
        """
        label = Label(
            self.getNextLabelName(),
            self.getNextLabelColor(),
            pmapColor=self.getNextPmapColor(),
        )
        label.nameChanged.connect(self._updateLabelShortcuts)
        label.nameChanged.connect(self.onLabelNameChanged)
        label.colorChanged.connect(self.onLabelColorChanged)
        label.pmapColorChanged.connect(self.onPmapColorChanged)

        newRow = self._labelControlUi.labelListModel.rowCount()
        self._labelControlUi.labelListModel.insertRow(newRow, label)
        newColorIndex = self._labelControlUi.labelListModel.index(newRow, 0)
        self.onLabelListDataChanged(
            newColorIndex, newColorIndex
        )  # Make sure label layer colortable is in sync with the new color

        # Call the 'changed' callbacks immediately to initialize any listeners
        self.onLabelNameChanged()
        self.onLabelColorChanged()
        self.onPmapColorChanged()

        # Make the new label selected
        nlabels = self._labelControlUi.labelListModel.rowCount()
        selectedRow = nlabels - 1
        self._labelControlUi.labelListModel.select(selectedRow)

        self._updateLabelShortcuts()

        e = self._labelControlUi.labelListModel.rowCount() > 0
        self._gui_enableLabeling(e)