def create_controls(self): """ Create UI controls. """ vbox = QtGui.QVBoxLayout() form = QtGui.QFormLayout() self.num_sigma = QtGui.QDoubleSpinBox() self.num_sigma.setValue(1.0) self.num_sigma.setMinimum(0.0) self.num_sigma.setSingleStep(0.1) self.num_sigma.setMaximum(1e3) self.num_sigma.setDecimals(2) form.addRow(tr("Sigma:"), self.num_sigma) vbox.addLayout(form) self.chk_preview = QtGui.QCheckBox(tr("Preview")) self.chk_preview.setCheckable(True) self.chk_preview.setChecked(False) vbox.addWidget(self.chk_preview) self.chk_preview.toggled[bool].connect(self.set_preview) self.gbo_output = QtGui.QGroupBox(tr("Output")) self.opt_new = QtGui.QRadioButton(tr("New signal")) self.opt_replace = QtGui.QRadioButton(tr("In place")) self.opt_new.setChecked(True) gbo_vbox2 = QtGui.QVBoxLayout() gbo_vbox2.addWidget(self.opt_new) gbo_vbox2.addWidget(self.opt_replace) self.gbo_output.setLayout(gbo_vbox2) vbox.addWidget(self.gbo_output) self.btn_ok = QtGui.QPushButton(tr("&OK")) self.btn_ok.setDefault(True) self.btn_ok.clicked.connect(self.accept) self.btn_cancel = QtGui.QPushButton(tr("&Cancel")) self.btn_cancel.clicked.connect(self.reject) hbox = QtGui.QHBoxLayout() hbox.addWidget(self.btn_ok) hbox.addWidget(self.btn_cancel) vbox.addLayout(hbox) vbox.addStretch(1) self.setLayout(vbox)
def setupButtons(self, yaml_file): """ Parse yaml file and setup Buttons. Format of the yaml file should be: - name: 'button name' (required) image: 'path to image for icon' (optional) image_size: 'width and height of icon' (optional) service: 'service' (required) column: 'column index' (optional, defaults to 0) """ self.buttons = [] with open(yaml_file) as f: yaml_data = yaml.load(f) # lookup colum direction direction = 'vertical' for d in yaml_data: if d.has_key('direction'): if d['direction'] == 'horizontal': direction = 'horizontal' else: # d['direction'] == 'vertical': direction = 'vertical' yaml_data.remove(d) break # lookup column num column_indices = [d['column'] for d in yaml_data] max_column_index = max(*column_indices) if direction == 'vertical': self.layout = QtGui.QHBoxLayout() self.layout_boxes = [QtGui.QVBoxLayout() for i in range(max_column_index + 1)] else: # direction == 'horizontal' self.layout = QtGui.QVBoxLayout() self.layout_boxes = [QtGui.QHBoxLayout() for i in range(max_column_index + 1)] self.button_groups = [QtGui.QGroupBox() for i in range(max_column_index + 1)] for button_data in yaml_data: # check if all the field is available if not button_data.has_key("name"): self.showError("name field is missed in yaml") raise Exception("name field is missed in yaml") if not button_data.has_key("service"): self.showError("service field is missed in yaml") raise Exception("service field is missed in yaml") if self.button_type == "push": button = QtGui.QToolButton() else: # self.button_type == "Radio": button = QtGui.QRadioButton() button.setSizePolicy(QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)) if button_data.has_key("image"): image_file = get_filename(button_data["image"])[len("file://"):] if os.path.exists(image_file): icon = QtGui.QIcon(image_file) button.setIcon(icon) if button_data.has_key("image_size"): button.setIconSize(QSize(button_data["image_size"][0], button_data["image_size"][1])) else: button.setIconSize(QSize(100, 100)) if button_data.has_key("name"): name = button_data['name'] button.setText(name) button.clicked.connect(self.buttonCallback(button_data['service'])) if self.button_type == "push": button.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon) else: # self.button_type == "Radio": if button_data.has_key("default_value") and button_data['default_value']: button.setChecked(True) self.layout_boxes[button_data['column']].addWidget(button) self.buttons.append(button) for i in range(len(self.button_groups)): self.button_groups[i].setLayout(self.layout_boxes[i]) for group in self.button_groups: self.layout.addWidget(group) self.setLayout(self.layout)
def init_ui(self): # type combobox ui_type_lable = QtGui.QLabel('Robot') ui_type_lable.setStyleSheet('QLabel {font: bold}') ui_type_lable.setMaximumWidth(70) # ui_type_lable.setFont(QtGui.QFont(QtGui.QFont.Bold)) ui_type_lable.setAlignment(QtCore.Qt.AlignCenter) self.ui_type = QtGui.QComboBox() self.ui_type.addItem('MTMR') self.ui_type.addItem('MTML') self.ui_type.addItem('PSM1') self.ui_type.addItem('PSM2') self.ui_type.addItem('PSM3') # self.ui_type.addItem('ECM') ui_hbox_type = QtGui.QHBoxLayout() ui_hbox_type.addWidget(ui_type_lable) ui_hbox_type.addWidget(self.ui_type) self.ui_type.currentIndexChanged.connect(self.slot_type_changed) # control mode # todo: use a for loop gbox = QtGui.QGridLayout() ui_btn_idle = QtGui.QPushButton('Idle') ui_btn_idle.setCheckable(True) ui_btn_idle.setChecked(True) gbox.addWidget(ui_btn_idle, 0, 0) ui_btn_idle.clicked[bool].connect(self.slot_btn_idle) ui_btn_home = QtGui.QPushButton('Home') ui_btn_home.setCheckable(True) gbox.addWidget(ui_btn_home, 0, 1) ui_btn_home.clicked[bool].connect(self.slot_btn_home) ui_btn_grav = QtGui.QPushButton('Gravity') ui_btn_grav.setCheckable(True) gbox.addWidget(ui_btn_grav, 1, 0) ui_btn_grav.clicked[bool].connect(self.slot_btn_grav) ui_btn_vfix = QtGui.QPushButton('Teleop') ui_btn_vfix.setCheckable(True) gbox.addWidget(ui_btn_vfix, 1, 1) ui_btn_vfix.clicked[bool].connect(self.slot_btn_teleop) ui_btn_group = QtGui.QButtonGroup(self._widget) ui_btn_group.addButton(ui_btn_idle) ui_btn_group.addButton(ui_btn_home) ui_btn_group.addButton(ui_btn_grav) ui_btn_group.addButton(ui_btn_vfix) ui_btn_group.setExclusive(True) # connect here self.ui_gbox_control = QtGui.QGroupBox('Control MTM') self.ui_gbox_control.setLayout(gbox) # ---- PSM Control Box ---- gbox = QtGui.QGridLayout() ui_btn_idle = QtGui.QPushButton('Idle') ui_btn_idle.setCheckable(True) ui_btn_idle.setChecked(True) gbox.addWidget(ui_btn_idle, 0, 0) ui_btn_idle.clicked[bool].connect(self.slot_btn_idle) ui_btn_home = QtGui.QPushButton('Home') ui_btn_home.setCheckable(True) gbox.addWidget(ui_btn_home, 0, 1) ui_btn_home.clicked[bool].connect(self.slot_btn_home) ui_btn_grav = QtGui.QPushButton('Teleop') ui_btn_grav.setCheckable(True) gbox.addWidget(ui_btn_grav, 1, 0) ui_btn_grav.clicked[bool].connect(self.slot_btn_teleop) ui_btn_vfix = QtGui.QPushButton('Manual') ui_btn_vfix.setCheckable(True) gbox.addWidget(ui_btn_vfix, 1, 1) ui_btn_vfix.clicked[bool].connect(self.slot_btn_manual) ui_btn_group = QtGui.QButtonGroup(self._widget) ui_btn_group.addButton(ui_btn_idle) ui_btn_group.addButton(ui_btn_home) ui_btn_group.addButton(ui_btn_grav) ui_btn_group.addButton(ui_btn_vfix) ui_btn_group.setExclusive(True) # connect here self.ui_gbox_control_psm = QtGui.QGroupBox('Control PSM') self.ui_gbox_control_psm.setLayout(gbox) self.ui_gbox_control_psm.setVisible(False) # ---- gripper box ----- ui_hbox_gripper = QtGui.QHBoxLayout() ui_gripper_label = QtGui.QLabel('Gripper Angle:') ui_hbox_gripper.addWidget(ui_gripper_label) ui_gbox_gripper = QtGui.QGroupBox('Gripper') ui_gbox_gripper.setLayout(ui_hbox_gripper) # ---- joint position group ----- jnt_pos_hbox = QtGui.QHBoxLayout() jp_widgets = [] jn_widgets = [] for i in range(7): pos_vbox = QtGui.QVBoxLayout() ui_ppos = QwtThermo() ui_ppos.setScalePosition(QwtThermo.NoScale) ui_ppos.setAutoFillBackground(True) ui_ppos.setAlarmLevel(0.8) ui_ppos.setPipeWidth(20) ui_ppos.setValue(0.0) ui_ppos.setMinimumSize(0, 40) ui_ppos.setRange(0.0, 1.0, False) ui_npos = QwtThermo() ui_npos.setScalePosition(QwtThermo.NoScale) ui_npos.setAlarmLevel(0.8) ui_npos.setPipeWidth(20) ui_npos.setValue(0.9) ui_npos.setMinimumSize(0, 40) ui_npos.setRange(1.0, 0.0, False) ui_npos.setValue(0.0) ui_label_jnt = QtGui.QLabel('J' + str(i)) pos_vbox.addWidget(ui_ppos) pos_vbox.addWidget(ui_npos) pos_vbox.addWidget(ui_label_jnt) jnt_pos_hbox.addLayout(pos_vbox) jp_widgets.append(ui_ppos) jn_widgets.append(ui_npos) # ui_btn_jnt_pos = QPushButton('J1') ui_gbox_jnt_pos = QtGui.QGroupBox('Joint Positions (normalized)') ui_gbox_jnt_pos.setLayout(jnt_pos_hbox) self.joint_widgets = zip(jp_widgets, jn_widgets) # joint torque group jnt_eff_hbox = QtGui.QHBoxLayout() tp_widgets = [] tn_widgets = [] for i in range(7): eff_vbox = QtGui.QVBoxLayout() ui_peff = QwtThermo() ui_peff.setScalePosition(QwtThermo.NoScale) ui_peff.setAutoFillBackground(True) ui_peff.setAlarmLevel(0.8) ui_peff.setPipeWidth(20) ui_peff.setValue(0.0) ui_peff.setMinimumSize(0, 30) ui_peff.setRange(0.0, 1.0, False) ui_neff = QwtThermo() ui_neff.setScalePosition(QwtThermo.NoScale) ui_neff.setAlarmLevel(0.8) ui_neff.setPipeWidth(20) ui_neff.setValue(0.9) ui_neff.setMinimumSize(0, 30) ui_neff.setRange(1.0, 0.0, False) ui_neff.setValue(0.0) ui_label_jnt = QtGui.QLabel('J' + str(i)) eff_vbox.addWidget(ui_peff) eff_vbox.addWidget(ui_neff) eff_vbox.addWidget(ui_label_jnt) jnt_eff_hbox.addLayout(eff_vbox) tp_widgets.append(ui_peff) tn_widgets.append(ui_neff) ui_gbox_jnt_eff = QtGui.QGroupBox('Joint Torques (normalized)') ui_gbox_jnt_eff.setLayout(jnt_eff_hbox) self.torque_widgets = zip(tp_widgets, tn_widgets) # make widgets colorful self.dvrk_green = QColor(87, 186, 142) self.dvrk_green_dark = self.dvrk_green.darker() self.dvrk_green_light = self.dvrk_green.lighter() self.dvrk_blue = QColor(80, 148, 204) self.dvrk_blue_dark = self.dvrk_blue.darker() self.dvrk_blue_light = self.dvrk_blue.lighter() self.dvrk_red = QColor(232, 47, 47) self.dvrk_red_dark = self.dvrk_red.darker() self.dvrk_red_light = self.dvrk_red.lighter() self.dvrk_orange = QColor(255, 103, 43) self.dvrk_orange_dark = self.dvrk_orange.darker() # joint_bg_color = self.dvrk_blue_dark.darker() joint_fill_color = self.dvrk_blue joint_alarm_color = self.dvrk_blue_light # self.dvrk_blue_light # torque_bg_color = self.dvrk_green_dark.darker() torque_fill_color = self.dvrk_green torque_alarm_color = self.dvrk_orange # self.dvrk_green_light for w in jp_widgets + jn_widgets: w.setAlarmLevel(0.80) w.setFillColor(joint_fill_color) w.setAlarmColor(joint_alarm_color) p = w.palette() # p.setColor(ui_ppos.backgroundRole(), joint_bg_color) w.setPalette(p) for w in tp_widgets + tn_widgets: w.setAlarmLevel(0.66) w.setFillColor(torque_fill_color) w.setAlarmColor(torque_alarm_color) p = w.palette() # p.setColor(ui_peff.backgroundRole(), torque_bg_color) w.setPalette(p) # main layout main_layout = QtGui.QVBoxLayout() main_layout.addLayout(ui_hbox_type) main_layout.addWidget(self.ui_gbox_control) main_layout.addWidget(self.ui_gbox_control_psm) main_layout.addWidget(ui_gbox_gripper) main_layout.addWidget(ui_gbox_jnt_pos) main_layout.addWidget(ui_gbox_jnt_eff) self._widget.setLayout(main_layout) pass