Exemplo n.º 1
0
    def __init__(self, presenter, plot_number, parent=None):
        super(PlotNameWidget, self).__init__(parent)

        self.presenter = presenter
        self.plot_number = plot_number

        self.mutex = QMutex()

        self.line_edit = QLineEdit(self.presenter.get_plot_name_from_number(plot_number))
        self.line_edit.setReadOnly(True)
        self.line_edit.setFrame(False)
        # changes the line edit to look like normal even when
        self.line_edit.setStyleSheet("""* { background-color: rgba(0, 0, 0, 0); }
        QLineEdit:disabled { color: black; }""")
        self.line_edit.setAttribute(Qt.WA_TransparentForMouseEvents, True)
        self.line_edit.editingFinished.connect(self.rename_plot)
        # Disabling the line edit prevents it from temporarily
        # grabbing focus when changing code editors - this triggered
        # the editingFinished signal, which was causing #26305
        self.line_edit.setDisabled(True)

        shown_icon = get_icon('mdi.eye')
        self.hide_button = QPushButton(shown_icon, "")
        self.hide_button.setToolTip('Hide')
        self.hide_button.setFlat(True)
        self.hide_button.setMaximumWidth(self.hide_button.iconSize().width() * 5 / 3)
        self.hide_button.clicked.connect(self.toggle_visibility)

        rename_icon = get_icon('mdi.square-edit-outline')
        self.rename_button = QPushButton(rename_icon, "")
        self.rename_button.setToolTip('Rename')
        self.rename_button.setFlat(True)
        self.rename_button.setMaximumWidth(self.rename_button.iconSize().width() * 5 / 3)
        self.rename_button.setCheckable(True)
        self.rename_button.toggled.connect(self.rename_button_toggled)

        close_icon = get_icon('mdi.close')
        self.close_button = QPushButton(close_icon, "")
        self.close_button.setToolTip('Delete')
        self.close_button.setFlat(True)
        self.close_button.setMaximumWidth(self.close_button.iconSize().width() * 5 / 3)
        self.close_button.clicked.connect(lambda: self.close_pressed(self.plot_number))

        self.layout = QHBoxLayout()

        # Get rid of the top and bottom margins - the button provides
        # some natural margin anyway. Get rid of right margin and
        # reduce spacing to get buttons closer together.
        self.layout.setContentsMargins(5, 0, 0, 0)
        self.layout.setSpacing(0)

        self.layout.addWidget(self.line_edit)
        self.layout.addWidget(self.hide_button)
        self.layout.addWidget(self.rename_button)
        self.layout.addWidget(self.close_button)

        self.layout.sizeHint()
        self.setLayout(self.layout)
Exemplo n.º 2
0
    def __init__(self, presenter, plot_number, parent=None):
        super(PlotNameWidget, self).__init__(parent)

        self.presenter = presenter
        self.plot_number = plot_number

        self.mutex = QMutex()

        self.line_edit = QLineEdit(
            self.presenter.get_plot_name_from_number(plot_number))
        self.line_edit.setReadOnly(True)
        self.line_edit.setFrame(False)
        self.line_edit.setStyleSheet(
            "* { background-color: rgba(0, 0, 0, 0); }")
        self.line_edit.setAttribute(Qt.WA_TransparentForMouseEvents, True)
        self.line_edit.editingFinished.connect(self.rename_plot)

        shown_icon = get_icon('fa.eye')
        self.hide_button = QPushButton(shown_icon, "")
        self.hide_button.setToolTip('Hide')
        self.hide_button.setFlat(True)
        self.hide_button.setMaximumWidth(self.hide_button.iconSize().width() *
                                         5 / 3)
        self.hide_button.clicked.connect(self.toggle_visibility)

        rename_icon = get_icon('fa.edit')
        self.rename_button = QPushButton(rename_icon, "")
        self.rename_button.setToolTip('Rename')
        self.rename_button.setFlat(True)
        self.rename_button.setMaximumWidth(
            self.rename_button.iconSize().width() * 5 / 3)
        self.rename_button.setCheckable(True)
        self.rename_button.toggled.connect(self.rename_button_toggled)

        close_icon = get_icon('fa.close')
        self.close_button = QPushButton(close_icon, "")
        self.close_button.setToolTip('Delete')
        self.close_button.setFlat(True)
        self.close_button.setMaximumWidth(
            self.close_button.iconSize().width() * 5 / 3)
        self.close_button.clicked.connect(
            lambda: self.close_pressed(self.plot_number))

        self.layout = QHBoxLayout()

        # Get rid of the top and bottom margins - the button provides
        # some natural margin anyway. Get rid of right margin and
        # reduce spacing to get buttons closer together.
        self.layout.setContentsMargins(5, 0, 0, 0)
        self.layout.setSpacing(0)

        self.layout.addWidget(self.line_edit)
        self.layout.addWidget(self.hide_button)
        self.layout.addWidget(self.rename_button)
        self.layout.addWidget(self.close_button)

        self.layout.sizeHint()
        self.setLayout(self.layout)
