Example #1
0
    def __init__(self, parent=None, checkbox_labels=None):
        super().__init__(parent)

        checkbox_labels = list() if checkbox_labels is None else list(checkbox_labels)

        self._checkboxes = OrderedDict()
        self._checkbox_width = 30
        self._width_hint = self._checkbox_width * len(checkbox_labels)

        main_layout = QtGui.QHBoxLayout()
        for box_label in checkbox_labels:
            # Create QLabel and QCheckBox for each checkbox label given in init
            label = QtGui.QLabel(box_label)
            label.setFixedWidth(self._checkbox_width)
            label.setAlignment(QtCore.Qt.AlignCenter)
            widget = QtGui.QCheckBox()
            widget.setFixedWidth(19)
            widget.setChecked(False)
            self._checkboxes[box_label] = {'label': label, 'widget': widget}

            # Forward editingFinished signal of child widget
            widget.stateChanged.connect(self.stateChanged)

            # Arrange CheckBoxes and Labels in a layout
            v_layout = QtGui.QVBoxLayout()
            v_layout.addWidget(label)
            v_layout.addWidget(widget)
            v_layout.setAlignment(label, QtCore.Qt.AlignHCenter)
            v_layout.setAlignment(widget, QtCore.Qt.AlignHCenter)
            main_layout.addLayout(v_layout)
        main_layout.addStretch(1)
        main_layout.setSpacing(0)
        main_layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(main_layout)
    def __init__(self,
                 parent,
                 title="Language selection",
                 name="Language codes",
                 instruction="Click button when you are done"):
        super(LanguageSelector, self).__init__(
            None, QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowTitleHint)
        self.qm_files_choices = {}
        self.parent = parent
        qm_files = utils.find_qm_files()

        # ========= check boxes ==============
        group_box = QtGui.QGroupBox(name)
        group_box_layout = QtGui.QGridLayout()
        for i, locale in enumerate(qm_files):
            check_box = QtGui.QCheckBox(locale)
            check_box.setAutoExclusive(True)
            self.qm_files_choices[check_box] = locale
            check_box.toggled.connect(self.check_box_toggled)
            group_box_layout.addWidget(check_box, i / 4, i % 4)
        # adding default language option. When using the PyQt distribution
        # no "en" files were found and yet "en" was the obvious default.
        # We need this option in case we want to revert a change.
        check_box = QtGui.QCheckBox("default")
        check_box.setAutoExclusive(True)
        self.qm_files_choices[check_box] = "default"
        check_box.toggled.connect(self.check_box_toggled)
        i = len(qm_files)
        group_box_layout.addWidget(check_box, i / 4, i % 4)
        group_box.setLayout(group_box_layout)

        # ========= buttons ==============
        button_box = QtGui.QDialogButtonBox()
        confirm_button = button_box.addButton(QtGui.QDialogButtonBox.Ok)
        confirm_button.clicked.connect(self.confirm)

        # ========= finalizing layout ====
        main_layout = QtGui.QVBoxLayout()
        main_layout.addWidget(group_box)
        main_layout.addWidget(QtGui.QLabel(instruction))
        main_layout.addWidget(button_box)
        self.setLayout(main_layout)
        self.setWindowTitle(title)
        self.show()
        self.raise_()
Example #3
0
    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)
Example #4
0
    def __init__(self, parent=None, digital_channels=None):
        super().__init__(parent)

        if digital_channels is None:
            self._digital_channels = list()
        else:
            self._digital_channels = digital_channels

        self._dch_checkboxes = OrderedDict()
        self._width_hint = 30 * len(self._digital_channels)

        main_layout = QtGui.QHBoxLayout()
        for chnl in self._digital_channels:
            # Create QLabel and QCheckBox for each digital channel
            label = QtGui.QLabel(chnl.rsplit('ch')[1])
            label.setFixedWidth(30)
            label.setAlignment(QtCore.Qt.AlignCenter)
            widget = QtGui.QCheckBox()
            widget.setFixedWidth(19)
            widget.setChecked(False)
            self._dch_checkboxes[chnl] = {'label': label, 'widget': widget}

            # Forward editingFinished signal of child widget
            widget.stateChanged.connect(self.stateChanged)

            # Arrange CheckBoxes and Labels in a layout
            v_layout = QtGui.QVBoxLayout()
            v_layout.addWidget(label)
            v_layout.addWidget(widget)
            v_layout.setAlignment(label, QtCore.Qt.AlignHCenter)
            v_layout.setAlignment(widget, QtCore.Qt.AlignHCenter)
            main_layout.addLayout(v_layout)
        main_layout.addStretch(1)
        main_layout.setSpacing(0)
        main_layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(main_layout)
