Пример #1
0
class ObjectUI(QtWidgets.QWidget):
    """
    Base class for the UI of FlatCAM objects. Deriving classes should
    put UI elements in ObjectUI.custom_box (QtWidgets.QLayout).
    """
    def __init__(self,
                 icon_file='share/flatcam_icon32.png',
                 title='FlatCAM Object',
                 parent=None):
        QtWidgets.QWidget.__init__(self, parent=parent)

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

        ## Page Title box (spacing between children)
        self.title_box = QtWidgets.QHBoxLayout()
        layout.addLayout(self.title_box)

        ## Page Title icon
        pixmap = QtWidgets.QPixmap(icon_file)
        self.icon = QtWidgets.QLabel()
        self.icon.setPixmap(pixmap)
        self.title_box.addWidget(self.icon, stretch=0)

        ## Title label
        self.title_label = QtWidgets.QLabel("<font size=5><b>" + title +
                                            "</b></font>")
        self.title_label.setAlignment(QtCore.Qt.AlignLeft
                                      | QtCore.Qt.AlignVCenter)
        self.title_box.addWidget(self.title_label, stretch=1)

        ## Object name
        self.name_box = QtWidgets.QHBoxLayout()
        layout.addLayout(self.name_box)
        name_label = QtWidgets.QLabel("Name:")
        self.name_box.addWidget(name_label)
        self.name_entry = FCEntry()
        self.name_box.addWidget(self.name_entry)

        ## Box box for custom widgets
        # This gets populated in offspring implementations.
        self.custom_box = QtWidgets.QVBoxLayout()
        layout.addLayout(self.custom_box)

        ###########################
        ## Common to all objects ##
        ###########################

        #### Scale ####
        self.scale_label = QtWidgets.QLabel('<b>Scale:</b>')
        self.scale_label.setToolTip("Change the size of the object.")
        layout.addWidget(self.scale_label)

        self.scale_grid = QtWidgets.QGridLayout()
        layout.addLayout(self.scale_grid)

        # Factor
        faclabel = QtWidgets.QLabel('Factor:')
        faclabel.setToolTip("Factor by which to multiply\n"
                            "geometric features of this object.")
        self.scale_grid.addWidget(faclabel, 0, 0)
        self.scale_entry = FloatEntry()
        self.scale_entry.set_value(1.0)
        self.scale_grid.addWidget(self.scale_entry, 0, 1)

        # GO Button
        self.scale_button = QtWidgets.QPushButton('Scale')
        self.scale_button.setToolTip("Perform scaling operation.")
        layout.addWidget(self.scale_button)

        #### Offset ####
        self.offset_label = QtWidgets.QLabel('<b>Offset:</b>')
        self.offset_label.setToolTip("Change the position of this object.")
        layout.addWidget(self.offset_label)

        self.offset_grid = QtWidgets.QGridLayout()
        layout.addLayout(self.offset_grid)

        self.offset_vectorlabel = QtWidgets.QLabel('Vector:')
        self.offset_vectorlabel.setToolTip(
            "Amount by which to move the object\n"
            "in the x and y axes in (x, y) format.")
        self.offset_grid.addWidget(self.offset_vectorlabel, 0, 0)
        self.offsetvector_entry = EvalEntry()
        self.offsetvector_entry.setText("(0.0, 0.0)")
        self.offset_grid.addWidget(self.offsetvector_entry, 0, 1)

        self.offset_button = QtWidgets.QPushButton('Offset')
        self.offset_button.setToolTip("Perform the offset operation.")
        layout.addWidget(self.offset_button)

        self.auto_offset_button = QtWidgets.QPushButton('Offset auto')
        self.auto_offset_button.setToolTip(
            "Align the object with the x and y axes.")
        layout.addWidget(self.auto_offset_button)

        #### Mirror ####
        self.mirror_label = QtWidgets.QLabel('<b>Mirror:</b>')
        self.mirror_label.setToolTip("Flip the object along an axis.")
        layout.addWidget(self.mirror_label)

        self.mirror_axis_grid = QtWidgets.QGridLayout()
        layout.addLayout(self.mirror_axis_grid)

        axislabel = QtWidgets.QLabel('Axis:')
        axislabel.setToolTip("Mirror axis parallel to the x or y axis.")
        self.mirror_axis_grid.addWidget(axislabel, 0, 0)

        self.mirror_axis_radio = RadioSet([{
            'label': 'X',
            'value': 'X'
        }, {
            'label': 'Y',
            'value': 'Y'
        }])
        self.mirror_axis_radio.set_value('Y')
        self.mirror_axis_grid.addWidget(self.mirror_axis_radio, 0, 1)

        self.mirror_auto_center_cb = FCCheckBox(
            label='Center axis automatically')
        self.mirror_auto_center_cb.setToolTip(
            "Place the mirror axis on the middle of the object.")
        self.mirror_auto_center_cb.set_value(True)
        layout.addWidget(self.mirror_auto_center_cb)

        self.mirror_button = QtWidgets.QPushButton('Mirror')
        self.mirror_button.setToolTip("Perform the mirror operation.")
        layout.addWidget(self.mirror_button)

        layout.addStretch()