Exemplo n.º 3
0
    def _init_toolbar(self):
        for text, tooltip_text, mdi_icon, callback, checked in self.toolitems:
            if text is None:
                self.addSeparator()
            else:
                if text == 'Create Script':
                    # Add a QMenu under the QToolButton for "Create Script"
                    a = self.addAction(get_icon(mdi_icon), text, lambda: None)
                    # This is the only way I could find of getting hold of the QToolButton object
                    button = [
                        child for child in self.children()
                        if isinstance(child, QtWidgets.QToolButton)
                    ][-1]
                    menu = QtWidgets.QMenu("Menu", parent=button)
                    menu.addAction(
                        "Script to file",
                        self.sig_generate_plot_script_file_triggered.emit)
                    menu.addAction(
                        "Script to clipboard",
                        self.sig_generate_plot_script_clipboard_triggered.emit)
                    button.setMenu(menu)
                    button.setPopupMode(QtWidgets.QToolButton.InstantPopup)
                elif mdi_icon:
                    a = self.addAction(get_icon(mdi_icon), text,
                                       getattr(self, callback))
                else:
                    a = self.addAction(text, getattr(self, callback))
                self._actions[callback] = a
                if checked is not None:
                    a.setCheckable(True)
                    a.setChecked(checked)
                if tooltip_text is not None:
                    a.setToolTip(tooltip_text)
                if text == 'Home':
                    a.triggered.connect(self.on_home_clicked)

        self.buttons = {}
        # Add the x,y location widget at the right side of the toolbar
        # The stretch factor is 1 which means any resizing of the toolbar
        # will resize this label instead of the buttons.
        if self.coordinates:
            self.locLabel = QtWidgets.QLabel("", self)
            self.locLabel.setAlignment(QtCore.Qt.AlignRight
                                       | QtCore.Qt.AlignTop)
            self.locLabel.setSizePolicy(
                QtWidgets.QSizePolicy(QtWidgets.Expanding,
                                      QtWidgets.QSizePolicy.Ignored))
            labelAction = self.addWidget(self.locLabel)
            labelAction.setVisible(True)

        # reference holder for subplots_adjust window
        self.adj_window = None

        # Adjust icon size or they are too small in PyQt5 by default
        dpi_ratio = QtWidgets.QApplication.instance().desktop().physicalDpiX(
        ) / 100
        self.setIconSize(QtCore.QSize(24 * dpi_ratio, 24 * dpi_ratio))
Exemplo n.º 4
0
    def __init__(self, parent, presenter):
        super(EmbeddedFindReplaceDialogView, self).__init__(parent)
        self.setupUi(self)
        self.resize(self.width(), 100)

        self.find.completer().setCaseSensitivity(Qt.CaseSensitive)
        self.replace.completer().setCaseSensitivity(Qt.CaseSensitive)

        self.presenter = presenter

        self.hide_find_replace = create_action(
            self, '', on_triggered=self.presenter.hide, shortcut=Qt.Key_Escape)
        self.addAction(self.hide_find_replace)

        self.enter_to_search = create_action(
            self,
            '',
            on_triggered=self.presenter.action_next,
            shortcut=[Qt.Key_Return, Qt.Key_Enter])
        self.addAction(self.enter_to_search)

        self.shift_enter_to_search_backwards = create_action(
            self,
            '',
            on_triggered=self.presenter.action_previous,
            shortcut=["Shift+Enter", "Shift+Return"])
        self.addAction(self.shift_enter_to_search_backwards)

        self.find.lineEdit().setPlaceholderText("Find")
        self.replace.lineEdit().setPlaceholderText("Replace with")

        self.setAttribute(Qt.WA_DeleteOnClose, True)

        arrow_up_icon = get_icon("mdi.arrow-up")
        arrow_down_icon = get_icon("mdi.arrow-down")
        x_icon = get_icon("mdi.close")

        self.next_button.setIcon(arrow_down_icon)
        self.previous_button.setIcon(arrow_up_icon)
        self.close_button.setIcon(x_icon)

        self.next_button.clicked.connect(self.presenter.action_next)
        self.previous_button.clicked.connect(self.presenter.action_previous)

        self.close_button.clicked.connect(self.presenter.action_close_button)

        self.replace_button.clicked.connect(self.presenter.action_replace)
        self.replace_all_button.clicked.connect(
            self.presenter.action_replace_all)

        self.find.currentTextChanged.connect(self.presenter.clear_search)
        self.match_case.stateChanged.connect(self.presenter.clear_search)
        self.words.stateChanged.connect(self.presenter.clear_search)
        self.regex.stateChanged.connect(self.presenter.clear_search)
        self.wrap_around.stateChanged.connect(self.presenter.clear_search)
Exemplo n.º 5
0
 def set_visibility_icon(self, is_shown):
     """
     Change the widget icon between shown and hidden
     :param is_shown: True if plot is shown, false if hidden
     """
     if is_shown:
         self.hide_button.setIcon(get_icon('mdi.eye'))
         self.hide_button.setToolTip('Hide')
     else:
         self.hide_button.setIcon(get_icon('mdi.eye', 'lightgrey'))
         self.hide_button.setToolTip('Show')
Exemplo n.º 6
0
 def set_visibility_icon(self, is_shown):
     """
     Change the widget icon between shown and hidden
     :param is_shown: True if plot is shown, false if hidden
     """
     if is_shown:
         self.hide_button.setIcon(get_icon('mdi.eye'))
         self.hide_button.setToolTip('Hide')
     else:
         self.hide_button.setIcon(get_icon('mdi.eye', 'lightgrey'))
         self.hide_button.setToolTip('Show')