Example #5
0
    def __init__(self, data, win_parent=None):
        """
        +--------+
        | BC Map |
        +--------+---------------+
        |  Origin                |
        |     X       Y      Z   |
        |                        |
        |  Normal                |
        |    NX      NY     NZ   |
        |                        |
        |  Apply Normal          |
        |    NX      NY     NZ   |
        |                        |
        |    Apply   OK  Cancel  |
        +--------+---------------+
        """
        QtGui.QDialog.__init__(self, win_parent)

        self._default_name = 'Plane'
        self.out_data = data
        self._axis = '?'
        self._plane = '?'

        ox_value, oy_value, oz_value = self.out_data['origin']
        nx_value, ny_value, nz_value = self.out_data['normal']
        ax_value, ay_value, az_value = self.out_data['a']
        bx_value, by_value, bz_value = self.out_data['b']

        self._origin_x_default = ox_value
        self._origin_y_default = oy_value
        self._origin_z_default = oz_value

        self._normal_x_default = nx_value
        self._normal_y_default = ny_value
        self._normal_z_default = nz_value

        self._ax_default = ax_value
        self._ay_default = ay_value
        self._az_default = az_value

        self._bx_default = bx_value
        self._by_default = by_value
        self._bz_default = bz_value

        self._default_is_apply = True

        self.name = QtGui.QLabel("Title:")
        self.name_edit = QtGui.QLineEdit(str(self._default_name))
        self.name_button = QtGui.QPushButton("Default")

        self.axis = QtGui.QLabel("Point on ? Axis:")
        self.combo_axis = QtGui.QComboBox(self)
        self.combo_axis.addItem("X")
        self.combo_axis.addItem("Y")
        self.combo_axis.addItem("Z")

        self.plane = QtGui.QLabel("Point on %s? Plane:" % self._axis)
        self.combo_plane = QtGui.QComboBox(self)
        self.combo_plane.addItem("X")
        self.combo_plane.addItem("Y")
        self.combo_plane.addItem("Z")

        self.origin = QtGui.QLabel("Origin:")
        self.origin_x_edit = QtGui.QLineEdit(str(self._origin_x_default))
        self.origin_y_edit = QtGui.QLineEdit(str(self._origin_y_default))
        self.origin_z_edit = QtGui.QLineEdit(str(self._origin_z_default))
        self.origin_default_button = QtGui.QPushButton("Default")
        #self.name_button = QtGui.QPushButton("Default")

        self.normal = QtGui.QLabel("Normal:")
        self.normal_x_edit = QtGui.QLineEdit(str(self._normal_x_default))
        self.normal_y_edit = QtGui.QLineEdit(str(self._normal_y_default))
        self.normal_z_edit = QtGui.QLineEdit(str(self._normal_z_default))
        self.normal_default_button = QtGui.QPushButton("Default")

        self.snap = QtGui.QLabel("Snap Normal:")
        self.snap_normal_xy_button = QtGui.QPushButton("XY Plane")
        self.snap_normal_yz_button = QtGui.QPushButton("YZ Plane")
        self.snap_normal_xz_button = QtGui.QPushButton("XZ Plane")

        self.point_a = QtGui.QLabel("Point on %s Axis:" % self._axis)
        self.ax_edit = QtGui.QLineEdit(str(self._ax_default))
        self.ay_edit = QtGui.QLineEdit(str(self._ay_default))
        self.az_edit = QtGui.QLineEdit(str(self._az_default))

        self.point_b = QtGui.QLabel("Point on %s%s Plane:" %
                                    (self._axis, self._plane))
        self.bx_edit = QtGui.QLineEdit(str(self._bx_default))
        self.by_edit = QtGui.QLineEdit(str(self._by_default))
        self.bz_edit = QtGui.QLineEdit(str(self._bz_default))

        self.check_apply = QtGui.QCheckBox("Automatically apply results")
        self.check_apply.setChecked(self._default_is_apply)

        # closing
        self.apply_button = QtGui.QPushButton("Apply")
        if self._default_is_apply:
            self.apply_button.setDisabled(True)

        self.ok_button = QtGui.QPushButton("OK")
        self.cancel_button = QtGui.QPushButton("Cancel")
        self.create_layout()
        self.set_connections()
