Beispiel #1
0
class RectAlignSettingsWidget(QtWidgets.QWidget):
    def __init__(self, parent: 'LayerAlignmentDialog', model: RectAlignmentModel) -> None:
        super(RectAlignSettingsWidget, self).__init__()
        self._parent = parent
        self.model = model

        layout = QtWidgets.QFormLayout()
        self.setLayout(layout)

        dims_gb = QtWidgets.QGroupBox("Scale")
        dims_gb_layout = QtWidgets.QFormLayout()
        dims_gb.setLayout(dims_gb_layout)
        layout.addWidget(dims_gb)

        self.dims_locked_cb = QtWidgets.QCheckBox()
        self.dims_locked_cb.clicked.connect(self.set_dims_locked)
        self.dims_1 = UnitLineEdit(UNIT_GROUP_MM)
        self.dims_2 = UnitLineEdit(UNIT_GROUP_MM)

        self.dims_1.edited.connect(self.changed_dim)
        self.dims_2.edited.connect(self.changed_dim)

        dims_gb_layout.addRow("Dims on perimeter", self.dims_locked_cb)
        dims_gb_layout.addRow("Dimension 1", self.dims_1)
        dims_gb_layout.addRow("Dimension 2", self.dims_2)

        origin_gb = QtWidgets.QGroupBox("Origin")
        origin_gb_layout = QtWidgets.QFormLayout()
        origin_gb.setLayout(origin_gb_layout)
        layout.addWidget(origin_gb)

        self.origin_ref = QtWidgets.QComboBox()
        self.origin_ref.addItem("Lower-left")
        self.origin_ref.addItem("Lower-right")
        self.origin_ref.addItem("Upper-left")
        self.origin_ref.addItem("Upper-right")
        origin_gb_layout.addRow(self.origin_ref)
        self.origin_ref.currentIndexChanged.connect(self.ref_changed)

        self.origin_x = PLineEdit()
        self.origin_y = PLineEdit()

        self.origin_x.editingFinished.connect(self.changed_dim)
        self.origin_y.editingFinished.connect(self.changed_dim)

        origin_gb_layout.addRow("Offset X:", self.origin_x)
        origin_gb_layout.addRow("Offset Y:", self.origin_y)

        layout.addWidget(origin_gb)

        fr_gb = QtWidgets.QGroupBox("Flip/Rotate")
        fr_gb_layout = QtWidgets.QHBoxLayout()
        fr_gb.setLayout(fr_gb_layout)

        self.flip_x_btn = QtWidgets.QPushButton("Flip X")
        self.flip_x_btn.setCheckable(True)
        fr_gb_layout.addWidget(self.flip_x_btn)

        self.flip_y_btn = QtWidgets.QPushButton("Flip Y")
        self.flip_y_btn.setCheckable(True)
        fr_gb_layout.addWidget(self.flip_y_btn)

        fr_gb_layout.addStretch()
        fr_gb_layout.addWidget(QtWidgets.QLabel("Rotate:"))
        self.theta_le = ThetaLineEdit()
        fr_gb_layout.addWidget(self.theta_le)
        fr_gb_layout.addWidget(QtWidgets.QLabel("\u00b0"))

        self.flip_x_btn.clicked.connect(self.rotate_flip_changed)
        self.flip_y_btn.clicked.connect(self.rotate_flip_changed)
        self.theta_le.editingFinished.connect(self.rotate_flip_changed)

        layout.addWidget(fr_gb)

        self.model.update_matricies()
        self.update_from_model()

    def update_from_model(self) -> None:
        self.dims_1.setPlaceholderValue(self.model.placeholder_dim_values[0])
        self.dims_2.setPlaceholderValue(self.model.placeholder_dim_values[1])

        self.dims_1.setValue(self.model.dim_values[0])
        self.dims_2.setValue(self.model.dim_values[1])

        self.dims_locked_cb.setChecked(self.model.dims_locked)

        self.origin_x.setText("%f" % self.model.translate_x)
        self.origin_y.setText("%f" % self.model.translate_y)

        # Updated the box index without forcing a retrigger
        self.origin_ref.blockSignals(True)
        self.origin_ref.setCurrentIndex(self.model.origin_idx)
        self.origin_ref.blockSignals(False)

        self.flip_x_btn.setChecked(self.model.flip_x)
        self.flip_y_btn.setChecked(self.model.flip_y)
        self.theta_le.setText("%4.1f" % math.degrees(self.model.rotate_theta))

    def rotate_flip_changed(self) -> None:
        theta = math.radians(float(self.theta_le.text()))
        cmd = cmd_set_rotate(self.model, theta, self.flip_x_btn.isChecked(), self.flip_y_btn.isChecked())
        self._parent.undoStack.push(cmd)

    def set_dims_locked(self) -> None:
        cmd = cmd_set_dimensions_locked(self.model, self.dims_locked_cb.isChecked())
        self._parent.undoStack.push(cmd)

    def changed_dim(self) -> None:
        dim_a = self.dims_1.getValue()
        dim_b = self.dims_2.getValue()

        translate_x = float(self.origin_x.text())
        translate_y = float(self.origin_y.text())
        if dim_a != self.model.dim_values[0] or dim_b != self.model.dim_values[1] or \
                translate_x != self.model.translate_x or translate_y != self.model.translate_y:
            cmd = cmd_set_dimensions(self.model, dim_a, dim_b, translate_x, translate_y)
            self._parent.undoStack.push(cmd)

    def ref_changed(self, idx: int) -> None:
        # Ordering in the combo box isn't pure counterclockwise. Map ordering to CCW
        if idx == 2:
            idx = 3
        elif idx == 3:
            idx = 2

        cmd = cmd_set_origin_reference(self.model, idx)
        self._parent.undoStack.push(cmd)