Exemplo n.º 7
0
    def __init__(self, presenter, plot_number, parent=None):
        super(PlotNameWidget, self).__init__(parent)

        self.presenter = presenter
        self.plot_number = plot_number

        self.mutex = QMutex()

        self.line_edit = QLineEdit(self.presenter.get_plot_name_from_number(plot_number))
        self.line_edit.setReadOnly(True)
        self.line_edit.setFrame(False)
        self.line_edit.setStyleSheet("* { background-color: rgba(0, 0, 0, 0); }")
        self.line_edit.setAttribute(Qt.WA_TransparentForMouseEvents, True)
        self.line_edit.editingFinished.connect(self.rename_plot)

        shown_icon = get_icon('mdi.eye')
        self.hide_button = QPushButton(shown_icon, "")
        self.hide_button.setToolTip('Hide')
        self.hide_button.setFlat(True)
        self.hide_button.setMaximumWidth(self.hide_button.iconSize().width() * 5 / 3)
        self.hide_button.clicked.connect(self.toggle_visibility)

        rename_icon = get_icon('mdi.square-edit-outline')
        self.rename_button = QPushButton(rename_icon, "")
        self.rename_button.setToolTip('Rename')
        self.rename_button.setFlat(True)
        self.rename_button.setMaximumWidth(self.rename_button.iconSize().width() * 5 / 3)
        self.rename_button.setCheckable(True)
        self.rename_button.toggled.connect(self.rename_button_toggled)

        close_icon = get_icon('mdi.close')
        self.close_button = QPushButton(close_icon, "")
        self.close_button.setToolTip('Delete')
        self.close_button.setFlat(True)
        self.close_button.setMaximumWidth(self.close_button.iconSize().width() * 5 / 3)
        self.close_button.clicked.connect(lambda: self.close_pressed(self.plot_number))

        self.layout = QHBoxLayout()

        # Get rid of the top and bottom margins - the button provides
        # some natural margin anyway. Get rid of right margin and
        # reduce spacing to get buttons closer together.
        self.layout.setContentsMargins(5, 0, 0, 0)
        self.layout.setSpacing(0)

        self.layout.addWidget(self.line_edit)
        self.layout.addWidget(self.hide_button)
        self.layout.addWidget(self.rename_button)
        self.layout.addWidget(self.close_button)

        self.layout.sizeHint()
        self.setLayout(self.layout)
Exemplo n.º 8
0
    def __init__(self, parent, presenter):
        super(EmbeddedFindReplaceDialogView, self).__init__(parent)
        self.setupUi(self)
        self.resize(self.width(), 100)

        self.find.completer().setCaseSensitivity(Qt.CaseSensitive)
        self.replace.completer().setCaseSensitivity(Qt.CaseSensitive)

        self.presenter = presenter

        self.hide_find_replace = create_action(self, '',
                                               on_triggered=self.presenter.hide,
                                               shortcut=Qt.Key_Escape)
        self.addAction(self.hide_find_replace)

        self.enter_to_search = create_action(self, '',
                                             on_triggered=self.presenter.action_next,
                                             shortcut=[Qt.Key_Return, Qt.Key_Enter])
        self.addAction(self.enter_to_search)

        self.shift_enter_to_search_backwards = create_action(self, '',
                                                             on_triggered=self.presenter.action_previous,
                                                             shortcut=["Shift+Enter", "Shift+Return"])
        self.addAction(self.shift_enter_to_search_backwards)

        self.find.lineEdit().setPlaceholderText("Find")
        self.replace.lineEdit().setPlaceholderText("Replace with")

        self.setAttribute(Qt.WA_DeleteOnClose, True)

        arrow_up_icon = get_icon("mdi.arrow-up")
        arrow_down_icon = get_icon("mdi.arrow-down")
        x_icon = get_icon("mdi.close")

        self.next_button.setIcon(arrow_down_icon)
        self.previous_button.setIcon(arrow_up_icon)
        self.close_button.setIcon(x_icon)

        self.next_button.clicked.connect(self.presenter.action_next)
        self.previous_button.clicked.connect(self.presenter.action_previous)

        self.close_button.clicked.connect(self.presenter.action_close_button)

        self.replace_button.clicked.connect(self.presenter.action_replace)
        self.replace_all_button.clicked.connect(self.presenter.action_replace_all)

        self.find.currentTextChanged.connect(self.presenter.clear_search)
        self.match_case.stateChanged.connect(self.presenter.clear_search)
        self.words.stateChanged.connect(self.presenter.clear_search)
        self.regex.stateChanged.connect(self.presenter.clear_search)
        self.wrap_around.stateChanged.connect(self.presenter.clear_search)
Exemplo n.º 9
0
    def set_up_color_selector_toolbar_button(self, fig):
        # check if the action is already in the toolbar
        if self._actions.get('line_colour'):
            return

        a = self.addAction(get_icon('mdi.palette'), "Line Colour", lambda: None)
        self._actions['line_colour'] = a

        if figure_type(fig) == FigureType.Wireframe:
            a.setToolTip("Set the colour of the wireframe.")
        else:
            a.setToolTip("Set the colour of the contour lines.")

        line_collection = next(col for col in fig.get_axes()[0].collections if isinstance(col, LineCollection))
        initial_colour = convert_color_to_hex(line_collection.get_color()[0])

        colour_dialog = QtWidgets.QColorDialog(QtGui.QColor(initial_colour))
        colour_dialog.setOption(QtWidgets.QColorDialog.NoButtons)
        colour_dialog.setOption(QtWidgets.QColorDialog.DontUseNativeDialog)
        colour_dialog.currentColorChanged.connect(self.change_line_collection_colour)

        button = [child for child in self.children() if isinstance(child, QtWidgets.QToolButton)][-1]

        menu = QtWidgets.QMenu("Menu", parent=button)
        colour_selector_action = QtWidgets.QWidgetAction(menu)
        colour_selector_action.setDefaultWidget(colour_dialog)
        menu.addAction(colour_selector_action)

        button.setMenu(menu)
        button.setPopupMode(QtWidgets.QToolButton.InstantPopup)
