Exemplo n.º 1
0
    def __init__(self, settings: ViewSettings):
        super().__init__()
        self.settings = settings
        self.color_list = []
        self.chosen = None
        self.prohibited_names = set(self.settings.label_color_dict.keys()
                                    )  # Prohibited name is added to reduce
        # probability of colormap cache collision

        self.color_picker = QColorDialog()
        self.color_picker.setWindowFlag(Qt.Widget)
        self.color_picker.setOptions(QColorDialog.DontUseNativeDialog
                                     | QColorDialog.NoButtons)
        self.add_color_btn = QPushButton("Add color")
        self.add_color_btn.clicked.connect(self.add_color)
        self.remove_color_btn = QPushButton("Remove last color")
        self.remove_color_btn.clicked.connect(self.remove_color)
        self.save_btn = QPushButton("Save")
        self.save_btn.clicked.connect(self.save)

        self.color_layout = QHBoxLayout()
        layout = QVBoxLayout()
        layout.addWidget(self.color_picker)
        btn_layout = QHBoxLayout()
        btn_layout.addWidget(self.add_color_btn)
        btn_layout.addWidget(self.remove_color_btn)
        btn_layout.addWidget(self.save_btn)
        layout.addLayout(btn_layout)
        layout.addLayout(self.color_layout)
        self.setLayout(layout)
Exemplo n.º 2
0
 def open_color_dialog(self, attr_name, mouse_event):
     d = QColorDialog(self)
     d.setCurrentColor(getattr(self, attr_name))
     f = partial(self.set_color, attr_name)
     d.colorSelected.connect(
         f)  # d.open(f) doesn't pass color for some reason
     d.open()
Exemplo n.º 3
0
 def launch_qcolor_dialog(self):
     color_dialog = QColorDialog(self)
     color_dialog.setCurrentColor(QColor(self.get_color()))
     color_dialog.colorSelected.connect(
         lambda: self.set_line_edit(color_dialog.selectedColor().name()))
     color_dialog.setModal(True)
     color_dialog.show()
Exemplo n.º 4
0
 def __init__(self, parent=None):
     """Initialize the ColorButton."""
     super().__init__(parent=parent)
     self.color_dialog = QColorDialog(self)
     self.clicked.connect(self.color_dialog.show)
     self.setObjectName("ColorButton")
     self.color_dialog.colorSelected.connect(self.setColor)
Exemplo n.º 5
0
    def __init__(self, parent: Optional[QWidget] = None):
        super(ColorPicker, self).__init__(parent)
        self.events = ColorPicker.Events()
        self.setAutoFillBackground(True)

        self._color_dialog = QColorDialog(self)
        self._color_dialog.setWindowFlags(Qt.Widget)
        self._color_dialog.setOptions(QColorDialog.DontUseNativeDialog
                                      | QColorDialog.NoButtons)

        self._menu = QMenu(self)
        action = QWidgetAction(self)
        action.setDefaultWidget(self._color_dialog)
        self._menu.addAction(action)
        self.setMenu(self._menu)

        # noinspection PyUnresolvedReferences
        self._menu.aboutToShow.connect(lambda: self._color_dialog.show())
        # noinspection PyUnresolvedReferences
        self._color_dialog.currentColorChanged.connect(
            self.events.color_changed)
        # noinspection PyUnresolvedReferences
        self._color_dialog.currentColorChanged.connect(
            lambda color: self.update())

        self.update()
Exemplo n.º 6
0
    def __init__(self, settings: ViewSettings):
        super().__init__()
        self.settings = settings
        self.color_picker = QColorDialog()
        self.color_picker.setWindowFlag(Qt.Widget)
        self.color_picker.setOptions(QColorDialog.DontUseNativeDialog
                                     | QColorDialog.NoButtons)
        self.opacity_spin = QDoubleSpinBox()
        self.opacity_spin.setRange(0, 1)
        self.opacity_spin.setSingleStep(0.1)
        self.opacity_spin.setDecimals(2)
        self.change_mask_color_btn = QPushButton("Change mask color")
        self.current_mask_color_preview = ColorShow(
            self.settings.get_from_profile("mask_presentation_color",
                                           [255, 255, 255]))

        self.opacity_spin.setValue(
            self.settings.get_from_profile("mask_presentation_opacity", 1))

        self.current_mask_color_preview.setAutoFillBackground(True)
        self.change_mask_color_btn.clicked.connect(self.change_color)
        self.opacity_spin.valueChanged.connect(self.change_opacity)

        layout = QVBoxLayout()
        layout.addWidget(self.color_picker)
        layout2 = QHBoxLayout()
        layout2.addWidget(self.change_mask_color_btn)
        layout2.addWidget(self.current_mask_color_preview, 1)
        layout2.addWidget(QLabel("Mask opacity"))
        layout2.addWidget(self.opacity_spin)
        layout.addLayout(layout2)
        self.setLayout(layout)
Exemplo n.º 7
0
    def choose_default_color(self):
        palette = self.default_color_btn.palette()
        initial = palette.color(QPalette.Button)

        dialog = QColorDialog(self)
        color: str = dialog.getColor(initial)
        if color.isValid():
            palette.setColor(QPalette.Button, color)
            self.default_color_btn.setPalette(palette)
Exemplo n.º 8
0
 def __init__(self):
     super().__init__()
     self.color_picker = QColorDialog()
     self.color_picker.setWindowFlag(Qt.Widget)
     self.color_picker.setOptions(QColorDialog.DontUseNativeDialog
                                  | QColorDialog.NoButtons)
     self.show_colormap = ColormapEdit()
     self.clear_btn = QPushButton("Clear")
     self.save_btn = QPushButton("Save")
     self.distribute_btn = QPushButton("Distribute evenly")
     self.reverse_btn = QPushButton("Reverse")
     self.info_label = InfoLabel(
         [
             "<strong>Tip:</strong> Select color and double click on below color bar. "
             + "Then repeat to add another colors.",
             "<strong>Tip:</strong> Double click on marker to remove it.",
             "<strong>Tip:</strong>  Press and hold mouse left button on marker to move it on color bar.",
         ],
         delay=10000,
     )
     layout = QVBoxLayout()
     layout.addWidget(self.color_picker)
     layout.addWidget(self.info_label)
     layout.addWidget(self.show_colormap)
     btn_layout = QHBoxLayout()
     btn_layout.addStretch(1)
     btn_layout.addWidget(self.reverse_btn)
     btn_layout.addWidget(self.distribute_btn)
     btn_layout.addWidget(self.clear_btn)
     btn_layout.addWidget(self.save_btn)
     layout.addLayout(btn_layout)
     self.setLayout(layout)
     self.show_colormap.double_clicked.connect(self.add_color)
     self.clear_btn.clicked.connect(self.show_colormap.clear)
     self.save_btn.clicked.connect(self.save)
     self.reverse_btn.clicked.connect(self.show_colormap.reverse)
     self.distribute_btn.clicked.connect(
         self.show_colormap.distribute_evenly)