Example #1
0
class ObjectsFrame(QFrame):

    object_region_changed = pyqtSignal("PyQt_PyObject", "PyQt_PyObject")

    def __init__(self, browser, regions, parent):
        QFrame.__init__(self, parent)
        layout = QGridLayout(self)
        layout.setContentsMargins(5, 5, 5, 5)

        self.browser = browser

        box_detect = QCheckBox("Detect Objects", self)
        box_detect.setChecked(False)
        box_detect.toggled.connect(self._on_detect_objects)
        layout.addWidget(box_detect, 0, 0)
        self._box_detect = box_detect

        self._box_region = QComboBox(self)
        self._box_region.setEnabled(box_detect.checkState() == Qt.Checked)
        self.update_regionbox(regions)
        self._box_region.activated[int].connect(self._on_current_region_changed)
        if len(regions) > 0:
            self._box_region.setCurrentIndex(0)
        layout.addWidget(self._box_region, 1, 0, 1, 2)
        layout.addWidget(QLabel("Show Contours:"), 2, 0)

        box = QRadioButton("by color", self)
        box.setEnabled(False)
        box.setChecked(True)
        box.toggled.connect(self._on_show_by_color)
        layout.addWidget(box, 3, 0)
        self._box_contours = box

        self._btn_contour_color = ColorButton(None, self)
        self._btn_contour_color.setEnabled(box_detect.checkState() == Qt.Checked)
        color = QColor("white")
        color.setAlphaF(1)
        self._btn_contour_color.set_color(color)
        self._btn_contour_color.color_changed.connect(self._on_contour_color_changed)

        layout.addWidget(self._btn_contour_color, 3, 1)

        box_classify = QRadioButton("by classification", self)
        box.setEnabled(False)
        box.setChecked(False)
        box_classify.toggled.connect(self._on_show_by_classification)
        box_classify.setChecked(False)
        layout.addWidget(box_classify, 4, 0)
        self._box_classify = box_classify

        box_show_contours = QCheckBox("show all", self)
        box_show_contours.setChecked(True)
        box_show_contours.toggled.connect(self._on_toggle_show_contours)
        box_show_contours.setEnabled(box_detect.checkState() == Qt.Checked)
        layout.addWidget(box_show_contours, 5, 0)
        self._box_show_contours = box_show_contours

    def update_regionbox(self, regions):
        current = self._box_region.currentText()
        self._box_region.clear()
        for k in sorted(regions):
            self._box_region.addItem(k, regions[k])
            found_old_idx = self._box_region.findText(current, flags=Qt.MatchExactly)
        if found_old_idx < 0:
            self._box_region.setCurrentIndex(0)
        else:
            self._box_region.setCurrentIndex(found_old_idx)
            self._object_region = regions.values()[found_old_idx]

    def _on_show_by_color(self, state):
        if state:
            self.browser._show_objects_by = "color"
            self.browser.on_refresh()

    def _on_show_by_classification(self, state):
        if state:
            self.browser._show_objects_by = "classification"
            self.browser.on_refresh()

    def _on_current_region_changed(self, index):
        channel, region = self._box_region.itemData(index)
        self.object_region_changed.emit(channel, region)

    def _on_detect_objects(self, state):
        # Enable depending buttons
        self._box_region.setEnabled(state)
        self._box_contours.setEnabled(state)
        self._box_classify.setEnabled(state)
        self._box_show_contours.setEnabled(state)
        self._btn_contour_color.setEnabled(state)

        self.browser._detect_objects = state
        self.browser.detect_objects_toggled(state)

    def _on_set_contour_state(self, state):
        self._box_contours.blockSignals(True)
        self._box_contours.setChecked(state)
        self._box_contours.blockSignals(False)

    def _on_contour_color_changed(self, color):
        self.browser._contour_color = color
        self.browser.image_viewer.set_contour_color(color)

    def _on_toggle_show_contours(self, state):
        self.browser._show_objects = state
        self.browser.image_viewer.show_contours = state
        self.browser.image_viewer._update_contours()