Exemplo n.º 10
0
    def setAlgorithms(self, algorithms, extensions, tooltips):
        """
        Set the algorithms displayed on the dialog.

        Args:
            algorithms (list(str)): list of algorithms
            extensions (dict(str:str)): extension used by each algorithm
            tooltips (dict(str:str)): short doc of each algorithm
        """
        for i in range(len(algorithms)):
            algo = algorithms[i]
            if algo in extensions:
                text = algo + " (" + extensions[algo] + ")"
            else:
                text = algo
            widget = QCheckBox(text, self)
            if algo in tooltips:
                widget.setToolTip(tooltips[algo])
            self._widgets[algorithms[i]] = widget
            self.algoList.addWidget(widget, i, 0, Qt.AlignLeft)
            helpButton = QToolButton(self)
            helpButton.setText('...')
            helpButton.setIcon(icons.get_icon("mdi.help"))
            helpButton.clicked.connect(
                lambda _, a=algorithms[i]: InterfaceManager().showHelpPage(
                    "qthelp://org.mantidproject/doc/algorithms/{}.html".format(
                        a)))
            self.algoList.addWidget(helpButton, i, 1, Qt.AlignRight)
Exemplo n.º 11
0
    def _init_toolbar(self):
        for text, tooltip_text, mdi_icon, callback in self.toolitems:
            if text is None:
                self.addSeparator()
            else:

                if mdi_icon:
                    a = self.addAction(get_icon(mdi_icon), text,
                                       getattr(self, callback))
                else:
                    a = self.addAction(text, getattr(self, callback))
                self._actions[callback] = a
                if tooltip_text is not None:
                    a.setToolTip(tooltip_text)

        if self.coordinates:
            self.locLabel = QtWidgets.QLabel("", self)
            self.locLabel.setAlignment(QtCore.Qt.AlignRight
                                       | QtCore.Qt.AlignTop)
            self.locLabel.setSizePolicy(
                QtWidgets.QSizePolicy(
                    QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                          QtWidgets.QSizePolicy.Ignored)))
            labelAction = self.addWidget(self.locLabel)
            labelAction.setVisible(True)

        # Adjust icon size or they are too small in PyQt5 by default
        dpi_ratio = QtWidgets.QApplication.instance().desktop().physicalDpiX(
        ) / 100
        self.setIconSize(QtCore.QSize(24 * dpi_ratio, 24 * dpi_ratio))
Exemplo n.º 12
0
    def __init__(self, canvas, parent, coordinates=True):
        """coordinates: should we show the coordinates on the right?"""
        QToolBar.__init__(self, parent)
        self.setAllowedAreas(Qt.TopToolBarArea | Qt.BottomToolBarArea)
        self._actions = {}  # mapping of toolitem method names to QActions.
        self.coordinates = coordinates

        for text, tooltip_text, mdi_icon, callback, checked, initializer in self.toolitems:
            if text is None:
                self.addSeparator()
            else:
                if callable(initializer):
                    a = initializer(self, text, tooltip_text, mdi_icon,
                                    callback, checked, initializer)
                elif mdi_icon:
                    a = self.addAction(get_icon(mdi_icon), text,
                                       getattr(self, callback))
                else:
                    a = self.addAction(text, getattr(self, callback))
                self._actions[callback] = a
                if checked is not None:
                    a.setCheckable(True)
                    a.setChecked(checked)
                if tooltip_text is not None:
                    a.setToolTip(tooltip_text)

        if self.coordinates:
            self.locLabel = QLabel("", self)
            self.locLabel.setAlignment(Qt.AlignRight | Qt.AlignTop)
            self.locLabel.setSizePolicy(
                QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Ignored))
            labelAction = self.addWidget(self.locLabel)
            labelAction.setVisible(True)
        NavigationToolbar2.__init__(self, canvas)
Exemplo n.º 13
0
    def _init_toolbar(self):
        for text, tooltip_text, fa_icon, callback, checked in self.toolitems:
            if text is None:
                self.addSeparator()
            else:
                if fa_icon:
                    a = self.addAction(get_icon(fa_icon), text, getattr(self, callback))
                else:
                    a = self.addAction(text, getattr(self, callback))
                self._actions[callback] = a
                if checked is not None:
                    a.setCheckable(True)
                    a.setChecked(checked)
                if tooltip_text is not None:
                    a.setToolTip(tooltip_text)

        # Add the x,y location widget at the right side of the toolbar
        # The stretch factor is 1 which means any resizing of the toolbar
        # will resize this label instead of the buttons.
        if self.coordinates:
            self.locLabel = QLabel("", self)
            self.locLabel.setAlignment(Qt.AlignRight | Qt.AlignTop)
            self.locLabel.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Ignored))
            labelAction = self.addWidget(self.locLabel)
            labelAction.setVisible(True)

        # Adjust icon size or they are too small in PyQt5 by default
        self.setIconSize(QSize(24, 24))

        # Location of a press event
        self._pressed_xy = None
