Example #1
0
 def __init__(self, parent=None):
     super().__init__(parent=parent)
     self.setTitle("Select peak")
     layout = QFormLayout()
     layout.setFieldGrowthPolicy(0)
     self.peak_select = QComboBox()
     layout.addRow(QLabel("Peak"), self.peak_select)
     self.setLayout(layout)
Example #2
0
 def __init__(self, parent=None):
     super().__init__(parent)
     layout = QFormLayout()
     layout.setFieldGrowthPolicy(0)
     self.plot_param = QComboBox()
     self.plot_param.addItems([
         "dspacing-center", "d-reference", "Center", "Height", "FWHM",
         "Mixing", "Intensity", "strain", "stress"
     ])
     self.plot_param.setCurrentIndex(self.plot_param.findText('strain'))
     layout.addRow(QLabel("Plot"), self.plot_param)
     self.measure_dir = QComboBox()
     self.measure_dir.addItems(["11", "22", "33"])
     layout.addRow(QLabel("Measurement Direction "), self.measure_dir)
     self.setLayout(layout)
Example #3
0
    def __init__(self, parent=None, is_report=False):
        QDialog.__init__(self, parent)
        self.is_report = is_report
        self.setWindowTitle(_("Issue reporter"))

        # To save the traceback sent to the internal console
        self.error_traceback = ""

        # Dialog main label
        if self.is_report:
            title = _("Please fill the following information")
        else:
            title = _("Spyder has encountered an internal problem!")
        main_label = QLabel(
            _("<h3>{title}</h3>"
              "Before reporting this problem, <i>please</i> consult our "
              "comprehensive "
              "<b><a href=\"{trouble_url}\">Troubleshooting Guide</a></b> "
              "which should help solve most issues, and search for "
              "<b><a href=\"{project_url}\">known bugs</a></b> "
              "matching your error message or problem description for a "
              "quicker solution.").format(title=title,
                                          trouble_url=__trouble_url__,
                                          project_url=__project_url__))
        main_label.setOpenExternalLinks(True)
        main_label.setWordWrap(True)
        main_label.setAlignment(Qt.AlignJustify)
        main_label.setStyleSheet('font-size: 12px;')

        # Issue title
        self.title = QLineEdit()
        self.title.textChanged.connect(self._contents_changed)
        self.title_chars_label = QLabel(
            _("{} more characters "
              "to go...").format(TITLE_MIN_CHARS))
        form_layout = QFormLayout()
        form_layout.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow)
        red_asterisk = '<font color="Red">*</font>'
        title_label = QLabel(_("<b>Title</b>: {}").format(red_asterisk))
        form_layout.setWidget(0, QFormLayout.LabelRole, title_label)
        form_layout.setWidget(0, QFormLayout.FieldRole, self.title)

        # Description
        steps_header = QLabel(
            _("<b>Steps to reproduce:</b> {}").format(red_asterisk))
        steps_text = QLabel(
            _("Please enter a detailed step-by-step "
              "description (in English) of what led up to "
              "the problem below. Issue reports without a "
              "clear way to reproduce them will be closed."))
        steps_text.setWordWrap(True)
        steps_text.setAlignment(Qt.AlignJustify)
        steps_text.setStyleSheet('font-size: 12px;')

        # Field to input the description of the problem
        self.input_description = DescriptionWidget(self)

        # Only allow to submit to Github if we have a long enough description
        self.input_description.textChanged.connect(self._contents_changed)

        # Widget to show errors
        self.details = ShowErrorWidget(self)
        self.details.set_pythonshell_font(get_font())
        self.details.hide()

        # Label to show missing chars
        self.initial_chars = len(self.input_description.toPlainText())
        self.desc_chars_label = QLabel(
            _("{} more characters "
              "to go...").format(DESC_MIN_CHARS))

        # Checkbox to dismiss future errors
        self.dismiss_box = QCheckBox(
            _("Hide all future errors during this "
              "session"))
        if self.is_report:
            self.dismiss_box.hide()

        # Dialog buttons
        gh_icon = ima.icon('github')
        self.submit_btn = QPushButton(gh_icon, _('Submit to Github'))
        self.submit_btn.setEnabled(False)
        self.submit_btn.clicked.connect(self._submit_to_github)

        self.details_btn = QPushButton(_('Show details'))
        self.details_btn.clicked.connect(self._show_details)
        if self.is_report:
            self.details_btn.hide()

        self.close_btn = QPushButton(_('Close'))
        if self.is_report:
            self.close_btn.clicked.connect(self.reject)

        # Buttons layout
        buttons_layout = QHBoxLayout()
        buttons_layout.addWidget(self.submit_btn)
        buttons_layout.addWidget(self.details_btn)
        buttons_layout.addWidget(self.close_btn)

        # Main layout
        layout = QVBoxLayout()
        layout.addWidget(main_label)
        layout.addSpacing(20)
        layout.addLayout(form_layout)
        layout.addWidget(self.title_chars_label)
        layout.addSpacing(12)
        layout.addWidget(steps_header)
        layout.addSpacing(-1)
        layout.addWidget(steps_text)
        layout.addSpacing(1)
        layout.addWidget(self.input_description)
        layout.addWidget(self.details)
        layout.addWidget(self.desc_chars_label)
        layout.addSpacing(15)
        layout.addWidget(self.dismiss_box)
        layout.addSpacing(15)
        layout.addLayout(buttons_layout)
        layout.setContentsMargins(25, 20, 25, 10)
        self.setLayout(layout)

        self.resize(570, 600)
        self.title.setFocus()

        # Set Tab key focus order
        self.setTabOrder(self.title, self.input_description)
