Exemplo n.º 1
0
    def __init__(self, *args):
        """MotorBrick constructor

        Arguments:
        :params args: 
        """
        super(MotorBrick, self).__init__(*args)

        # Hardware objects ----------------------------------------------------

        self.motor_hwobj = None  # hardware object
        self.control_dialog = None

        # Graphic elements-----------------------------------------------------

        self.frame = QtImport.QGroupBox()
        self.frame_layout = QtImport.QVBoxLayout()

        self.step_slider_panel = QtImport.QWidget()
        step_slider_panel_layout = QtImport.QHBoxLayout()

        self.move_box = MoveBox()

        self.step_backward = StepEditor(StepEditor.LEFT_LAYOUT, 20, None,
                                        "new step:", "-")

        self.slider = MotorSlider()

        self.step_forward = StepEditor(StepEditor.RIGHT_LAYOUT, 20, None,
                                       "new step:", "+")
        self.motor_position_label = self.slider.current_label
        self.name_position_box = QtImport.QFrame()
        self.name_position_box_layout = QtImport.QHBoxLayout()
        self.motor_name_label = QtImport.QLabel()
        self.position_label = QtImport.QLabel()

        # Layout --------------------------------------------------------------
        step_slider_panel_layout.addWidget(self.step_backward)
        step_slider_panel_layout.addWidget(self.slider)
        step_slider_panel_layout.addWidget(self.step_forward)
        self.step_slider_panel.setLayout(step_slider_panel_layout)

        self.frame_layout.addWidget(self.step_slider_panel)
        self.frame_layout.addWidget(self.move_box, 0, QtImport.Qt.AlignCenter)
        self.frame.setLayout(self.frame_layout)

        self.name_position_box_layout.addWidget(self.motor_name_label)
        self.name_position_box_layout.addWidget(self.position_label)

        self.name_position_box.setLayout(self.name_position_box_layout)

        self.setSizePolicy(QtImport.QSizePolicy.Minimum,
                           QtImport.QSizePolicy.Fixed)
        self.frame.setFlat(False)

        # Hide 'edit step' button associated to step_backward
        self.step_backward.allow_change_value(False)

        self.step_slider_panel.setSizePolicy(QtImport.QSizePolicy.Minimum,
                                             QtImport.QSizePolicy.Fixed)
        self.name_position_box.hide()
        self.name_position_box.setSizePolicy(QtImport.QSizePolicy.Expanding,
                                             QtImport.QSizePolicy.Fixed)
        self.name_position_box.setFrameStyle(QtImport.QFrame.Panel
                                             | QtImport.QFrame.Raised)
        self.name_position_box.setLineWidth(1)
        self.name_position_box.setMidLineWidth(0)
        self.motor_name_label.setAlignment(QtImport.Qt.AlignLeft
                                           | QtImport.Qt.AlignVCenter)
        self.position_label.setAlignment(QtImport.Qt.AlignRight
                                         | QtImport.Qt.AlignVCenter)

        self.main_layout = QtImport.QVBoxLayout()
        self.main_layout.addWidget(self.name_position_box, 0,
                                   QtImport.Qt.AlignTop)
        self.main_layout.addWidget(self.frame, 0, QtImport.Qt.AlignCenter)

        self.setLayout(self.main_layout)

        # Qt signal/slot connections -----------------------------------------
        self.move_box.move_motor_signal.connect(self.move_motor)
        self.move_box.stop_motor_signal.connect(self.stop_motor)
        self.step_forward.clicked_signal.connect(self.step_forward_clicked)
        self.step_forward.value_changed_signal.connect(
            self.step_forward_value_changed)
        self.step_backward.clicked_signal.connect(self.step_backward_clicked)

        # define properties

        self.add_property("appearance", "combo", ("tiny", "normal"), "normal")
        self.add_property("allowConfigure", "boolean", True)
        self.add_property("mnemonic", "string", "")
        self.add_property("allowDoubleClick", "boolean", False)
        self.add_property("formatString", "formatString", "+##.####")  # %+8.4f
        self.add_property("dialogCaption", "string", "", hidden=True)
Exemplo n.º 2
0
    def __init__(self,
                 layout,
                 initial_value,
                 parent=None,
                 title="",
                 prefix=""):
        """"
        Constructor of StepEditor

        :param layout: select step value edit widget position
        :param initial_value: set motor initial position
        :param parent: parent widget
        :param title: step value edit widget's title
        :param prefix: + / - symbol fordward/backward step buttons
        """
        super(StepEditor, self).__init__(parent)

        self.prefix = prefix
        self.value = initial_value

        # Graphic elements-----------------------------------------------------

        self.title_label = QtImport.QLabel(title)
        self.selection_box = QtImport.QFrame()
        self.edition_box = QtImport.QFrame()

        self.txt_new_value = QtImport.QLineEdit()
        self.cmd_ok = QtImport.QPushButton()
        self.cmd_ok.setIcon(Icons.load_icon("button_ok_small"))
        self.cmd_ok.setFixedWidth(20)

        self.cmd_cancel = QtImport.QPushButton()
        self.cmd_cancel.setIcon(Icons.load_icon("button_cancel_small"))
        self.cmd_cancel.setFixedWidth(20)

        self.edition_box.hide()
        self.title_label.hide()
        self.edition_box.setSizePolicy(QtImport.QSizePolicy.Fixed,
                                       QtImport.QSizePolicy.Fixed)

        self.double_validator = QtImport.QDoubleValidator(self.txt_new_value)
        self.double_validator.setNotation(
            QtImport.QDoubleValidator.StandardNotation)
        self.txt_new_value.setValidator(self.double_validator)

        # Layout --------------------------------------------------------------

        self.main_vertical_layout = QtImport.QVBoxLayout()
        self.selection_box_layout = QtImport.QHBoxLayout()
        self.edition_box_layout = QtImport.QHBoxLayout()

        # widget's addition order defines their position

        self.edition_box_layout.addWidget(self.txt_new_value)
        self.edition_box_layout.addWidget(self.cmd_ok)
        self.edition_box_layout.addWidget(self.cmd_cancel)
        self.edition_box.setLayout(self.edition_box_layout)

        self.selection_box_layout.addWidget(self.edition_box)

        if layout == StepEditor.RIGHT_LAYOUT:
            self.cmd_select_value = QtImport.QPushButton(prefix +
                                                         str(initial_value))
            self.cmd_edit_value = QtImport.QPushButton("...")
            self.selection_box_layout.addWidget(self.cmd_select_value)
            self.selection_box_layout.addWidget(self.cmd_edit_value)

        else:
            self.cmd_edit_value = QtImport.QPushButton("...")
            self.cmd_select_value = QtImport.QPushButton(prefix +
                                                         str(initial_value))
            self.selection_box_layout.addWidget(self.cmd_edit_value)
            self.selection_box_layout.addWidget(self.cmd_select_value)

        self.selection_box.setLayout(self.selection_box_layout)

        self.main_vertical_layout.addWidget(self.title_label)
        self.main_vertical_layout.addWidget(self.selection_box)

        self.setLayout(self.main_vertical_layout)

        self.cmd_select_value.setAutoDefault(False)

        # Qt signal/slot connections -----------------------------------------
        self.cmd_select_value.clicked.connect(self.cmd_select_value_clicked)
        self.cmd_edit_value.clicked.connect(self.cmd_edit_values_clicked)
        self.txt_new_value.returnPressed.connect(self.validate_new_value)
        self.cmd_ok.clicked.connect(self.validate_new_value)
        self.cmd_cancel.clicked.connect(self.end_edit)