Exemplo n.º 14
0
    def setColumns(self, allColumns, hiddenColumns):
        """
        Set the columns in the context menu.

        Args:
            allColumns (list(str)): list of column names
            hiddenColumns (list(str)): list of hidden column names
        """
        for column in allColumns:
            if column in hiddenColumns:
                action = self._colMenu.addAction(icons.get_icon("mdi.close"),
                                                 column)
            else:
                action = self._colMenu.addAction(icons.get_icon("mdi.check"),
                                                 column)
            action.triggered.connect(
                lambda _, c=column: self.toogleColumnVisibility.emit(c))
    def __init__(self, parent=None, window_flags=None):
        if window_flags is not None:
            super(EngineeringDiffractionGui,
                  self).__init__(parent, window_flags)
        else:
            super(EngineeringDiffractionGui, self).__init__(parent)

        # Main Window
        self.setupUi(self)
        self.tabs = self.tab_main
        self.setFocusPolicy(QtCore.Qt.StrongFocus)
        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)

        self.btn_settings.setIcon(get_icon("mdi.settings", "black", 1.2))

        # Create status bar widgets
        self.status_label = QtWidgets.QLabel()
        self.savedir_label = QtWidgets.QLabel()
        self.savedir_label.setMaximumWidth(self.status_savdirMaxwidth)

        # observers
        self.update_statusbar_text_observable = GenericObserverWithArgPassing(
            self.set_statusbar_text)
        self.update_savedir_observable = GenericObserverWithArgPassing(
            self.update_savedir)
        self.savedir_observer = SavedirObserver(self)

        # this presenter needs to be accessible to this view so that it can be accessed by project save
        self.presenter = self.setup_presenter()

        # setup that can only happen with presenter created
        self.setup_statusbar()
        self.set_on_instrument_changed(
            self.presenter.calibration_presenter.set_instrument_override)
        self.set_on_rb_num_changed(
            self.presenter.calibration_presenter.set_rb_num)
        self.set_on_instrument_changed(
            self.presenter.focus_presenter.set_instrument_override)
        self.set_on_rb_num_changed(self.presenter.focus_presenter.set_rb_num)

        # load most recent calibration, if one saved
        self.presenter.calibration_presenter.load_last_calibration()

        # load previous rb number if saved, create mechanism to save
        self.set_rb_no(self.presenter.get_saved_rb_number())
        self.set_on_rb_num_changed(self.presenter.set_saved_rb_number)

        # Usage Reporting
        try:
            import mantid

            # register startup
            mantid.UsageService.registerFeatureUsage(
                mantid.kernel.FeatureType.Interface, "Engineering Diffraction",
                False)
        except ImportError:
            pass
Exemplo n.º 16
0
 def test_get_icon_list_and_list_of_options(self):
     icon = get_icon(["mdi.run-fast", "mdi.run"], [{
         "color": "red",
         "scaleFactor": 1.5
     }, {
         "color": "green",
         "scaleFactor": 1.2
     }])
     self.assertEqual(icon.isNull(), False)
Exemplo n.º 17
0
def _create_script_action(self, text, tooltip_text, mdi_icon, *args):
    # Add a QMenu under the QToolButton for "Create Script"
    a = self.addAction(get_icon(mdi_icon), text, lambda: None)
    # This is the only way I could find of getting hold of the QToolButton object
    button = [child for child in self.children()
              if isinstance(child, QtWidgets.QToolButton)][-1]
    menu =  QtWidgets.QMenu("Menu", parent=button)
    menu.addAction("Script to file",
                   self.sig_generate_plot_script_file_triggered.emit)
    menu.addAction("Script to clipboard",
                   self.sig_generate_plot_script_clipboard_triggered.emit)
    button.setMenu(menu)
    button.setPopupMode(QtWidgets.QToolButton.InstantPopup)
    return a
Exemplo n.º 18
0
    def setAddRemoveColumnMenu(self, columns):
        """
        Fill the "add/remove column" menu. This function is triggered each time
        the menu is displayed to display a correct icon depending on the status
        of the column (hidden or not).

        Args:
            columns (list(str)): list of column titles
        """
        if self.menuAddRemoveColumn.receivers(QMenu.triggered):
            self.menuAddRemoveColumn.triggered.disconnect()
        self.menuAddRemoveColumn.clear()
        hidden = self.table.getHiddenColumns()
        for c in columns:
            action = QAction(c, self.menuAddRemoveColumn)
            if c in hidden:
                action.setIcon(icons.get_icon("mdi.close"))
            else:
                action.setIcon(icons.get_icon("mdi.check"))
            self.menuAddRemoveColumn.addAction(action)

        self.menuAddRemoveColumn.triggered.connect(
            lambda action: self.table.toggleColumnVisibility(action.text()))
    def __init__(self, parent=None, window_flags=None):
        if window_flags is not None:
            super(EngineeringDiffractionGui,
                  self).__init__(parent, window_flags)
        else:
            super(EngineeringDiffractionGui, self).__init__(parent)

    # Main Window
        self.setupUi(self)
        self.doc = "Engineering Diffraction"
        self.tabs = self.tab_main
        self.setFocusPolicy(QtCore.Qt.StrongFocus)
        self.calibration_presenter = None
        self.focus_presenter = None
        self.fitting_presenter = None
        self.settings_presenter = None
        self.calibration_observer = CalibrationObserver(self)
        self.savedir_observer = SavedirObserver(self)
        self.set_on_help_clicked(self.open_help_window)

        self.set_on_settings_clicked(self.open_settings)
        self.btn_settings.setIcon(get_icon("mdi.settings", "black", 1.2))

        # Setup Elements
        self.setup_settings()
        self.setup_calibration()
        self.setup_focus()
        self.setup_fitting()

        # Setup status bar
        self.status_label = QtWidgets.QLabel()
        self.savedir_label = QtWidgets.QLabel()
        self.savedir_label.setMaximumWidth(self.status_savdirMaxwidth)
        self.setup_statusbar()

        # Setup notifiers
        self.setup_calibration_notifier()
        self.setup_savedir_notifier()

        # Usage Reporting
        try:
            import mantid

            # register startup
            mantid.UsageService.registerFeatureUsage(
                mantid.kernel.FeatureType.Interface, "Engineering Diffraction",
                False)
        except ImportError:
            pass