Example #4
0
    def setupUI(self):
        width, height = self.determine_dialog_dimensions()

        self.setFixedSize(width, height)
        self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        self.setWindowTitle("About Mantid Workbench")
        self.setStyleSheet(f"""QDialog {{
    background-color: rgb(190, 230, 190);
}}
QLabel{{
    font: {self.rescale_w(14)}px;
}}
QPushButton{{
    font: {self.rescale_w(14)}px;
}}
QCommandLinkButton{{
    font: {self.rescale_w(22)}px;
    background-color: rgba(255, 255, 255, 0);
    border-radius: {self.rescale_w(15)}px;
}}
QCommandLinkButton:hover {{
    background-color: rgba(45, 105, 45, 40);
}}""")

        # version label section at th etop
        parent_layout = QVBoxLayout()
        parent_layout.addSpacerItem(
            QSpacerItem(self.rescale_w(20),
                        self.rescale_h(70),
                        vPolicy=QSizePolicy.Fixed))
        self.lbl_version.setText("version ")
        self.lbl_version.setIndent(self.rescale_w(115))
        self.lbl_version.setStyleSheet(f"""color: rgb(215, 215, 215);
font: {self.rescale_w(28)}pt;
font-weight: bold;
font-size: {self.rescale_w(28)}px""")
        parent_layout.addWidget(self.lbl_version)
        parent_layout.addSpacerItem(
            QSpacerItem(self.rescale_w(20),
                        self.rescale_h(40),
                        vPolicy=QSizePolicy.MinimumExpanding))

        # split into the two columns
        two_box_layout = QHBoxLayout()
        # left side Welcome and Tutorial
        left_layout = QVBoxLayout()
        left_layout.setContentsMargins(self.rescale_w(5), 0,
                                       self.rescale_w(10), 0)
        left_layout.setSpacing(0)
        # welcome label
        lbl_welcome = QLabel()
        lbl_welcome.setStyleSheet(
            f"color: rgb(45, 105, 45); font-size: {self.rescale_w(28)}px;")
        lbl_welcome.setText("Welcome")
        left_layout.addWidget(lbl_welcome)
        # release notes
        self.setup_command_link_button(
            self.clb_release_notes, "Release Notes",
            ':/images/Notepad-Bloc-notes-icon-48x48.png')
        left_layout.addWidget(self.clb_release_notes)
        # sample datasets
        self.setup_command_link_button(self.clb_sample_datasets,
                                       "Sample Datasets",
                                       ':/images/download-icon-48x48.png')
        left_layout.addWidget(self.clb_sample_datasets)
        # Tutorials Label
        lbl_tutorials = QLabel()
        lbl_tutorials.setStyleSheet(
            f"color: rgb(45, 105, 45); font-size: {self.rescale_w(28)}px;")
        lbl_tutorials.setText("Tutorials")
        left_layout.addWidget(lbl_tutorials)
        # Mantid Introduction
        self.setup_command_link_button(
            self.clb_mantid_introduction, "Mantid Introduction",
            ':/images/Misc-Tutorial-icon-48x48.png')
        left_layout.addWidget(self.clb_mantid_introduction)
        # Introduction to python
        self.setup_command_link_button(self.clb_python_introduction,
                                       "Introduction to Python",
                                       ':/images/Python-icon-48x48.png')
        left_layout.addWidget(self.clb_python_introduction)
        # Python in Mantid
        self.setup_command_link_button(self.clb_python_in_mantid,
                                       "Python In Mantid",
                                       ':/images/Circle_cog_48x48.png')
        left_layout.addWidget(self.clb_python_in_mantid)
        # Extending Mantid with python
        self.setup_command_link_button(
            self.clb_extending_mantid, "Extending Mantid with Python",
            ':/images/Plugin-Python-icon-48x48.png')
        left_layout.addWidget(self.clb_extending_mantid)

        # right hand side Setup and facility icons
        right_layout = QVBoxLayout()
        right_layout.setSpacing(0)
        # personal setup
        grp_personal_setup = QGroupBox()
        grp_personal_setup.setStyleSheet(f"""QGroupBox {{
     border: {self.rescale_w(3)}px solid  rgb(38, 128, 20);;
     border-radius: {self.rescale_w(10)}px;
     background-color: rgb(240, 240, 240);
}}
QGroupBox QLabel{{
    font: {self.rescale_w(12)}px;
    color: rgb(121, 121, 121);
}}
QGroupBox QComboBox{{
    font: {self.rescale_w(12)}px;
}}
font: {self.rescale_w(12)}px;
""")
        grp_personal_setup_layout = QVBoxLayout()
        grp_personal_setup_layout.setContentsMargins(self.rescale_w(9),
                                                     self.rescale_h(1),
                                                     self.rescale_w(9),
                                                     self.rescale_h(9))
        grp_personal_setup_layout.setSpacing(0)
        grp_personal_setup.setLayout(grp_personal_setup_layout)
        lbl_personal_setup = QLabel()
        lbl_personal_setup.setStyleSheet(
            f"color: rgb(38, 128, 20);\nfont-size: {self.rescale_w(18)}px;")
        lbl_personal_setup.setText("Personal Setup")
        lbl_personal_setup.setAlignment(Qt.AlignHCenter)
        grp_personal_setup_layout.addWidget(lbl_personal_setup)
        personal_setup_form_layout = QFormLayout()
        personal_setup_form_layout.setFieldGrowthPolicy(
            QFormLayout.AllNonFixedFieldsGrow)
        personal_setup_form_layout.setHorizontalSpacing(self.rescale_w(5))
        personal_setup_form_layout.setVerticalSpacing(self.rescale_h(5))
        personal_setup_form_layout.setLabelAlignment(Qt.AlignRight)
        # default Facility
        lbl_default_facilty = QLabel()
        lbl_default_facilty.setText("Default Facility")
        personal_setup_form_layout.addRow(lbl_default_facilty,
                                          self.cb_facility)
        # default instrument
        lbl_default_instrument = QLabel()
        lbl_default_instrument.setText("Default Instrument")
        personal_setup_form_layout.addRow(lbl_default_instrument,
                                          self.cb_instrument)
        # Set Data Directories
        lbl_mud = QLabel()
        lbl_mud.setText("Set data directories")
        self.pb_manage_user_directories.setText("Manage User Directories")
        personal_setup_form_layout.addRow(lbl_mud,
                                          self.pb_manage_user_directories)
        # Usage data
        lbl_allow_usage_data = QLabel()
        lbl_allow_usage_data.setText("Report Usage Data")
        usagelayout = QHBoxLayout()
        usagelayout.setContentsMargins(0, 0, 0, 0)
        self.chk_allow_usage_data.setChecked(True)
        self.chk_allow_usage_data.setStyleSheet(
            f"padding: {self.rescale_w(4)}px;")
        usagelayout.addWidget(self.chk_allow_usage_data)
        usagelayout.addSpacerItem(
            QSpacerItem(self.rescale_w(40),
                        self.rescale_h(20),
                        hPolicy=QSizePolicy.Expanding))
        self.lbl_privacy_policy.setText(
            r'<html><head/><body><p>'
            r'<a href="https://www.mantidproject.org/MantidProject:Privacy_policy'
            r'#Usage_Data_recorded_in_Mantid">'
            r'<span style=" text-decoration: underline; color:#0000ff;">'
            r'Privacy Policy</span></a></p></body></html>')
        self.lbl_privacy_policy.setOpenExternalLinks(False)
        usagelayout.addWidget(self.lbl_privacy_policy)
        personal_setup_form_layout.addRow(lbl_allow_usage_data, usagelayout)
        grp_personal_setup_layout.addLayout(personal_setup_form_layout)
        right_layout.addWidget(grp_personal_setup)
        right_layout.addSpacerItem(
            QSpacerItem(self.rescale_w(20),
                        self.rescale_h(40),
                        vPolicy=QSizePolicy.Expanding))

        # facility icons
        # Row one
        icon_layout_top = QHBoxLayout()
        icon_layout_top.setContentsMargins(0, self.rescale_h(10), 0, 0)
        icon_layout_top.setSpacing(0)
        icon_layout_top.addWidget(
            self.create_label_with_image(112, 50,
                                         ':/images/ISIS_Logo_Transparent.gif'))
        icon_layout_top.addSpacerItem(
            QSpacerItem(self.rescale_w(10),
                        self.rescale_h(20),
                        hPolicy=QSizePolicy.Fixed))
        icon_layout_top.addWidget(
            self.create_label_with_image(
                94, 50, ':/images/ess_logo_transparent_small.png'))
        icon_layout_top.addSpacerItem(
            QSpacerItem(self.rescale_w(40), 20, hPolicy=QSizePolicy.Expanding))
        right_layout.addLayout(icon_layout_top)
        # Row two
        icon_layout_middle = QHBoxLayout()
        icon_layout_middle.setContentsMargins(0, self.rescale_h(10), 0, 0)
        icon_layout_middle.setSpacing(0)
        icon_layout_middle.addWidget(
            self.create_label_with_image(
                200, 30, ':/images/Ornl_hfir_sns_logo_small.png'))
        icon_layout_middle.addSpacerItem(
            QSpacerItem(self.rescale_w(40),
                        self.rescale_h(20),
                        hPolicy=QSizePolicy.Expanding))
        right_layout.addLayout(icon_layout_middle)
        # Row three
        icon_layout_bottom = QHBoxLayout()
        icon_layout_bottom.setContentsMargins(0, self.rescale_h(10), 0, 0)
        icon_layout_bottom.setSpacing(0)
        icon_layout_bottom.addWidget(
            self.create_label_with_image(
                110, 40, ':/images/Tessella_Logo_Transparent.gif'))
        icon_layout_bottom.addSpacerItem(
            QSpacerItem(self.rescale_w(10),
                        self.rescale_h(20),
                        hPolicy=QSizePolicy.Fixed))
        icon_layout_bottom.addWidget(
            self.create_label_with_image(50, 50, ':/images/ILL_logo.png'))
        icon_layout_bottom.addSpacerItem(
            QSpacerItem(self.rescale_w(10),
                        self.rescale_h(20),
                        hPolicy=QSizePolicy.Fixed))
        icon_layout_bottom.addWidget(
            self.create_label_with_image(92, 50,
                                         ':/images/CSNS_Logo_Short.png'))
        icon_layout_bottom.addSpacerItem(
            QSpacerItem(self.rescale_w(40),
                        self.rescale_h(20),
                        hPolicy=QSizePolicy.Expanding))
        right_layout.addLayout(icon_layout_bottom)

        # end the two box layout
        two_box_layout.addLayout(left_layout)
        two_box_layout.addLayout(right_layout)
        parent_layout.addLayout(two_box_layout)

        # footer
        footer_layout = QHBoxLayout()
        # do not show again
        do_not_show_layout = QVBoxLayout()
        do_not_show_layout.setContentsMargins(self.rescale_w(15), 0, 0, 0)
        do_not_show_layout.setSpacing(self.rescale_w(2))
        do_not_show_layout.addSpacerItem(
            QSpacerItem(1, self.rescale_h(1), vPolicy=QSizePolicy.Expanding))
        lbl_update = QLabel()
        lbl_update.setMinimumSize(self.rescale_w(400), 0)
        lbl_update.setStyleSheet("color: rgb(25,125,25);")
        lbl_update.setText(
            'You can revisit this dialog by selecting "About" on the Help menu.'
        )
        lbl_update.setAlignment(Qt.AlignBottom)
        do_not_show_layout.addWidget(lbl_update)

        do_not_show_checkbox_layout = QHBoxLayout()
        self.chk_do_not_show_until_next_release.setChecked(True)
        do_not_show_checkbox_layout.addWidget(
            self.chk_do_not_show_until_next_release)
        do_not_show_checkbox_layout.addSpacerItem(
            QSpacerItem(self.rescale_w(10),
                        self.rescale_h(2),
                        hPolicy=QSizePolicy.Fixed))
        lbl_do_not_show = QLabel()
        lbl_do_not_show.setStyleSheet("color: rgb(25,125,25);")
        lbl_do_not_show.setText('Do not show again until next release')
        do_not_show_checkbox_layout.addWidget(lbl_do_not_show)
        do_not_show_checkbox_layout.addSpacerItem(
            QSpacerItem(self.rescale_w(40), 10, hPolicy=QSizePolicy.Expanding))
        do_not_show_layout.addLayout(do_not_show_checkbox_layout)
        footer_layout.addLayout(do_not_show_layout)

        # Close button
        close_button_layout = QVBoxLayout()
        close_button_layout.addSpacerItem(
            QSpacerItem(20, self.rescale_h(15), vPolicy=QSizePolicy.Expanding))
        self.pb_close.setText("Close")
        self.pb_close.setDefault(True)
        close_button_layout.addWidget(self.pb_close)
        footer_layout.addLayout(close_button_layout)
        footer_layout.addSpacerItem(
            QSpacerItem(self.rescale_w(100),
                        self.rescale_h(20),
                        hPolicy=QSizePolicy.Fixed))
        parent_layout.addLayout(footer_layout)
        self.setLayout(parent_layout)

        self.setAttribute(Qt.WA_DeleteOnClose, True)