Beispiel #2
0
class RectAlignSettingsWidget(QtGui.QWidget):
    def __init__(self, parent, model):
        super(RectAlignSettingsWidget, self).__init__()
        self._parent = parent
        self.model = model

        layout = QtGui.QFormLayout()
        self.setLayout(layout)

        dims_gb = QtGui.QGroupBox("Scale")
        dims_gb_layout = QtGui.QFormLayout()
        dims_gb.setLayout(dims_gb_layout)
        layout.addWidget(dims_gb)

        self.dims_locked_cb = QtGui.QCheckBox()
        self.dims_locked_cb.clicked.connect(self.set_dims_locked)
        self.dims_1 = UnitLineEdit(UNIT_GROUP_MM)
        self.dims_2 = UnitLineEdit(UNIT_GROUP_MM)

        self.dims_1.edited.connect(self.changed_dim)
        self.dims_2.edited.connect(self.changed_dim)


        dims_gb_layout.addRow("Dims on perimeter", self.dims_locked_cb)
        dims_gb_layout.addRow("Dimension 1", self.dims_1)
        dims_gb_layout.addRow("Dimension 2", self.dims_2)

        origin_gb = QtGui.QGroupBox("Origin")
        origin_gb_layout = QtGui.QFormLayout()
        origin_gb.setLayout(origin_gb_layout)
        layout.addWidget(origin_gb)

        self.origin_ref = QtGui.QComboBox()
        self.origin_ref.addItem("Lower-left")
        self.origin_ref.addItem("Lower-right")
        self.origin_ref.addItem("Upper-left")
        self.origin_ref.addItem("Upper-right")
        origin_gb_layout.addRow(self.origin_ref)
        self.origin_ref.currentIndexChanged.connect(self.ref_changed)

        self.origin_x = PLineEdit()
        self.origin_y = PLineEdit()

        self.origin_x.editingFinished.connect(self.changed_dim)
        self.origin_y.editingFinished.connect(self.changed_dim)

        origin_gb_layout.addRow("Offset X:", self.origin_x)
        origin_gb_layout.addRow("Offset Y:", self.origin_y)

        layout.addWidget(origin_gb)

        fr_gb = QtGui.QGroupBox("Flip/Rotate")
        fr_gb_layout = QtGui.QHBoxLayout()
        fr_gb.setLayout(fr_gb_layout)

        self.flip_x_btn = QtGui.QPushButton("Flip X")
        self.flip_x_btn.setCheckable(True)
        fr_gb_layout.addWidget(self.flip_x_btn)

        self.flip_y_btn = QtGui.QPushButton("Flip Y")
        self.flip_y_btn.setCheckable(True)
        fr_gb_layout.addWidget(self.flip_y_btn)

        fr_gb_layout.addStretch()
        fr_gb_layout.addWidget(QtGui.QLabel("Rotate:"))
        self.theta_le = ThetaLineEdit()
        fr_gb_layout.addWidget(self.theta_le)
        fr_gb_layout.addWidget(QtGui.QLabel("\u00b0"))

        self.flip_x_btn.clicked.connect(self.rotate_changed)
        self.flip_y_btn.clicked.connect(self.rotate_changed)
        self.theta_le.editingFinished.connect(self.rotate_changed)

        layout.addWidget(fr_gb)

        self.model.changed.connect(self.update_controls_ra)
        self.model.update_matricies()
        self.update_controls_ra()

    def update_controls_ra(self):
        self.dims_1.setPlaceholderText("%f" % self.model.placeholder_dim_values[0])
        self.dims_2.setPlaceholderText("%f" % self.model.placeholder_dim_values[1])

        self.dims_1.setValue(self.model.dim_values[0])
        self.dims_2.setValue(self.model.dim_values[1])

        self.dims_locked_cb.setChecked(self.model.dims_locked)

        self.origin_x.setText("%f" % self.model.translate_x)
        self.origin_y.setText("%f" % self.model.translate_y)

        # Updated the box index without forcing a retrigger
        self.origin_ref.blockSignals(True)
        self.origin_ref.setCurrentIndex(self.model.origin_idx)
        self.origin_ref.blockSignals(False)


        self.flip_x_btn.setChecked(self.model.flip_x)
        self.flip_y_btn.setChecked(self.model.flip_y)
        self.theta_le.setText("%4.1f" % math.degrees(self.model.rotate_theta))


    def rotate_changed(self):
        theta = math.radians(float(self.theta_le.text()))
        cmd = cmd_set_rotate(self.model, theta, self.flip_x_btn.isChecked(), self.flip_y_btn.isChecked())
        self._parent.undoStack.push(cmd)

    def set_dims_locked(self):
        cmd = cmd_set_dimensions_locked(self.model, self.dims_locked_cb.isChecked())
        self._parent.undoStack.push(cmd)

    def changed_dim(self):
        dim_a = self.dims_1.getValue()
        dim_b = self.dims_2.getValue()

        translate_x = float(self.origin_x.text())
        translate_y = float(self.origin_y.text())
        if dim_a != self.model.dim_values[0] or dim_b != self.model.dim_values[1] or \
                        translate_x != self.model.translate_x or translate_y != self.model.translate_y:
            cmd = cmd_set_dimensions(self.model, dim_a, dim_b, translate_x, translate_y)
            self._parent.undoStack.push(cmd)


    def ref_changed(self, idx):
        # Ordering in the combo box isn't pure counterclockwise. Map ordering to CCW
        if idx == 2:
            idx = 3
        elif idx == 3:
            idx = 2

        cmd = cmd_set_origin_reference(self.model, idx)
        self._parent.undoStack.push(cmd)