Exemplo n.º 20
0
    def _init_toolbar(self):
        for text, tooltip_text, mdi_icon, callback, checked in self.toolitems:
            if text is None:
                self.addSeparator()
            else:
                action = self.addAction(get_icon(mdi_icon), text, getattr(self, callback))
                self._actions[callback] = action
                if checked is not None:
                    action.setCheckable(True)
                    action.setChecked(checked)
                if tooltip_text is not None:
                    action.setToolTip(tooltip_text)

        dpi_ratio = QtWidgets.QApplication.instance().desktop().physicalDpiX() / 100
        self.setIconSize(QtCore.QSize(24 * dpi_ratio, 24 * dpi_ratio))
Exemplo n.º 21
0
    def __init__(self, parent=None):
        QtWidgets.QTabWidget.__init__(self, parent)

        self.tab_bar = self.TabBar(self)

        self.tab_bar.onDetachTabSignal.connect(self.detach_tab)
        # self.tab_bar.detachedTabDropSignal.connect(self.detached_tab_drop)

        self.setTabBar(self.tab_bar)

        # Used to keep a reference to detached tabs since their QMainWindow
        # does not have a parent
        self.detachedTabs = {}

        self.tab_order = []
        self.attached_tab_names = []

        self.valid_tab_icon = QIcon()
        self.invalid_tab_icon = icons.get_icon("mdi.asterisk", "red", 0.5)
Exemplo n.º 22
0
    def __init__(self, ws, parent=None):
        self.overlay_visible = False
        self.scatter = None
        self.aspect_equal = False
        super().__init__(ws, parent=parent)

        self.view.data_view.mpl_toolbar.addSeparator()

        # Add aspect ratio button, use used nonOrthogonalClicked
        # signal, easier than creating a new one
        self.view.data_view.mpl_toolbar.nonOrthogonalClicked.disconnect()
        self.view.data_view.mpl_toolbar.addAction(
            get_icon('mdi.aspect-ratio'), 'aspect',
            self.view.data_view.mpl_toolbar.nonOrthogonalClicked).setToolTip(
                'Toggle aspect ratio')
        self.view.data_view.mpl_toolbar.nonOrthogonalClicked.connect(
            self.toggle_aspect)

        self.view.data_view.mpl_toolbar.peaksOverlayClicked.disconnect()
        self.view.data_view.mpl_toolbar.peaksOverlayClicked.connect(
            self.overlay)
Exemplo n.º 23
0
    def __init__(self, parent=None, presenter=None):
        self.presenter = presenter if presenter else CodeEditorTabPresenter(self)
        super(CodeEditorTabWidget, self).__init__(parent)

        self.setAttribute(Qt.WA_DeleteOnClose, True)
        self.setContextMenuPolicy(Qt.ActionsContextMenu)
        self.setMovable(True)
        self.setTabsClosable(True)
        self.setDocumentMode(True)

        self.last_tab_clicked = 0

        self.setup_tabs_context_menu(parent)
        self.setup_options_actions(parent)

        # create a button to add new tabs
        plus_button = QPushButton(self)
        plus_button.setObjectName(self.NEW_EDITOR_PLUS_BTN_OBJECT_NAME)
        plus_button.clicked.connect(parent.plus_button_clicked)
        plus_button.setShortcut('Ctrl+N')
        plus_button.setIcon(get_icon("mdi.plus", "black", 1.2))
        self.setCornerWidget(plus_button, Qt.TopLeftCorner)
Exemplo n.º 24
0
    def _init_toolbar(self):
        for text, tooltip_text, mdi_icon, callback, checked in self.toolitems:
            if text is None:
                self.addSeparator()
            else:
                if mdi_icon:
                    a = self.addAction(get_icon(mdi_icon),
                                       text, getattr(self, callback))
                else:
                    a = self.addAction(text, getattr(self, callback))
                self._actions[callback] = a
                if checked is not None:
                    a.setCheckable(True)
                    a.setChecked(checked)
                if tooltip_text is not None:
                    a.setToolTip(tooltip_text)

        self.buttons = {}
        # Add the x,y location widget at the right side of the toolbar
        # The stretch factor is 1 which means any resizing of the toolbar
        # will resize this label instead of the buttons.
        if self.coordinates:
            self.locLabel = QtWidgets.QLabel("", self)
            self.locLabel.setAlignment(
                    QtCore.Qt.AlignRight | QtCore.Qt.AlignTop)
            self.locLabel.setSizePolicy(
                QtWidgets.QSizePolicy(QtWidgets.Expanding,
                                      QtWidgets.QSizePolicy.Ignored))
            labelAction = self.addWidget(self.locLabel)
            labelAction.setVisible(True)

        # reference holder for subplots_adjust window
        self.adj_window = None

        # Adjust icon size or they are too small in PyQt5 by default
        dpi_ratio = QtWidgets.QApplication.instance().desktop().physicalDpiX()/100
        self.setIconSize(QtCore.QSize(24*dpi_ratio, 24*dpi_ratio))
Exemplo n.º 25
0
    def __init__(self, parent=None):
        super(EngineeringDiffractionGui, self).__init__(parent)

        # Main Window
        self.setupUi(self)
        self.doc = "Engineering Diffraction"
        self.tabs = self.tab_main
        self.setFocusPolicy(QtCore.Qt.StrongFocus)
        self.calibration_presenter = None
        self.focus_presenter = None
        self.fitting_presenter = None
        self.settings_presenter = None
        self.set_on_help_clicked(self.open_help_window)

        self.set_on_settings_clicked(self.open_settings)
        self.btn_settings.setIcon(get_icon("mdi.settings", "black", 1.2))

        # Setup Elements
        self.setup_settings()
        self.setup_calibration()
        self.setup_focus()
        self.setup_fitting()

        # Setup notifiers
        self.setup_calibration_notifier()

        # Usage Reporting
        try:
            import mantid

            # register startup
            mantid.UsageService.registerFeatureUsage(
                mantid.kernel.FeatureType.Interface, "Engineering Diffraction",
                False)
        except ImportError:
            pass