Example #5
0
    def __init__(self, session, parent=None):
        super(SpecVizViewer, self).__init__(session, parent=parent)

        # Connect the dataview to the specviz messaging system
        dispatch.setup(self)

        # We now set up the options widget. This controls for example which
        # attribute should be used to indicate the filenames of the spectra.
        self._options_widget = OptionsWidget(data_viewer=self)

        # The layer widget is used to select which data or subset to show.
        # We don't use the default layer list, because in this case we want to
        # make sure that only one dataset or subset can be selected at any one
        # time.
        self._layer_widget = LayerWidget()

        # Make sure we update the viewer if either the selected layer or the
        # column specifying the filename is changed.
        self._layer_widget.ui.combo_active_layer.currentIndexChanged.connect(
            nonpartial(self._update_options))
        # self._layer_widget.ui.combo_active_layer.currentIndexChanged.connect(
        #     nonpartial(self._refresh_data))
        # self._options_widget.ui.combo_file_attribute.currentIndexChanged.connect(
        #     nonpartial(self._refresh_data))

        # We keep a cache of the specviz data objects that correspond to a given
        # filename - although this could take up a lot of memory if there are
        # many spectra, so maybe this isn't needed
        self._specviz_data_cache = OrderedDict()

        # We set up the specviz viewer and controller as done for the standalone
        # specviz application
        self.viewer = App(disabled={'Data List': True},
                          hidden={
                              'Layer List': True,
                              'Statistics': True,
                              'Model Fitting': True,
                              'Mask Editor': True,
                              'Data List': True
                          },
                          menubar=False)

        # Remove Glue's viewer status bar
        self.statusBar().hide()

        # Make the main toolbar smaller to fit better inside Glue
        for tb in self.viewer._all_tool_bars.values():
            # tb['widget'].setToolButtonStyle(Qt.ToolButtonIconOnly)
            tb['widget'].setIconSize(QSize(24, 24))

        # Set the view mode of mdi area to tabbed so that user aren't confused
        mdi_area = self.viewer.main_window.mdi_area
        mdi_area.setViewMode(mdi_area.TabbedView)
        mdi_area.setDocumentMode(True)
        mdi_area.setTabPosition(QTabWidget.South)

        layer_list = self.viewer._instanced_plugins.get('Layer List')
        self._layer_list = layer_list.widget(
        ) if layer_list is not None else None

        model_fitting = self.viewer._instanced_plugins.get('Model Fitting')
        self._model_fitting = model_fitting.widget(
        ) if model_fitting is not None else None

        # Create combo box to hold the types of data summation that can be done
        self._data_operation = QComboBox()
        self._data_operation.addItems(['Sum', 'Mean', 'Median'])

        self._data_operation.currentIndexChanged.connect(
            self._on_operation_changed)

        data_op_form = QFormLayout()
        data_op_form.addRow("Collapse Operation", self._data_operation)
        data_op_form.setFieldGrowthPolicy(QFormLayout.AllNonFixedFieldsGrow)

        self._unified_options = QWidget()

        layout = QVBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addLayout(data_op_form)
        # layout.addWidget(self._options_widget)
        # layout.addWidget(self._layer_widget)
        layout.addWidget(self._layer_list)

        self._unified_options.setLayout(layout)

        self.setCentralWidget(self.viewer.main_window)