Beispiel #3
0
class UnitLineEdit(QtWidgets.QWidget):
    edited = QtCore.Signal()

    def __init__(self, unitGroup: UnitGroup) -> None:
        super(UnitLineEdit, self).__init__()
        self.unit_idx : int = 0
        self._value : Optional[float] = 0

        self._layout = QtWidgets.QHBoxLayout()
        self._layout.setContentsMargins(0,0,0,0)

        self.__lineEdit = PLineEdit()

        # Skipping typing - slots don't seem to work
        self.__lineEdit.editingFinished.connect(self.text_changed)

        self.__unitDropDown = QtWidgets.QComboBox()
        self.__unitDropDown.currentIndexChanged.connect(self.indexChanged)

        self._placeholder_value : Optional[float] = None

        self.setLayout(self._layout)
        self._layout.addWidget(self.__lineEdit, 0)
        self._layout.addWidget(self.__unitDropDown, 1)

        self.setUnitGroup(unitGroup)

    def setPlaceholderText(self, text: str) -> None:
        self.__lineEdit.setPlaceholderText(text)

    def setPlaceholderValue(self, value: float) -> None:
        self._placeholder_value = value
        self.update_field_value()

    def setUnitGroup(self, ug: UnitGroup) -> None:
        self.__unitGroup = ug
        self.__unitDropDown.clear()
        for k in ug.names:
            self.__unitDropDown.addItem(k)

        self.__unitDropDown.setCurrentIndex(ug.default_index)

    def indexChanged(self, idx: int) -> None:
        self.unit_idx = idx
        self.update_field_value()

    def setUnitName(self, unitname: str) -> None:
        pass

    def getUnitName(self) -> None:
        pass

    def setEnabled(self, enabled: bool) -> None:
        self.__unitDropDown.setEnabled(enabled)
        self.__lineEdit.setEnabled(enabled)

    def setValue(self, value: Optional[float]) -> None:
        self._value = value
        self.update_field_value()

    def update_field_value(self) -> None:
        scale = self.__unitGroup.get_scale(self.unit_idx)
        if self._value is None:
            self.__lineEdit.setText("")
        else:
            self.__lineEdit.setText("%s" % (self._value / float(scale)))

        if self._placeholder_value is None:
            self.__lineEdit.setPlaceholderText("")
        else:
            self.__lineEdit.setPlaceholderText("%s" % (self._placeholder_value / float(scale)))

    def text_changed(self) -> None:
        v = self.__lineEdit.text()
        scale = self.__unitGroup.get_scale(self.unit_idx)

        newvalue : Optional[float]
        if v == "":
            newvalue = None
        else:
            newvalue = float(v) * scale

        if newvalue != self._value:
            self._value = newvalue

            self.edited.emit()

    def getValue(self) -> Optional[float]:
        if self._value is not None:
            return self._value
        return self._placeholder_value

    def getValueRaw(self) -> Optional[float]:
        return self._value

    @property
    def suppress_enter(self) -> bool:
        return self.__lineEdit.suppress_enter

    @suppress_enter.setter
    def suppress_enter(self, v: bool) -> None:
        self.__lineEdit.suppress_enter = v