Example #6
0
    def __init__(self, parent=None, parameters_dict=None):
        super().__init__(parent)
        if parameters_dict is None:
            self._parameters = OrderedDict()
        else:
            self._parameters = parameters_dict

        self._width_hint = 90 * len(self._parameters)
        self._ach_widgets = OrderedDict()

        main_layout = QtGui.QHBoxLayout()
        for param in self._parameters:
            label = QtGui.QLabel(param)
            label.setAlignment(QtCore.Qt.AlignCenter)
            if self._parameters[param]['type'] == float:
                widget = ScienDSpinBox()
                widget.setMinimum(self._parameters[param]['min'])
                widget.setMaximum(self._parameters[param]['max'])
                widget.setDecimals(6, False)
                widget.setValue(self._parameters[param]['init'])
                widget.setSuffix(self._parameters[param]['unit'])
                # Set size constraints
                widget.setFixedWidth(90)
                # Forward editingFinished signal of child widget
                widget.editingFinished.connect(self.editingFinished)
            elif self._parameters[param]['type'] == int:
                widget = ScienSpinBox()
                widget.setValue(self._parameters[param]['init'])
                widget.setMinimum(self._parameters[param]['min'])
                widget.setMaximum(self._parameters[param]['max'])
                widget.setSuffix(self._parameters[param]['unit'])
                # Set size constraints
                widget.setFixedWidth(90)
                # Forward editingFinished signal of child widget
                widget.editingFinished.connect(self.editingFinished)
            elif self._parameters[param]['type'] == str:
                widget = QtGui.QLineEdit()
                widget.setText(self._parameters[param]['init'])
                # Set size constraints
                widget.setFixedWidth(90)
                # Forward editingFinished signal of child widget
                widget.editingFinished.connect(self.editingFinished)
            elif self._parameters[param]['type'] == bool:
                widget = QtGui.QCheckBox()
                widget.setChecked(self._parameters[param]['init'])
                # Set size constraints
                widget.setFixedWidth(90)
                # Forward editingFinished signal of child widget
                widget.stateChanged.connect(self.editingFinished)
            elif issubclass(self._parameters[param]['type'], Enum):
                widget = QtGui.QComboBox()
                for option in self._parameters[param]['type']:
                    widget.addItem(option.name, option)
                widget.setCurrentText(self._parameters[param]['init'].name)
                # Set size constraints
                widget.setFixedWidth(90)
                # Forward editingFinished signal of child widget
                widget.currentIndexChanged.connect(self.editingFinished)

            self._ach_widgets[param] = {'label': label, 'widget': widget}

            v_layout = QtGui.QVBoxLayout()
            v_layout.addWidget(label)
            v_layout.addWidget(widget)
            v_layout.setAlignment(label, QtCore.Qt.AlignHCenter)
            v_layout.setAlignment(widget, QtCore.Qt.AlignHCenter)
            main_layout.addLayout(v_layout)

        main_layout.addStretch(1)
        main_layout.setSpacing(0)
        main_layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(main_layout)