Example #2
0
class ObjectsFrame(QFrame):

    object_region_changed = pyqtSignal("PyQt_PyObject", "PyQt_PyObject")

    def __init__(self, browser, regions, parent):
        QFrame.__init__(self, parent)
        layout = QGridLayout(self)
        layout.setContentsMargins(5, 5, 5, 5)

        self.browser = browser

        box_detect = QCheckBox('Detect Objects', self)
        box_detect.setChecked(False)
        box_detect.toggled.connect(self._on_detect_objects)
        layout.addWidget(box_detect, 0, 0)
        self._box_detect = box_detect

        self._box_region = QComboBox(self)
        self._box_region.setEnabled(box_detect.checkState() == Qt.Checked)
        self.update_regionbox(regions)
        self._box_region.activated[int].connect(
            self._on_current_region_changed)
        if len(regions) > 0:
            self._box_region.setCurrentIndex(0)
        layout.addWidget(self._box_region, 1, 0, 1, 2)
        layout.addWidget(QLabel('Show Contours:'), 2, 0)

        box = QRadioButton('by color', self)
        box.setEnabled(False)
        box.setChecked(True)
        box.toggled.connect(self._on_show_by_color)
        layout.addWidget(box, 3, 0)
        self._box_contours = box

        self._btn_contour_color = ColorButton(None, self)
        self._btn_contour_color.setEnabled(
            box_detect.checkState() == Qt.Checked)
        color = QColor('white')
        color.setAlphaF(1)
        self._btn_contour_color.set_color(color)
        self._btn_contour_color.color_changed.connect( \
            self._on_contour_color_changed)

        layout.addWidget(self._btn_contour_color, 3, 1)

        box_classify = QRadioButton('by classification', self)
        box.setEnabled(False)
        box.setChecked(False)
        box_classify.toggled.connect(self._on_show_by_classification)
        box_classify.setChecked(False)
        layout.addWidget(box_classify, 4, 0)
        self._box_classify = box_classify

        box_show_contours = QCheckBox('show all', self)
        box_show_contours.setChecked(True)
        box_show_contours.toggled.connect(self._on_toggle_show_contours)
        box_show_contours.setEnabled(box_detect.checkState() == Qt.Checked)
        layout.addWidget(box_show_contours, 5, 0)
        self._box_show_contours = box_show_contours

    def update_regionbox(self, regions):
        current = self._box_region.currentText()
        self._box_region.clear()
        for k, v in regions.iteritems():
            self._box_region.addItem(k, v)
        try:  # try to keep the current setting
            self._box_region.setCurrentIndex( \
                self._box_region.findText(current, flags=Qt.MatchExactly))
        except Exception:
            pass

    def _on_show_by_color(self, state):
        if state:
            self.browser._show_objects_by = 'color'
            self.browser.on_refresh()

    def _on_show_by_classification(self, state):
        if state:
            self.browser._show_objects_by = 'classification'
            self.browser.on_refresh()

    def _on_current_region_changed(self, index):
        channel, region = self._box_region.itemData(index)
        self.object_region_changed.emit(channel, region)

    def _on_detect_objects(self, state):
        # Enable depending buttons
        self._box_region.setEnabled(state)
        self._box_contours.setEnabled(state)
        self._box_classify.setEnabled(state)
        self._box_show_contours.setEnabled(state)
        self._btn_contour_color.setEnabled(state)

        self.browser._detect_objects = state
        self.browser.detect_objects_toggled(state)

    def _on_set_contour_state(self, state):
        self._box_contours.blockSignals(True)
        self._box_contours.setChecked(state)
        self._box_contours.blockSignals(False)

    def _on_contour_color_changed(self, color):
        self.browser._contour_color = color
        self.browser.image_viewer.set_contour_color(color)

    def _on_toggle_show_contours(self, state):
        self.browser._show_objects = state
        self.browser.image_viewer.show_contours = state
        self.browser.image_viewer._update_contours()