Example #6
0
class CustomDialog(QDialog):
    INVALID_COLOR = QColor(255, 235, 235)

    def __init__(self, title="Title", description="Description", parent=None):
        QDialog.__init__(self, parent)

        self._option_list = []
        """ :type: list of QWidget """

        self.setModal(True)
        self.setWindowTitle(title)

        self.layout = QFormLayout()
        self.layout.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow)
        self.layout.setSizeConstraint(QLayout.SetFixedSize)

        label = QLabel(description)
        label.setAlignment(Qt.AlignHCenter)

        self.layout.addRow(self.createSpace(5))
        self.layout.addRow(label)
        self.layout.addRow(self.createSpace(10))

        self.ok_button = None

        self.setLayout(self.layout)

    def notValid(self, msg):
        """Called when the name is not valid."""
        self.ok_button.setEnabled(False)

    def valid(self):
        """Called when the name is valid."""
        self.ok_button.setEnabled(True)

    def optionValidationChanged(self):
        valid = True
        for option in self._option_list:
            if hasattr(option, "isValid"):
                if not option.isValid():
                    valid = False
                    self.notValid("One or more options are incorrectly set!")

        if valid:
            self.valid()

    def showAndTell(self):
        """
        Shows the dialog modally and returns the true or false (accept/reject)
        @rtype: bool
        """
        self.optionValidationChanged()
        return self.exec_()

    def createSpace(self, size=5):
        """Creates a widget that can be used as spacing on  a panel."""
        qw = QWidget()
        qw.setMinimumSize(QSize(size, size))

        return qw

    def addSpace(self, size=10):
        """ Add some vertical spacing """
        space_widget = self.createSpace(size)
        self.layout.addRow("", space_widget)

    def addLabeledOption(self, label, option_widget):
        """
        @type option_widget: QWidget
        """
        self._option_list.append(option_widget)

        if hasattr(option_widget, "validationChanged"):
            option_widget.validationChanged.connect(
                self.optionValidationChanged)

        if hasattr(option_widget, "getValidationSupport"):
            validation_support = option_widget.getValidationSupport()
            validation_support.validationChanged.connect(
                self.optionValidationChanged)

        self.layout.addRow("%s:" % label, option_widget)

    def addWidget(self, widget, label=""):
        if not label.endswith(":"):
            label = "%s:" % label
        self.layout.addRow(label, widget)

    def addButtons(self):
        buttons = QDialogButtonBox(
            QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Horizontal, self)
        self.ok_button = buttons.button(QDialogButtonBox.Ok)
        self.ok_button.setEnabled(False)

        self.layout.addRow(self.createSpace(10))
        self.layout.addRow(buttons)

        buttons.accepted.connect(self.accept)
        buttons.rejected.connect(self.reject)