Example #7
0
    def __init__(self, data, win_parent=None):
        """
        +-----------------+
        | Break Surfaces  |
        +-----------------+------+
        |  EngineInlet           |
        |  EngineOutlet          |
        |                        |
        |  Name      EngineInlet |
        |  RegionMode * RegionID |
        |             * All      |
        |                        |
        |  AllowedRegions:       |
        |    Region ID      3    |
        |                        |
        |  PickMode  * All       |
        |  Pick Mode  x On/Off   |
        |  Pick Angle   20 deg   |
        |                        |
        |         Revert         |
        |     RenumberRegions    |
        |         Close          |
        +------------------------+
        """
        QtGui.QDialog.__init__(self, win_parent)
        self.setWindowTitle('Break Surface')

        #default
        self.win_parent = win_parent
        self.out_data = data

        self.points = data['points']

        self.keys = sorted(self.points.keys())
        keys = self.keys
        nrows = len(keys)

        active_point = data['active_point']
        #self.active_key = keys[0]
        self.active_key = active_point
        name = self.active_key
        description = self.points[self.active_key][0]

        self._use_old_table = False
        items = ['Node %i' % val for val in keys]
        header_labels = ['Nodes']
        table_model = Model(items, header_labels, self)
        view = SingleChoiceQTableView(self)  #Call your custom QTableView here
        view.setModel(table_model)
        view.horizontalHeader().setResizeMode(QtGui.QHeaderView.Stretch)
        self.table = view

        #self.representation = actor_obj.representation
        #print('rep =', self.representation)

        table = self.table
        #headers = [QtCore.QString('Groups')]

        header = table.horizontalHeader()
        header.setStretchLastSection(True)

        #----------------------------------------------
        #self._default_is_apply = False

        self.mode_header = QtGui.QLabel("Mode:")

        nregions_max = 10
        pick_angle = 20.0
        region_id = 4
        all_regions = True
        self.region_id = QtGui.QLabel("Region ID:")
        self.region_id_edit = QtGui.QSpinBox(self)
        self.region_id_edit.setRange(1, nregions_max)
        self.region_id_edit.setSingleStep(1)
        self.region_id_edit.setValue(region_id)

        self.pick_angle = QtGui.QLabel("Pick Angle:")
        self.pick_angle_edit = QtGui.QDoubleSpinBox(self)
        self.pick_angle_edit.setRange(0.0, 360.0)
        self.pick_angle_edit.setDecimals(3)
        self.pick_angle_edit.setSingleStep(0.5)
        self.pick_angle_edit.setValue(pick_angle)

        # region IDs/all
        self.checkbox_region_ids = QtGui.QCheckBox("Region IDs")
        self.checkbox_region_all = QtGui.QCheckBox("All Regions")
        self.checkbox_region_all.setChecked(all_regions)
        self.checkbox_region_ids.setChecked(not all_regions)

        # pick mode
        self.checkbox_pick_mode = QtGui.QCheckBox("Pick Mode  (Off=label)")
        self.checkbox_pick_mode.setChecked(False)

        #----------------------------------------------
        self.nodes_header = QtGui.QLabel("Single Node:")
        self.name = QtGui.QLabel("ID:")
        self.name_edit = QtGui.QLineEdit('Node %i' % name)
        self.name_edit.setDisabled(True)

        #----------------------------------------------

        # closing
        #if self._default_is_apply:
        #self.apply_button.setDisabled(True)

        self.close_button = QtGui.QPushButton("Close")

        self.create_layout()
Example #8
0
    def populate_gui(self):
        _contain_parsed = self.contain_parsed
        for _row, _entry in enumerate(_contain_parsed):

            if _entry == ['']:
                continue

            self.parent.ui.table.insertRow(_row)

            #select
            _layout = QtGui.QHBoxLayout()
            _widget = QtGui.QCheckBox()
            _widget.setEnabled(True)
            _layout.addWidget(_widget)
            _layout.addStretch()
            _new_widget = QtGui.QWidget()
            _new_widget.setLayout(_layout)

            #if _entry[0] == "True":
            #   _widget.setChecked(True)
            _widget.stateChanged.connect(
                lambda state=0, row=_row: self.parent.
                table_select_state_changed(state, row))
            self.parent.ui.table.setCellWidget(_row, 0, _new_widget)

            #name
            _item = QtGui.QTableWidgetItem(_entry[1])
            self.parent.ui.table.setItem(_row, 1, _item)

            #runs
            _item = QtGui.QTableWidgetItem(_entry[2])
            self.parent.ui.table.setItem(_row, 2, _item)

            #Sample formula
            if _entry[3]:
                _item = QtGui.QTableWidgetItem(_entry[3])
            else:
                _item = QtGui.QTableWidgetItem("")
            self.parent.ui.table.setItem(_row, 3, _item)

            #mass density
            if _entry[4]:
                _item = QtGui.QTableWidgetItem(_entry[4])
            else:
                _item = QtGui.QTableWidgetItem("")
            self.parent.ui.table.setItem(_row, 4, _item)

            #radius
            if _entry[5]:
                _item = QtGui.QTableWidgetItem(_entry[5])
            else:
                _item = QtGui.QTableWidgetItem("")
            self.parent.ui.table.setItem(_row, 5, _item)

            #packing fraction
            if _entry[6]:
                _item = QtGui.QTableWidgetItem(_entry[6])
            else:
                _item = QtGui.QTableWidgetItem("")
            self.parent.ui.table.setItem(_row, 6, _item)

            #sample shape
            _widget = QtGui.QComboBox()
            _widget.addItem("Cylinder")
            _widget.addItem("Sphere")
            if _entry[7] == "Sphere":
                _widget.setCurrentIndex(1)
            self.parent.ui.table.setCellWidget(_row, 7, _widget)

            #do abs corr
            _layout = QtGui.QHBoxLayout()
            _widget = QtGui.QCheckBox()
            if _entry[8] == "True":
                _widget.setCheckState(QtCore.Qt.Checked)
            _widget.setStyleSheet("border:  2px; solid-black")
            _widget.setEnabled(True)
            _layout.addStretch()
            _layout.addWidget(_widget)
            _layout.addStretch()
            _new_widget = QtGui.QWidget()
            _new_widget.setLayout(_layout)
            self.parent.ui.table.setCellWidget(_row, 8, _new_widget)

        for _row, _entry in enumerate(_contain_parsed):

            if _entry == ['']:
                continue

            #select
            _widget = self.parent.ui.table.cellWidget(_row, 0).children()[1]
            if _entry[0] == "True":
                _widget.setChecked(True)