Example #3
0
class ObjectsFrame(QFrame):

    object_region_changed = pyqtSignal("PyQt_PyObject", "PyQt_PyObject")

    def __init__(self, browser, regions, parent):
        QFrame.__init__(self, parent)
        layout = QGridLayout(self)
        layout.setContentsMargins(5, 5, 5, 5)

        self.browser = browser

        box_detect = QCheckBox('Detect Objects', self)
        box_detect.setChecked(False)
        box_detect.toggled.connect(self._on_detect_objects)
        layout.addWidget(box_detect, 0, 0)
        self._box_detect = box_detect

        self._box_region = QComboBox(self)
        self._box_region.setEnabled(box_detect.checkState() == Qt.Checked)
        self.update_regionbox(regions)
        self._box_region.activated[int].connect(self._on_current_region_changed)
        if len(regions) > 0:
            self._box_region.setCurrentIndex(0)
        layout.addWidget(self._box_region, 1, 0, 1, 2)
        layout.addWidget(QLabel('Show Contours:'), 2, 0)

        box = QRadioButton('by color', self)
        box.setEnabled(False)
        box.setChecked(True)
        box.toggled.connect(self._on_show_by_color)
        layout.addWidget(box, 3, 0)
        self._box_contours = box

        self._btn_contour_color = ColorButton(None, self)
        self._btn_contour_color.setEnabled(box_detect.checkState() == Qt.Checked)
        color = QColor('white')
        color.setAlphaF(1)
        self._btn_contour_color.set_color(color)
        self._btn_contour_color.color_changed.connect( \
            self._on_contour_color_changed)

        layout.addWidget(self._btn_contour_color, 3, 1)

        box_classify = QRadioButton('by classification', self)
        box.setEnabled(False)
        box.setChecked(False)
        box_classify.toggled.connect(self._on_show_by_classification)
        box_classify.setChecked(False)
        layout.addWidget(box_classify, 4, 0)
        self._box_classify = box_classify

        box_show_contours = QCheckBox('show all', self)
        box_show_contours.setChecked(True)
        box_show_contours.toggled.connect(self._on_toggle_show_contours)
        box_show_contours.setEnabled(box_detect.checkState() == Qt.Checked)
        layout.addWidget(box_show_contours, 5, 0)
        self._box_show_contours = box_show_contours

    def update_regionbox(self, regions):
        current = self._box_region.currentText()
        self._box_region.clear()
        for k, v in regions.iteritems():
            self._box_region.addItem(k, v)
        try: # try to keep the current setting
            self._box_region.setCurrentIndex( \
                self._box_region.findText(current, flags=Qt.MatchExactly))
        except Exception:
            pass

    def _on_show_by_color(self, state):
        if state:
            self.browser._show_objects_by = 'color'
            self.browser.on_refresh()

    def _on_show_by_classification(self, state):
        if state:
            self.browser._show_objects_by = 'classification'
            self.browser.on_refresh()

    def _on_current_region_changed(self, index):
        channel, region = self._box_region.itemData(index)
        self.object_region_changed.emit(channel, region)

    def _on_detect_objects(self, state):
        # Enable depending buttons
        self._box_region.setEnabled(state)
        self._box_contours.setEnabled(state)
        self._box_classify.setEnabled(state)
        self._box_show_contours.setEnabled(state)
        self._btn_contour_color.setEnabled(state)

        self.browser._detect_objects = state
        self.browser.detect_objects_toggled(state)

    def _on_set_contour_state(self, state):
        self._box_contours.blockSignals(True)
        self._box_contours.setChecked(state)
        self._box_contours.blockSignals(False)

    def _on_contour_color_changed(self, color):
        self.browser._contour_color = color
        self.browser.image_viewer.set_contour_color(color)

    def _on_toggle_show_contours(self, state):
        self.browser._show_objects = state
        self.browser.image_viewer.show_contours = state
        self.browser.image_viewer._update_contours()