Example #7
0
 def _init_ui(self):
     layout = QFormLayout()
     layout.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow)  # Fix for Mac OS
     return layout
Example #8
0
    def __init__(self, parent=None, is_report=False):
        QDialog.__init__(self, parent)
        self.is_report = is_report

        self.setWindowTitle(_("Issue reporter"))
        self.setModal(True)

        # To save the traceback sent to the internal console
        self.error_traceback = ""

        # Dialog main label
        if self.is_report:
            title = _("Please fill the following information")
        else:
            title = _("Spyder has encountered an internal problem!")
        main_label = QLabel(
            _("<h3>{title}</h3>"
              "Before reporting this problem, <i>please</i> consult our "
              "comprehensive "
              "<b><a href=\"{trouble_url}\">Troubleshooting Guide</a></b> "
              "which should help solve most issues, and search for "
              "<b><a href=\"{project_url}\">known bugs</a></b> "
              "matching your error message or problem description for a "
              "quicker solution."
              ).format(title=title, trouble_url=__trouble_url__,
                          project_url=__project_url__))
        main_label.setOpenExternalLinks(True)
        main_label.setWordWrap(True)
        main_label.setAlignment(Qt.AlignJustify)
        main_label.setStyleSheet('font-size: 12px;')

        # Issue title
        self.title = QLineEdit()
        self.title.textChanged.connect(self._contents_changed)
        self.title_chars_label = QLabel(_("{} more characters "
                                          "to go...").format(TITLE_MIN_CHARS))
        form_layout = QFormLayout()
        form_layout.setFieldGrowthPolicy(QFormLayout.ExpandingFieldsGrow)
        red_asterisk = '<font color="Red">*</font>'
        title_label = QLabel(_("<b>Title</b>: {}").format(red_asterisk))
        form_layout.setWidget(0, QFormLayout.LabelRole, title_label)
        form_layout.setWidget(0, QFormLayout.FieldRole, self.title)

        # Description
        steps_header = QLabel(
            _("<b>Steps to reproduce:</b> {}").format(red_asterisk))
        steps_text = QLabel(_("Please enter a detailed step-by-step "
                              "description (in English) of what led up to "
                              "the problem below. Issue reports without a "
                              "clear way to reproduce them will be closed."))
        steps_text.setWordWrap(True)
        steps_text.setAlignment(Qt.AlignJustify)
        steps_text.setStyleSheet('font-size: 12px;')

        # Field to input the description of the problem
        self.input_description = DescriptionWidget(self)

        # Only allow to submit to Github if we have a long enough description
        self.input_description.textChanged.connect(self._contents_changed)

        # Widget to show errors
        self.details = ShowErrorWidget(self)
        self.details.set_pythonshell_font(get_font())
        self.details.hide()

        # Label to show missing chars
        self.initial_chars = len(self.input_description.toPlainText())
        self.desc_chars_label = QLabel(_("{} more characters "
                                         "to go...").format(DESC_MIN_CHARS))

        # Checkbox to dismiss future errors
        self.dismiss_box = QCheckBox(_("Hide all future errors during this "
                                       "session"))
        if self.is_report:
            self.dismiss_box.hide()

        # Dialog buttons
        gh_icon = ima.icon('github')
        self.submit_btn = QPushButton(gh_icon, _('Submit to Github'))
        self.submit_btn.setEnabled(False)
        self.submit_btn.clicked.connect(self._submit_to_github)

        self.details_btn = QPushButton(_('Show details'))
        self.details_btn.clicked.connect(self._show_details)
        if self.is_report:
            self.details_btn.hide()

        self.close_btn = QPushButton(_('Close'))
        if self.is_report:
            self.close_btn.clicked.connect(self.reject)

        # Buttons layout
        buttons_layout = QHBoxLayout()
        buttons_layout.addWidget(self.submit_btn)
        buttons_layout.addWidget(self.details_btn)
        buttons_layout.addWidget(self.close_btn)

        # Main layout
        layout = QVBoxLayout()
        layout.addWidget(main_label)
        layout.addSpacing(20)
        layout.addLayout(form_layout)
        layout.addWidget(self.title_chars_label)
        layout.addSpacing(12)
        layout.addWidget(steps_header)
        layout.addSpacing(-1)
        layout.addWidget(steps_text)
        layout.addSpacing(1)
        layout.addWidget(self.input_description)
        layout.addWidget(self.details)
        layout.addWidget(self.desc_chars_label)
        layout.addSpacing(15)
        layout.addWidget(self.dismiss_box)
        layout.addSpacing(15)
        layout.addLayout(buttons_layout)
        layout.setContentsMargins(25, 20, 25, 10)
        self.setLayout(layout)

        self.resize(570, 600)
        self.title.setFocus()

        # Set Tab key focus order
        self.setTabOrder(self.title, self.input_description)