Example #9
0
    def export(self):
        """ Displays a dialog for exporting HTML generated by Qt's rich text
        system.

        Returns
        -------
        The name of the file that was saved, or None if no file was saved.
        """
        parent = self.control.window()
        dialog = QtWidgets.QFileDialog(parent, 'Save as...')
        dialog.setAcceptMode(QtWidgets.QFileDialog.AcceptSave)
        filters = [
            'HTML with PNG figures (*.html *.htm)',
            'XHTML with inline SVG figures (*.xhtml *.xml)'
        ]
        dialog.setNameFilters(filters)
        if self.filename:
            dialog.selectFile(self.filename)
            root, ext = os.path.splitext(self.filename)
            if ext.lower() in ('.xml', '.xhtml'):
                dialog.selectNameFilter(filters[-1])

        if dialog.exec_():
            self.filename = dialog.selectedFiles()[0]
            choice = dialog.selectedNameFilter()
            html = py3compat.cast_unicode(self.control.document().toHtml())

            # Configure the exporter.
            if choice.startswith('XHTML'):
                exporter = export_xhtml
            else:
                # If there are PNGs, decide how to export them.
                inline = self.inline_png
                if inline is None and IMG_RE.search(html):
                    dialog = QtGui.QDialog(parent)
                    dialog.setWindowTitle('Save as...')
                    layout = QtGui.QVBoxLayout(dialog)
                    msg = "Exporting HTML with PNGs"
                    info = "Would you like inline PNGs (single large html " \
                        "file) or external image files?"
                    checkbox = QtGui.QCheckBox("&Don't ask again")
                    checkbox.setShortcut('D')
                    ib = QtWidgets.QPushButton("&Inline")
                    ib.setShortcut('I')
                    eb = QtWidgets.QPushButton("&External")
                    eb.setShortcut('E')
                    box = QtWidgets.QMessageBox(QtWidgets.QMessageBox.Question,
                                                dialog.windowTitle(), msg)
                    box.setInformativeText(info)
                    box.addButton(ib, QtWidgets.QMessageBox.NoRole)
                    box.addButton(eb, QtWidgets.QMessageBox.YesRole)
                    layout.setSpacing(0)
                    layout.addWidget(box)
                    layout.addWidget(checkbox)
                    dialog.setLayout(layout)
                    dialog.show()
                    reply = box.exec_()
                    dialog.hide()
                    inline = (reply == 0)
                    if checkbox.checkState():
                        # Don't ask anymore; always use this choice.
                        self.inline_png = inline
                exporter = lambda h, f, i: export_html(h, f, i, inline)

            # Perform the export!
            try:
                return exporter(html, self.filename, self.image_tag)
            except Exception as e:
                msg = "Error exporting HTML to %s\n" % self.filename + str(e)
                reply = QtWidgets.QMessageBox.warning(parent, 'Error', msg,
                                                      QtWidgets.QMessageBox.Ok,
                                                      QtWidgets.QMessageBox.Ok)

        return None