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)