Example #9
0
    def __init__(self, settings: QSettings, parent: Optional[QObject] = None):
        # noinspection PyArgumentList
        super(NappingDialog, self).__init__(parent)

        checked_selection_mode = NappingDialog.SelectionMode(
            int(
                settings.value(
                    self.SELECTION_MODE_SETTING,
                    defaultValue=self.DEFAULT_SELECTION_MODE.value)))
        self._file_selection_mode_button = QRadioButton(
            'Single file pair', self)
        self._file_selection_mode_button.setChecked(
            checked_selection_mode == NappingDialog.SelectionMode.FILE)
        self._dir_selection_mode_button = QRadioButton(
            'Directories (multiple file pairs)', self)
        self._dir_selection_mode_button.setChecked(
            checked_selection_mode == NappingDialog.SelectionMode.DIR)
        self._selection_mode_buttons_group = QButtonGroup(self)
        self._selection_mode_buttons_group.addButton(
            self._file_selection_mode_button, NappingDialog.SelectionMode.FILE)
        self._selection_mode_buttons_group.addButton(
            self._dir_selection_mode_button, NappingDialog.SelectionMode.DIR)
        # noinspection PyUnresolvedReferences
        self._selection_mode_buttons_group.buttonClicked.connect(
            lambda _: self.refresh())

        matching_strategy_combo_box_current_text = str(
            settings.value(self.MATCHING_STRATEGY_SETTING,
                           defaultValue=self.DEFAULT_MATCHING_STRATEGY.value))
        self._matching_strategy_combo_box = QComboBox(self)
        self._matching_strategy_combo_box.addItems(
            [x.value for x in NappingDialog.MatchingStrategy])
        self._matching_strategy_combo_box.setCurrentText(
            matching_strategy_combo_box_current_text)
        # noinspection PyUnresolvedReferences
        self._matching_strategy_combo_box.currentIndexChanged.connect(
            lambda _: self.refresh())

        source_images_file_line_edit_text = str(
            settings.value(self.SOURCE_IMAGES_SETTING,
                           defaultValue=self.DEFAULT_SOURCE_IMAGES))
        self._source_images_file_line_edit = FileLineEdit(check_exists=True,
                                                          parent=self)
        self._source_images_file_line_edit.file_dialog.setWindowTitle(
            'Select source image(s)')
        self._source_images_file_line_edit.setText(
            source_images_file_line_edit_text)
        # noinspection PyUnresolvedReferences
        self._source_images_file_line_edit.textChanged.connect(
            lambda text: self.refresh(text))

        source_regex_line_edit_text = str(
            settings.value(self.SOURCE_REGEX_SETTING,
                           defaultValue=self.DEFAULT_SOURCE_REGEX))
        self._source_regex_label = QLabel('        RegEx:')
        self._source_regex_line_edit = QLineEdit(self)
        self._source_regex_line_edit.setText(source_regex_line_edit_text)
        # noinspection PyUnresolvedReferences
        self._source_regex_line_edit.textChanged.connect(
            lambda _: self.refresh())

        target_images_file_line_edit_text = str(
            settings.value(self.TARGET_IMAGES_SETTING,
                           defaultValue=self.DEFAULT_TARGET_IMAGES))
        self._target_images_file_line_edit = FileLineEdit(check_exists=True,
                                                          parent=self)
        self._target_images_file_line_edit.file_dialog.setWindowTitle(
            'Select target image(s)')
        self._target_images_file_line_edit.setText(
            target_images_file_line_edit_text)
        # noinspection PyUnresolvedReferences
        self._target_images_file_line_edit.textChanged.connect(
            lambda text: self.refresh(text))

        target_regex_line_edit_text = str(
            settings.value(self.TARGET_REGEX_SETTING,
                           defaultValue=self.DEFAULT_TARGET_REGEX))
        self._target_regex_label = QLabel('        RegEx:')
        self._target_regex_line_edit = QLineEdit(self)
        self._target_regex_line_edit.setText(target_regex_line_edit_text)
        # noinspection PyUnresolvedReferences
        self._target_regex_line_edit.textChanged.connect(
            lambda _: self.refresh())

        control_points_dest_file_line_edit_text = str(
            settings.value(self.CONTROL_POINTS_DEST_SETTING,
                           defaultValue=self.DEFAULT_CONTROL_POINTS_DEST))
        self._control_points_dest_file_line_edit = FileLineEdit(parent=self)
        self._control_points_dest_file_line_edit.file_dialog.setWindowTitle(
            'Select control points destination')
        self._control_points_dest_file_line_edit.setText(
            control_points_dest_file_line_edit_text)
        # noinspection PyUnresolvedReferences
        self._control_points_dest_file_line_edit.textChanged.connect(
            lambda text: self.refresh(text))

        joint_transform_dest_file_line_edit_text = str(
            settings.value(self.JOINT_TRANSFORM_DEST_SETTING,
                           defaultValue=self.DEFAULT_JOINT_TRANSFORM_DEST))
        self._joint_transform_dest_file_line_edit = FileLineEdit(parent=self)
        self._joint_transform_dest_file_line_edit.file_dialog.setWindowTitle(
            'Select joint transform destination')
        self._joint_transform_dest_file_line_edit.setText(
            joint_transform_dest_file_line_edit_text)
        # noinspection PyUnresolvedReferences
        self._joint_transform_dest_file_line_edit.textChanged.connect(
            lambda text: self.refresh(text))

        transform_type_combo_box_current_text = str(
            settings.value(self.TRANSFORM_TYPE_SETTING,
                           defaultValue=self.DEFAULT_TRANSFORM_TYPE))
        self._transform_type_combo_box = QComboBox(self)
        self._transform_type_combo_box.addItems(
            [x.value for x in NappingDialog.TransformType])
        self._transform_type_combo_box.setCurrentText(
            transform_type_combo_box_current_text)
        # noinspection PyUnresolvedReferences
        self._transform_type_combo_box.currentIndexChanged.connect(
            lambda _: self.refresh())

        source_coords_file_line_edit_text = str(
            settings.value(self.SOURCE_COORDS_SETTING,
                           defaultValue=self.DEFAULT_SOURCE_COORDS))
        self._source_coords_file_line_edit = FileLineEdit(check_exists=True,
                                                          parent=self)
        self._source_coords_file_line_edit.file_dialog.setWindowTitle(
            'Select source coordinates')
        self._source_coords_file_line_edit.setText(
            source_coords_file_line_edit_text)
        # noinspection PyUnresolvedReferences
        self._source_coords_file_line_edit.textChanged.connect(
            lambda text: self.refresh(text))

        source_coords_regex_line_edit_text = str(
            settings.value(self.SOURCE_COORDS_REGEX_SETTING,
                           defaultValue=self.DEFAULT_SOURCE_COORDS_REGEX))
        self._source_coords_regex_label = QLabel('        RegEx:')
        self._source_coords_regex_line_edit = QLineEdit(self)
        self._source_coords_regex_line_edit.setText(
            source_coords_regex_line_edit_text)
        # noinspection PyUnresolvedReferences
        self._source_coords_regex_line_edit.textChanged.connect(
            lambda _: self.refresh())

        transformed_coords_dest_file_line_edit_text = str(
            settings.value(self.TRANSFORMED_COORDS_DEST_SETTING,
                           defaultValue=self.DEFAULT_TRANSFORMED_COORDS_DEST))
        self._transformed_coords_dest_file_line_edit = FileLineEdit(
            parent=self)
        self._transformed_coords_dest_file_line_edit.file_dialog.setWindowTitle(
            'Select transformed coordinates destination')
        self._transformed_coords_dest_file_line_edit.setText(
            transformed_coords_dest_file_line_edit_text)
        # noinspection PyUnresolvedReferences
        self._transformed_coords_dest_file_line_edit.textChanged.connect(
            lambda text: self.refresh(text))

        pre_transform_file_line_edit_text = str(
            settings.value(self.PRE_TRANSFORM_SETTING,
                           defaultValue=self.DEFAULT_PRE_TRANSFORM))
        self._pre_transform_file_line_edit = FileLineEdit(parent=self)
        self._pre_transform_file_line_edit.file_dialog.setWindowTitle(
            'Select pre-transform')
        self._pre_transform_file_line_edit.setText(
            pre_transform_file_line_edit_text)
        self._pre_transform_file_line_edit.file_dialog.setFileMode(
            QFileDialog.ExistingFile)
        self._pre_transform_file_line_edit.file_dialog.setNameFilter(
            'Numpy files (*.npy)')
        # noinspection PyUnresolvedReferences
        self._pre_transform_file_line_edit.textChanged.connect(
            lambda text: self.refresh(text))

        post_transform_file_line_edit_text = str(
            settings.value(self.POST_TRANSFORM_SETTING,
                           defaultValue=self.DEFAULT_POST_TRANSFORM))
        self._post_transform_file_line_edit = FileLineEdit(parent=self)
        self._post_transform_file_line_edit.file_dialog.setWindowTitle(
            'Select post-transform')
        self._post_transform_file_line_edit.file_dialog.setFileMode(
            QFileDialog.ExistingFile)
        self._post_transform_file_line_edit.file_dialog.setNameFilter(
            'Numpy files (*.npy)')
        self._post_transform_file_line_edit.setText(
            post_transform_file_line_edit_text)
        # noinspection PyUnresolvedReferences
        self._post_transform_file_line_edit.textChanged.connect(
            lambda text: self.refresh(text))

        self._button_box = QDialogButtonBox(
            QDialogButtonBox.Ok | QDialogButtonBox.Cancel, self)
        # noinspection PyUnresolvedReferences
        self._button_box.rejected.connect(self.reject)

        # noinspection PyUnresolvedReferences
        @self._button_box.accepted.connect
        def on_button_box_accepted():
            settings.setValue(self.SELECTION_MODE_SETTING,
                              self.selection_mode.value)
            settings.setValue(self.SOURCE_IMAGES_SETTING,
                              str(self.source_images_path))
            settings.setValue(self.SOURCE_REGEX_SETTING, self.source_regex)
            settings.setValue(self.TARGET_IMAGES_SETTING,
                              str(self.target_images_path))
            settings.setValue(self.TARGET_REGEX_SETTING, self.target_regex)
            settings.setValue(self.CONTROL_POINTS_DEST_SETTING,
                              str(self.control_points_dest_path))
            settings.setValue(self.JOINT_TRANSFORM_DEST_SETTING,
                              str(self.joint_transform_dest_path))
            settings.setValue(self.TRANSFORM_TYPE_SETTING,
                              self.transform_type.value)
            settings.setValue(self.MATCHING_STRATEGY_SETTING,
                              self.matching_strategy.value)
            settings.setValue(self.SOURCE_COORDS_SETTING,
                              str(self.source_coords_path or ''))
            settings.setValue(self.SOURCE_COORDS_REGEX_SETTING,
                              self.source_coords_regex)
            settings.setValue(self.TRANSFORMED_COORDS_DEST_SETTING,
                              str(self.transformed_coords_dest_path or ''))
            settings.setValue(self.PRE_TRANSFORM_SETTING,
                              str(self.pre_transform_path or ''))
            settings.setValue(self.POST_TRANSFORM_SETTING,
                              str(self.post_transform_path or ''))
            settings.sync()
            self.accept()

        required_group_box = QGroupBox(self)
        required_group_box_layout = QFormLayout()
        required_group_box_layout.setLabelAlignment(Qt.AlignLeft)
        required_group_box_layout.setRowWrapPolicy(QFormLayout.DontWrapRows)
        required_group_box_layout.setFieldGrowthPolicy(
            QFormLayout.AllNonFixedFieldsGrow)
        required_group_box_layout.addRow('Source image(s):',
                                         self._source_images_file_line_edit)
        required_group_box_layout.addRow(self._source_regex_label,
                                         self._source_regex_line_edit)
        required_group_box_layout.addRow('Target image(s):',
                                         self._target_images_file_line_edit)
        required_group_box_layout.addRow(self._target_regex_label,
                                         self._target_regex_line_edit)
        required_group_box_layout.addRow(
            'Control points dest.:', self._control_points_dest_file_line_edit)
        required_group_box_layout.addRow(
            'Joint transform dest.:',
            self._joint_transform_dest_file_line_edit)
        required_group_box_layout.addRow('Transform type:',
                                         self._transform_type_combo_box)
        required_group_box.setLayout(required_group_box_layout)

        optional_group_box = QGroupBox(self)
        optional_group_box_layout = QFormLayout()
        optional_group_box_layout.setLabelAlignment(Qt.AlignLeft)
        optional_group_box_layout.setRowWrapPolicy(QFormLayout.DontWrapRows)
        optional_group_box_layout.setFieldGrowthPolicy(
            QFormLayout.AllNonFixedFieldsGrow)
        optional_group_box_layout.addRow('Source coordinates:',
                                         self._source_coords_file_line_edit)
        optional_group_box_layout.addRow(self._source_coords_regex_label,
                                         self._source_coords_regex_line_edit)
        optional_group_box_layout.addRow(
            'Transformed coord. dest.:',
            self._transformed_coords_dest_file_line_edit)
        optional_group_box_layout.addRow('Pre-transform:',
                                         self._pre_transform_file_line_edit)
        optional_group_box_layout.addRow('Post-transform:',
                                         self._post_transform_file_line_edit)
        optional_group_box.setLayout(optional_group_box_layout)

        layout = QVBoxLayout()
        mode_layout = QHBoxLayout()
        # noinspection PyArgumentList
        mode_layout.addWidget(self._file_selection_mode_button)
        # noinspection PyArgumentList
        mode_layout.addWidget(self._dir_selection_mode_button)
        # noinspection PyArgumentList
        mode_layout.addWidget(self._matching_strategy_combo_box)
        mode_layout.addStretch()
        layout.addLayout(mode_layout)
        # noinspection PyArgumentList
        layout.addWidget(required_group_box)
        # noinspection PyArgumentList
        layout.addWidget(optional_group_box)
        # noinspection PyArgumentList
        layout.addWidget(self._button_box)
        self.setLayout(layout)

        self.setWindowTitle('Control point matching')
        self.setMinimumWidth(600)
        self.refresh()