Exemplo n.º 26
0
    def _init_toolbar(self):
        for text, tooltip_text, fa_icon, callback, checked in self.toolitems:
            if text is None:
                self.addSeparator()
            else:
                if fa_icon:
                    a = self.addAction(get_icon(fa_icon),
                                       text, getattr(self, callback))
                else:
                    a = self.addAction(text, getattr(self, callback))
                self._actions[callback] = a
                if checked is not None:
                    a.setCheckable(True)
                    a.setChecked(checked)
                if tooltip_text is not None:
                    a.setToolTip(tooltip_text)

        self.buttons = {}
        # Add the x,y location widget at the right side of the toolbar
        # The stretch factor is 1 which means any resizing of the toolbar
        # will resize this label instead of the buttons.
        if self.coordinates:
            self.locLabel = QtWidgets.QLabel("", self)
            self.locLabel.setAlignment(
                    QtCore.Qt.AlignRight | QtCore.Qt.AlignTop)
            self.locLabel.setSizePolicy(
                QtWidgets.QSizePolicy(QtWidgets.Expanding,
                                      QtWidgets.QSizePolicy.Ignored))
            labelAction = self.addWidget(self.locLabel)
            labelAction.setVisible(True)

        # reference holder for subplots_adjust window
        self.adj_window = None

        # Adjust icon size or they are too small in PyQt5 by default
        self.setIconSize(QtCore.QSize(24, 24))
Exemplo n.º 27
0
def red_asterisk():
    global RED_ASTERISK
    if RED_ASTERISK is None:
        RED_ASTERISK = get_icon('mdi.asterisk', 'red', 0.6)
    return RED_ASTERISK
Exemplo n.º 28
0
 def test_get_icon_name(self):
     icon = get_icon("mdi.run-fast")
     self.assertEqual(icon.isNull(), False)
Exemplo n.º 29
0
 def test_get_icon_name_color_scaleFactor(self):
     icon = get_icon("mdi.run-fast", "red", 1.5)
     self.assertEqual(icon.isNull(), False)
Exemplo n.º 30
0
    def setup_options_actions(self, parent):
        """
        Setup the actions for the Options menu. The actions are handled by the parent widget
        """
        container_widget = QWidget(self)
        layout = QHBoxLayout(container_widget)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.setSpacing(0)
        container_widget.setLayout(layout)
        self.setCornerWidget(container_widget, Qt.TopRightCorner)

        run_button = QPushButton(container_widget)
        run_button.setObjectName(self.RUN_BUTTON_OBJECT_NAME)
        run_button.setIcon(get_icon("mdi.play", PLAY_BUTTON_GREEN_COLOR, 1.6))
        run_button.clicked.connect(parent.execute_current_async)
        layout.addWidget(run_button)

        abort_button = QPushButton(container_widget)
        abort_button.setObjectName(self.ABORT_BUTTON_OBJECT_NAME)
        abort_button.setIcon(
            get_icon("mdi.square", ABORT_BUTTON_RED_COLOR, 1.1))
        abort_button.clicked.connect(parent.abort_current)
        layout.addWidget(abort_button)

        options_button = QPushButton(container_widget)
        options_button.setObjectName(self.OPTIONS_BUTTON_OBJECT_NAME)
        options_button.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum)
        options_button.setText("Options")

        options_menu = QMenu("", self)
        options_button.setMenu(options_menu)
        layout.addWidget(options_button)

        self.tabCloseRequested.connect(parent.close_tab)

        run_action = create_action(self,
                                   "Run",
                                   on_triggered=parent.execute_current_async,
                                   shortcut=("Ctrl+Enter", "Ctrl+Return"),
                                   shortcut_context=Qt.ApplicationShortcut,
                                   shortcut_visible_in_context_menu=True)

        run_all_action = create_action(self,
                                       "Run All",
                                       on_triggered=parent.execute_async,
                                       shortcut=("Ctrl+Shift+Enter",
                                                 "Ctrl+Shift+Return"),
                                       shortcut_context=Qt.ApplicationShortcut,
                                       shortcut_visible_in_context_menu=True)

        abort_action = create_action(self,
                                     "Abort",
                                     on_triggered=parent.abort_current,
                                     shortcut="Ctrl+D",
                                     shortcut_context=Qt.ApplicationShortcut,
                                     shortcut_visible_in_context_menu=True)

        # menu action to toggle the find/replace dialog
        toggle_find_replace = create_action(
            self,
            'Find/Replace...',
            on_triggered=parent.toggle_find_replace_dialog,
            shortcut='Ctrl+F',
            shortcut_visible_in_context_menu=True)

        toggle_comment_action = create_action(
            self,
            "Comment/Uncomment",
            on_triggered=parent.toggle_comment_current,
            shortcut="Ctrl+/",
            shortcut_context=Qt.ApplicationShortcut,
            shortcut_visible_in_context_menu=True)

        tabs_to_spaces_action = create_action(
            self,
            'Tabs to Spaces',
            on_triggered=parent.tabs_to_spaces_current,
            shortcut_visible_in_context_menu=True)

        spaces_to_tabs_action = create_action(
            self,
            'Spaces to Tabs',
            on_triggered=parent.spaces_to_tabs_current,
            shortcut_visible_in_context_menu=True)

        toggle_whitespace_action = create_action(
            self,
            'Toggle Whitespace Visible',
            on_triggered=parent.toggle_whitespace_visible_all,
            shortcut_visible_in_context_menu=True)

        # Store actions for adding to menu bar; None will add a separator
        editor_actions = [
            run_action, run_all_action, abort_action, None,
            toggle_find_replace, None, toggle_comment_action,
            toggle_whitespace_action, None, tabs_to_spaces_action,
            spaces_to_tabs_action
        ]

        add_actions(options_menu, editor_actions)