Beispiel #4
0
class UnitLineEdit(QtGui.QWidget):
    edited = QtCore.Signal()

    def __init__(self, unitGroup, field_type=int):
        super(UnitLineEdit, self).__init__()
        self.unit_idx = 0
        self._value = 0
        self._field_type = float

        self.layout = QtGui.QHBoxLayout()
        self.layout.setContentsMargins(0, 0, 0, 0)

        self.__lineEdit = PLineEdit()
        self.__lineEdit.editingFinished.connect(self.text_changed)

        self.__unitDropDown = QtGui.QComboBox()
        self.__unitDropDown.currentIndexChanged.connect(self.indexChanged)

        self.setLayout(self.layout)
        self.layout.addWidget(self.__lineEdit, 0)
        self.layout.addWidget(self.__unitDropDown, 1)

        self.setUnitGroup(unitGroup)

    def setPlaceholderText(self, text):
        self.__lineEdit.setPlaceholderText(text)

    def resize(self, w, h):
        super(UnitLineEdit, self).resize(w, h)

    def setUnitGroup(self, ug):
        self.__unitGroup = ug
        self.__unitDropDown.clear()
        for k in ug.names:
            self.__unitDropDown.addItem(k)

        self.__unitDropDown.setCurrentIndex(ug.default_index)

    def indexChanged(self, idx):
        self.unit_idx = idx
        self.update_field_value()

    def setUnitName(self, unitname):
        pass

    def getUnitName(self):
        pass

    def setEnabled(self, enabled):
        self.__unitDropDown.setEnabled(enabled)
        self.__lineEdit.setEnabled(enabled)

    def setValue(self, value):
        self._value = value
        self.update_field_value()

    def update_field_value(self):
        if self._value is None:
            self.__lineEdit.setText("")
        else:
            scale = self.__unitGroup.get_scale(self.unit_idx)
            self.__lineEdit.setText("%s" % (self._value / float(scale)))

    def text_changed(self):
        v = self.__lineEdit.text()
        scale = self.__unitGroup.get_scale(self.unit_idx)

        if v == "":
            newvalue = None
        else:
            newvalue = float(v) * scale

        if newvalue != self._value:
            self._value = newvalue
            self.edited.emit()

    def getValue(self):
        return self._value

    @property
    def suppress_enter(self):
        return self.__lineEdit.suppress_enter

    @suppress_enter.setter
    def suppress_enter(self, v):
        self.__lineEdit.suppress_enter = v