Exemplo n.º 31
0
 def test_get_icon_list_and_list_of_options(self):
     icon = get_icon(["mdi.run-fast", "mdi.run"], [{"color": "red", "scaleFactor": 1.5},
                                                   {"color": "green", "scaleFactor": 1.2}])
     self.assertEqual(icon.isNull(), False)
Exemplo n.º 32
0
 def test_get_icon_name(self):
     icon = get_icon("mdi.run-fast")
     self.assertEqual(icon.isNull(), False)
Exemplo n.º 33
0
    def setup_header(self):
        """
        Setup the window header. Set the buttons icons and connect the signals.
        """
        self.actionLoadRundex.triggered.connect(self.load_rundex)
        self.actionSaveAs.triggered.connect(self.saveRundexAs)
        self.actionSave.triggered.connect(self.saveRundex)
        self.actionManageDirectories.triggered.connect(self.show_directory_manager)
        self.actionSettings.triggered.connect(self.showSettings.emit)
        self.actionClose.triggered.connect(self.close)
        self.actionAddRow.triggered.connect(self.add_row_after)
        self.actionDelRow.triggered.connect(self.del_selected_rows)
        self.actionCopyRow.triggered.connect(self.copySelectedCells)
        self.actionCutRow.triggered.connect(self.cutSelectedCells)
        self.actionPasteRow.triggered.connect(self.pasteCells)
        self.actionErase.triggered.connect(self.eraseSelectedCells)
        self.actionProcessRow.triggered.connect(self.process_selected_rows)
        self.actionProcessAll.triggered.connect(self.process_all_rows)
        self.actionStopProcessing.triggered.connect(self.processStopped.emit)
        self.actionHelp.triggered.connect(self.helpWindow)

        self.instrumentselector = instrumentselector.InstrumentSelector(self)
        self.instrumentselector.setToolTip("Instrument")
        self.toolbar.insertWidget(0, self.instrumentselector, 0, Qt.AlignLeft)
        self.instrumentselector.instrumentSelectionChanged.connect(
                self._changeInstrument)

        self.modeSelector.currentTextChanged.connect(
                self._changeAcquisitionMode)

        self.cycleNumber.editingFinished.connect(self._changeCycleOrExperiment)
        self.experimentId.editingFinished.connect(self._changeCycleOrExperiment)

        self.datadirs.setIcon(icons.get_icon("mdi.folder"))
        self.datadirs.clicked.connect(self.show_directory_manager)

        self.load.setIcon(icons.get_icon("mdi.file-import"))
        self.load.clicked.connect(self.load_rundex)

        self.settings.setIcon(icons.get_icon("mdi.settings"))
        self.settings.clicked.connect(self.showSettings.emit)

        self.paste.setIcon(icons.get_icon("mdi.content-paste"))
        self.paste.clicked.connect(self.pasteCells)

        self.copy.setIcon(icons.get_icon("mdi.content-copy"))
        self.copy.clicked.connect(self.copySelectedCells)

        self.cut.setIcon(icons.get_icon("mdi.content-cut"))
        self.cut.clicked.connect(self.cutSelectedCells)

        self.erase.setIcon(icons.get_icon("mdi.eraser"))
        self.erase.clicked.connect(self.eraseSelectedCells)

        self.deleterow.setIcon(icons.get_icon("mdi.table-row-remove"))
        self.deleterow.clicked.connect(self.del_selected_rows)

        self.addrow.setIcon(icons.get_icon("mdi.table-row-plus-after"))
        self.addrow.clicked.connect(self.add_row_after)

        self.save.setIcon(icons.get_icon("mdi.file-export"))
        self.save.clicked.connect(self.saveRundexAs)

        self.help.setIcon(icons.get_icon("mdi.help"))
        self.help.clicked.connect(self.helpWindow)

        self.fill.setIcon(icons.get_icon("mdi.arrow-expand-down"))
        self.fill.clicked.connect(self.automatic_filling)

        self.processRows.setIcon(icons.get_icon("mdi.play"))
        self.processRows.clicked.connect(self.process_selected_rows)

        self.processAll.setIcon(icons.get_icon("mdi.fast-forward"))
        self.processAll.clicked.connect(self.process_all_rows)

        self.stop.setIcon(icons.get_icon("mdi.stop"))
        self.stop.clicked.connect(self.processStopped.emit)
Exemplo n.º 34
0
def red_asterisk():
    global RED_ASTERISK
    if RED_ASTERISK is None:
        RED_ASTERISK = get_icon('fa.asterisk', color='red', scale_factor=0.6)
    return RED_ASTERISK
Exemplo n.º 35
0
def red_asterisk():
    global RED_ASTERISK
    if RED_ASTERISK is None:
        RED_ASTERISK = get_icon('mdi.asterisk', 'red', 0.6)
    return RED_ASTERISK
Exemplo n.º 36
0
 def test_get_icon_name_color_scaleFactor(self):
     icon = get_icon("mdi.run-fast", "red", 1.5)
     self.assertEqual(icon.isNull(), False)
Exemplo n.º 37
0
def red_asterisk():
    global RED_ASTERISK
    if RED_ASTERISK is None:
        RED_ASTERISK = get_icon('fa.asterisk', color='red', scale_factor=0.6)
    return RED_ASTERISK