Beispiel #5
0
class UnitLineEdit(QtGui.QWidget):
    edited = QtCore.Signal()

    def __init__(self, unitGroup, field_type=int):
        super(UnitLineEdit, self).__init__()
        self.unit_idx = 0
        self._value = 0
        self._field_type = float

        self.layout = QtGui.QHBoxLayout()
        self.layout.setContentsMargins(0, 0, 0, 0)

        self.__lineEdit = PLineEdit()
        self.__lineEdit.editingFinished.connect(self.text_changed)

        self.__unitDropDown = QtGui.QComboBox()
        self.__unitDropDown.currentIndexChanged.connect(self.indexChanged)

        self._placeholder_value = None

        self.setLayout(self.layout)
        self.layout.addWidget(self.__lineEdit, 0)
        self.layout.addWidget(self.__unitDropDown, 1)

        self.setUnitGroup(unitGroup)

    def setPlaceholderText(self, text):
        self.__lineEdit.setPlaceholderText(text)

    def setPlaceholderValue(self, value):
        self._placeholder_value = value
        self.update_field_value()

    def resize(self, w, h):
        super(UnitLineEdit, self).resize(w, h)

    def setUnitGroup(self, ug):
        self.__unitGroup = ug
        self.__unitDropDown.clear()
        for k in ug.names:
            self.__unitDropDown.addItem(k)

        self.__unitDropDown.setCurrentIndex(ug.default_index)

    def indexChanged(self, idx):
        self.unit_idx = idx
        self.update_field_value()

    def setUnitName(self, unitname):
        pass

    def getUnitName(self):
        pass

    def setEnabled(self, enabled):
        self.__unitDropDown.setEnabled(enabled)
        self.__lineEdit.setEnabled(enabled)

    def setValue(self, value):
        self._value = value
        self.update_field_value()

    def update_field_value(self):
        scale = self.__unitGroup.get_scale(self.unit_idx)
        if self._value is None:
            self.__lineEdit.setText("")
        else:
            self.__lineEdit.setText("%s" % (self._value / float(scale)))

        if self._placeholder_value is None:
            self.__lineEdit.setPlaceholderText("")
        else:
            self.__lineEdit.setPlaceholderText(
                "%s" % (self._placeholder_value / float(scale)))

    def text_changed(self):
        v = self.__lineEdit.text()
        scale = self.__unitGroup.get_scale(self.unit_idx)

        if v == "":
            newvalue = None
        else:
            newvalue = float(v) * scale

        if newvalue != self._value:
            self._value = newvalue
            self.edited.emit()

    def getValue(self):
        return self._value

    @property
    def suppress_enter(self):
        return self.__lineEdit.suppress_enter

    @suppress_enter.setter
    def suppress_enter(self, v):
        self.__lineEdit.suppress_enter = v